Free Statistics

of Irreproducible Research!

Author's title

Author*The author of this computation has been verified*
R Software Modulerwasp_regression_trees1.wasp
Title produced by softwareRecursive Partitioning (Regression Trees)
Date of computationMon, 10 Dec 2012 11:20:53 -0500
Cite this page as followsStatistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?v=date/2012/Dec/10/t1355156534l8g0dlnfyh2e8ob.htm/, Retrieved Sat, 27 Apr 2024 05:05:41 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=198227, Retrieved Sat, 27 Apr 2024 05:05:41 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact76
Family? (F = Feedback message, R = changed R code, M = changed R Module, P = changed Parameters, D = changed Data)
-     [Recursive Partitioning (Regression Trees)] [] [2010-12-05 18:59:57] [b98453cac15ba1066b407e146608df68]
- R PD    [Recursive Partitioning (Regression Trees)] [WS10: Recursive P...] [2012-12-10 16:20:53] [933e9ab295d38e240eca0a457ef09371] [Current]
Feedback Forum

Post a new message
Dataseries X:
210907	56	396	81	3	79	30
120982	56	297	55	4	58	28
176508	54	559	50	12	60	38
179321	89	967	125	2	108	30
123185	40	270	40	1	49	22
52746	25	143	37	3	0	26
385534	92	1562	63	0	121	25
33170	18	109	44	0	1	18
101645	63	371	88	0	20	11
149061	44	656	66	5	43	26
165446	33	511	57	0	69	25
237213	84	655	74	0	78	38
173326	88	465	49	7	86	44
133131	55	525	52	7	44	30
258873	60	885	88	3	104	40
180083	66	497	36	9	63	34
324799	154	1436	108	0	158	47
230964	53	612	43	4	102	30
236785	119	865	75	3	77	31
135473	41	385	32	0	82	23
202925	61	567	44	7	115	36
215147	58	639	85	0	101	36
344297	75	963	86	1	80	30
153935	33	398	56	5	50	25
132943	40	410	50	7	83	39
174724	92	966	135	0	123	34
174415	100	801	63	0	73	31
225548	112	892	81	5	81	31
223632	73	513	52	0	105	33
124817	40	469	44	0	47	25
221698	45	683	113	0	105	33
210767	60	643	39	3	94	35
170266	62	535	73	4	44	42
260561	75	625	48	1	114	43
84853	31	264	33	4	38	30
294424	77	992	59	2	107	33
101011	34	238	41	0	30	13
215641	46	818	69	0	71	32
325107	99	937	64	0	84	36
7176	17	70	1	0	0	0
167542	66	507	59	2	59	28
106408	30	260	32	1	33	14
96560	76	503	129	0	42	17
265769	146	927	37	2	96	32
269651	67	1269	31	10	106	30
149112	56	537	65	6	56	35
175824	107	910	107	0	57	20
152871	58	532	74	5	59	28
111665	34	345	54	4	39	28
116408	61	918	76	1	34	39
362301	119	1635	715	2	76	34
78800	42	330	57	2	20	26
183167	66	557	66	0	91	39
277965	89	1178	106	8	115	39
150629	44	740	54	3	85	33
168809	66	452	32	0	76	28
24188	24	218	20	0	8	4




Summary of computational transaction
Raw Inputview raw input (R code)
Raw Outputview raw output of R engine
Computing time4 seconds
R Server'Gertrude Mary Cox' @ cox.wessa.net

\begin{tabular}{lllllllll}
\hline
Summary of computational transaction \tabularnewline
Raw Input & view raw input (R code)  \tabularnewline
Raw Output & view raw output of R engine  \tabularnewline
Computing time & 4 seconds \tabularnewline
R Server & 'Gertrude Mary Cox' @ cox.wessa.net \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=198227&T=0

[TABLE]
[ROW][C]Summary of computational transaction[/C][/ROW]
[ROW][C]Raw Input[/C][C]view raw input (R code) [/C][/ROW]
[ROW][C]Raw Output[/C][C]view raw output of R engine [/C][/ROW]
[ROW][C]Computing time[/C][C]4 seconds[/C][/ROW]
[ROW][C]R Server[/C][C]'Gertrude Mary Cox' @ cox.wessa.net[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=198227&T=0

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=198227&T=0

As an alternative you can also use a QR Code:  

The GUIDs for individual cells are displayed in the table below:

Summary of computational transaction
Raw Inputview raw input (R code)
Raw Outputview raw output of R engine
Computing time4 seconds
R Server'Gertrude Mary Cox' @ cox.wessa.net







Goodness of Fit
Correlation0.8584
R-squared0.7369
RMSE41916.7411

\begin{tabular}{lllllllll}
\hline
Goodness of Fit \tabularnewline
Correlation & 0.8584 \tabularnewline
R-squared & 0.7369 \tabularnewline
RMSE & 41916.7411 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=198227&T=1

[TABLE]
[ROW][C]Goodness of Fit[/C][/ROW]
[ROW][C]Correlation[/C][C]0.8584[/C][/ROW]
[ROW][C]R-squared[/C][C]0.7369[/C][/ROW]
[ROW][C]RMSE[/C][C]41916.7411[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=198227&T=1

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=198227&T=1

As an alternative you can also use a QR Code:  

The GUIDs for individual cells are displayed in the table below:

Goodness of Fit
Correlation0.8584
R-squared0.7369
RMSE41916.7411







Actuals, Predictions, and Residuals
#ActualsForecastsResiduals
1210907160322.89473684250584.1052631579
2120982160322.894736842-39340.8947368421
3176508160322.89473684216185.1052631579
4179321291262.909090909-111941.909090909
5123185160322.894736842-37137.8947368421
65274672565.6363636364-19819.6363636364
7385534291262.90909090994271.0909090909
83317072565.6363636364-39395.6363636364
910164572565.636363636429079.3636363636
10149061205153.6875-56092.6875
11165446160322.8947368425123.10526315789
12237213205153.687532059.3125
13173326160322.89473684213003.1052631579
14133131160322.894736842-27191.8947368421
15258873205153.687553719.3125
16180083160322.89473684219760.1052631579
17324799291262.90909090933536.0909090909
18230964205153.687525810.3125
19236785205153.687531631.3125
20135473160322.894736842-24849.8947368421
21202925205153.6875-2228.6875
22215147205153.68759993.3125
23344297291262.90909090953034.0909090909
24153935160322.894736842-6387.89473684211
25132943160322.894736842-27379.8947368421
26174724291262.909090909-116538.909090909
27174415205153.6875-30738.6875
28225548205153.687520394.3125
29223632160322.89473684263309.1052631579
30124817160322.894736842-35505.8947368421
31221698205153.687516544.3125
32210767205153.68755613.3125
33170266160322.8947368429943.10526315789
34260561205153.687555407.3125
358485372565.636363636412287.3636363636
36294424291262.9090909093161.09090909088
3710101172565.636363636428445.3636363636
38215641205153.687510487.3125
39325107291262.90909090933844.0909090909
40717672565.6363636364-65389.6363636364
41167542160322.8947368427219.10526315789
4210640872565.636363636433842.3636363636
439656072565.636363636423994.3636363636
44265769291262.909090909-25493.9090909091
45269651291262.909090909-21611.9090909091
46149112160322.894736842-11210.8947368421
47175824205153.6875-29329.6875
48152871160322.894736842-7451.89473684211
4911166572565.636363636439099.3636363636
50116408205153.6875-88745.6875
51362301291262.90909090971038.0909090909
527880072565.63636363646234.36363636363
53183167160322.89473684222844.1052631579
54277965291262.909090909-13297.9090909091
55150629205153.6875-54524.6875
56168809160322.8947368428486.10526315789
572418872565.6363636364-48377.6363636364

\begin{tabular}{lllllllll}
\hline
Actuals, Predictions, and Residuals \tabularnewline
# & Actuals & Forecasts & Residuals \tabularnewline
1 & 210907 & 160322.894736842 & 50584.1052631579 \tabularnewline
2 & 120982 & 160322.894736842 & -39340.8947368421 \tabularnewline
3 & 176508 & 160322.894736842 & 16185.1052631579 \tabularnewline
4 & 179321 & 291262.909090909 & -111941.909090909 \tabularnewline
5 & 123185 & 160322.894736842 & -37137.8947368421 \tabularnewline
6 & 52746 & 72565.6363636364 & -19819.6363636364 \tabularnewline
7 & 385534 & 291262.909090909 & 94271.0909090909 \tabularnewline
8 & 33170 & 72565.6363636364 & -39395.6363636364 \tabularnewline
9 & 101645 & 72565.6363636364 & 29079.3636363636 \tabularnewline
10 & 149061 & 205153.6875 & -56092.6875 \tabularnewline
11 & 165446 & 160322.894736842 & 5123.10526315789 \tabularnewline
12 & 237213 & 205153.6875 & 32059.3125 \tabularnewline
13 & 173326 & 160322.894736842 & 13003.1052631579 \tabularnewline
14 & 133131 & 160322.894736842 & -27191.8947368421 \tabularnewline
15 & 258873 & 205153.6875 & 53719.3125 \tabularnewline
16 & 180083 & 160322.894736842 & 19760.1052631579 \tabularnewline
17 & 324799 & 291262.909090909 & 33536.0909090909 \tabularnewline
18 & 230964 & 205153.6875 & 25810.3125 \tabularnewline
19 & 236785 & 205153.6875 & 31631.3125 \tabularnewline
20 & 135473 & 160322.894736842 & -24849.8947368421 \tabularnewline
21 & 202925 & 205153.6875 & -2228.6875 \tabularnewline
22 & 215147 & 205153.6875 & 9993.3125 \tabularnewline
23 & 344297 & 291262.909090909 & 53034.0909090909 \tabularnewline
24 & 153935 & 160322.894736842 & -6387.89473684211 \tabularnewline
25 & 132943 & 160322.894736842 & -27379.8947368421 \tabularnewline
26 & 174724 & 291262.909090909 & -116538.909090909 \tabularnewline
27 & 174415 & 205153.6875 & -30738.6875 \tabularnewline
28 & 225548 & 205153.6875 & 20394.3125 \tabularnewline
29 & 223632 & 160322.894736842 & 63309.1052631579 \tabularnewline
30 & 124817 & 160322.894736842 & -35505.8947368421 \tabularnewline
31 & 221698 & 205153.6875 & 16544.3125 \tabularnewline
32 & 210767 & 205153.6875 & 5613.3125 \tabularnewline
33 & 170266 & 160322.894736842 & 9943.10526315789 \tabularnewline
34 & 260561 & 205153.6875 & 55407.3125 \tabularnewline
35 & 84853 & 72565.6363636364 & 12287.3636363636 \tabularnewline
36 & 294424 & 291262.909090909 & 3161.09090909088 \tabularnewline
37 & 101011 & 72565.6363636364 & 28445.3636363636 \tabularnewline
38 & 215641 & 205153.6875 & 10487.3125 \tabularnewline
39 & 325107 & 291262.909090909 & 33844.0909090909 \tabularnewline
40 & 7176 & 72565.6363636364 & -65389.6363636364 \tabularnewline
41 & 167542 & 160322.894736842 & 7219.10526315789 \tabularnewline
42 & 106408 & 72565.6363636364 & 33842.3636363636 \tabularnewline
43 & 96560 & 72565.6363636364 & 23994.3636363636 \tabularnewline
44 & 265769 & 291262.909090909 & -25493.9090909091 \tabularnewline
45 & 269651 & 291262.909090909 & -21611.9090909091 \tabularnewline
46 & 149112 & 160322.894736842 & -11210.8947368421 \tabularnewline
47 & 175824 & 205153.6875 & -29329.6875 \tabularnewline
48 & 152871 & 160322.894736842 & -7451.89473684211 \tabularnewline
49 & 111665 & 72565.6363636364 & 39099.3636363636 \tabularnewline
50 & 116408 & 205153.6875 & -88745.6875 \tabularnewline
51 & 362301 & 291262.909090909 & 71038.0909090909 \tabularnewline
52 & 78800 & 72565.6363636364 & 6234.36363636363 \tabularnewline
53 & 183167 & 160322.894736842 & 22844.1052631579 \tabularnewline
54 & 277965 & 291262.909090909 & -13297.9090909091 \tabularnewline
55 & 150629 & 205153.6875 & -54524.6875 \tabularnewline
56 & 168809 & 160322.894736842 & 8486.10526315789 \tabularnewline
57 & 24188 & 72565.6363636364 & -48377.6363636364 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=198227&T=2

[TABLE]
[ROW][C]Actuals, Predictions, and Residuals[/C][/ROW]
[ROW][C]#[/C][C]Actuals[/C][C]Forecasts[/C][C]Residuals[/C][/ROW]
[ROW][C]1[/C][C]210907[/C][C]160322.894736842[/C][C]50584.1052631579[/C][/ROW]
[ROW][C]2[/C][C]120982[/C][C]160322.894736842[/C][C]-39340.8947368421[/C][/ROW]
[ROW][C]3[/C][C]176508[/C][C]160322.894736842[/C][C]16185.1052631579[/C][/ROW]
[ROW][C]4[/C][C]179321[/C][C]291262.909090909[/C][C]-111941.909090909[/C][/ROW]
[ROW][C]5[/C][C]123185[/C][C]160322.894736842[/C][C]-37137.8947368421[/C][/ROW]
[ROW][C]6[/C][C]52746[/C][C]72565.6363636364[/C][C]-19819.6363636364[/C][/ROW]
[ROW][C]7[/C][C]385534[/C][C]291262.909090909[/C][C]94271.0909090909[/C][/ROW]
[ROW][C]8[/C][C]33170[/C][C]72565.6363636364[/C][C]-39395.6363636364[/C][/ROW]
[ROW][C]9[/C][C]101645[/C][C]72565.6363636364[/C][C]29079.3636363636[/C][/ROW]
[ROW][C]10[/C][C]149061[/C][C]205153.6875[/C][C]-56092.6875[/C][/ROW]
[ROW][C]11[/C][C]165446[/C][C]160322.894736842[/C][C]5123.10526315789[/C][/ROW]
[ROW][C]12[/C][C]237213[/C][C]205153.6875[/C][C]32059.3125[/C][/ROW]
[ROW][C]13[/C][C]173326[/C][C]160322.894736842[/C][C]13003.1052631579[/C][/ROW]
[ROW][C]14[/C][C]133131[/C][C]160322.894736842[/C][C]-27191.8947368421[/C][/ROW]
[ROW][C]15[/C][C]258873[/C][C]205153.6875[/C][C]53719.3125[/C][/ROW]
[ROW][C]16[/C][C]180083[/C][C]160322.894736842[/C][C]19760.1052631579[/C][/ROW]
[ROW][C]17[/C][C]324799[/C][C]291262.909090909[/C][C]33536.0909090909[/C][/ROW]
[ROW][C]18[/C][C]230964[/C][C]205153.6875[/C][C]25810.3125[/C][/ROW]
[ROW][C]19[/C][C]236785[/C][C]205153.6875[/C][C]31631.3125[/C][/ROW]
[ROW][C]20[/C][C]135473[/C][C]160322.894736842[/C][C]-24849.8947368421[/C][/ROW]
[ROW][C]21[/C][C]202925[/C][C]205153.6875[/C][C]-2228.6875[/C][/ROW]
[ROW][C]22[/C][C]215147[/C][C]205153.6875[/C][C]9993.3125[/C][/ROW]
[ROW][C]23[/C][C]344297[/C][C]291262.909090909[/C][C]53034.0909090909[/C][/ROW]
[ROW][C]24[/C][C]153935[/C][C]160322.894736842[/C][C]-6387.89473684211[/C][/ROW]
[ROW][C]25[/C][C]132943[/C][C]160322.894736842[/C][C]-27379.8947368421[/C][/ROW]
[ROW][C]26[/C][C]174724[/C][C]291262.909090909[/C][C]-116538.909090909[/C][/ROW]
[ROW][C]27[/C][C]174415[/C][C]205153.6875[/C][C]-30738.6875[/C][/ROW]
[ROW][C]28[/C][C]225548[/C][C]205153.6875[/C][C]20394.3125[/C][/ROW]
[ROW][C]29[/C][C]223632[/C][C]160322.894736842[/C][C]63309.1052631579[/C][/ROW]
[ROW][C]30[/C][C]124817[/C][C]160322.894736842[/C][C]-35505.8947368421[/C][/ROW]
[ROW][C]31[/C][C]221698[/C][C]205153.6875[/C][C]16544.3125[/C][/ROW]
[ROW][C]32[/C][C]210767[/C][C]205153.6875[/C][C]5613.3125[/C][/ROW]
[ROW][C]33[/C][C]170266[/C][C]160322.894736842[/C][C]9943.10526315789[/C][/ROW]
[ROW][C]34[/C][C]260561[/C][C]205153.6875[/C][C]55407.3125[/C][/ROW]
[ROW][C]35[/C][C]84853[/C][C]72565.6363636364[/C][C]12287.3636363636[/C][/ROW]
[ROW][C]36[/C][C]294424[/C][C]291262.909090909[/C][C]3161.09090909088[/C][/ROW]
[ROW][C]37[/C][C]101011[/C][C]72565.6363636364[/C][C]28445.3636363636[/C][/ROW]
[ROW][C]38[/C][C]215641[/C][C]205153.6875[/C][C]10487.3125[/C][/ROW]
[ROW][C]39[/C][C]325107[/C][C]291262.909090909[/C][C]33844.0909090909[/C][/ROW]
[ROW][C]40[/C][C]7176[/C][C]72565.6363636364[/C][C]-65389.6363636364[/C][/ROW]
[ROW][C]41[/C][C]167542[/C][C]160322.894736842[/C][C]7219.10526315789[/C][/ROW]
[ROW][C]42[/C][C]106408[/C][C]72565.6363636364[/C][C]33842.3636363636[/C][/ROW]
[ROW][C]43[/C][C]96560[/C][C]72565.6363636364[/C][C]23994.3636363636[/C][/ROW]
[ROW][C]44[/C][C]265769[/C][C]291262.909090909[/C][C]-25493.9090909091[/C][/ROW]
[ROW][C]45[/C][C]269651[/C][C]291262.909090909[/C][C]-21611.9090909091[/C][/ROW]
[ROW][C]46[/C][C]149112[/C][C]160322.894736842[/C][C]-11210.8947368421[/C][/ROW]
[ROW][C]47[/C][C]175824[/C][C]205153.6875[/C][C]-29329.6875[/C][/ROW]
[ROW][C]48[/C][C]152871[/C][C]160322.894736842[/C][C]-7451.89473684211[/C][/ROW]
[ROW][C]49[/C][C]111665[/C][C]72565.6363636364[/C][C]39099.3636363636[/C][/ROW]
[ROW][C]50[/C][C]116408[/C][C]205153.6875[/C][C]-88745.6875[/C][/ROW]
[ROW][C]51[/C][C]362301[/C][C]291262.909090909[/C][C]71038.0909090909[/C][/ROW]
[ROW][C]52[/C][C]78800[/C][C]72565.6363636364[/C][C]6234.36363636363[/C][/ROW]
[ROW][C]53[/C][C]183167[/C][C]160322.894736842[/C][C]22844.1052631579[/C][/ROW]
[ROW][C]54[/C][C]277965[/C][C]291262.909090909[/C][C]-13297.9090909091[/C][/ROW]
[ROW][C]55[/C][C]150629[/C][C]205153.6875[/C][C]-54524.6875[/C][/ROW]
[ROW][C]56[/C][C]168809[/C][C]160322.894736842[/C][C]8486.10526315789[/C][/ROW]
[ROW][C]57[/C][C]24188[/C][C]72565.6363636364[/C][C]-48377.6363636364[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=198227&T=2

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=198227&T=2

As an alternative you can also use a QR Code:  

The GUIDs for individual cells are displayed in the table below:

Actuals, Predictions, and Residuals
#ActualsForecastsResiduals
1210907160322.89473684250584.1052631579
2120982160322.894736842-39340.8947368421
3176508160322.89473684216185.1052631579
4179321291262.909090909-111941.909090909
5123185160322.894736842-37137.8947368421
65274672565.6363636364-19819.6363636364
7385534291262.90909090994271.0909090909
83317072565.6363636364-39395.6363636364
910164572565.636363636429079.3636363636
10149061205153.6875-56092.6875
11165446160322.8947368425123.10526315789
12237213205153.687532059.3125
13173326160322.89473684213003.1052631579
14133131160322.894736842-27191.8947368421
15258873205153.687553719.3125
16180083160322.89473684219760.1052631579
17324799291262.90909090933536.0909090909
18230964205153.687525810.3125
19236785205153.687531631.3125
20135473160322.894736842-24849.8947368421
21202925205153.6875-2228.6875
22215147205153.68759993.3125
23344297291262.90909090953034.0909090909
24153935160322.894736842-6387.89473684211
25132943160322.894736842-27379.8947368421
26174724291262.909090909-116538.909090909
27174415205153.6875-30738.6875
28225548205153.687520394.3125
29223632160322.89473684263309.1052631579
30124817160322.894736842-35505.8947368421
31221698205153.687516544.3125
32210767205153.68755613.3125
33170266160322.8947368429943.10526315789
34260561205153.687555407.3125
358485372565.636363636412287.3636363636
36294424291262.9090909093161.09090909088
3710101172565.636363636428445.3636363636
38215641205153.687510487.3125
39325107291262.90909090933844.0909090909
40717672565.6363636364-65389.6363636364
41167542160322.8947368427219.10526315789
4210640872565.636363636433842.3636363636
439656072565.636363636423994.3636363636
44265769291262.909090909-25493.9090909091
45269651291262.909090909-21611.9090909091
46149112160322.894736842-11210.8947368421
47175824205153.6875-29329.6875
48152871160322.894736842-7451.89473684211
4911166572565.636363636439099.3636363636
50116408205153.6875-88745.6875
51362301291262.90909090971038.0909090909
527880072565.63636363646234.36363636363
53183167160322.89473684222844.1052631579
54277965291262.909090909-13297.9090909091
55150629205153.6875-54524.6875
56168809160322.8947368428486.10526315789
572418872565.6363636364-48377.6363636364



Parameters (Session):
par1 = 1 ; par2 = none ; par3 = 6 ; par4 = no ;
Parameters (R input):
par1 = 1 ; par2 = none ; par3 = 6 ; par4 = no ;
R code (references can be found in the software module):
library(party)
library(Hmisc)
par1 <- as.numeric(par1)
par3 <- as.numeric(par3)
x <- data.frame(t(y))
is.data.frame(x)
x <- x[!is.na(x[,par1]),]
k <- length(x[1,])
n <- length(x[,1])
colnames(x)[par1]
x[,par1]
if (par2 == 'kmeans') {
cl <- kmeans(x[,par1], par3)
print(cl)
clm <- matrix(cbind(cl$centers,1:par3),ncol=2)
clm <- clm[sort.list(clm[,1]),]
for (i in 1:par3) {
cl$cluster[cl$cluster==clm[i,2]] <- paste('C',i,sep='')
}
cl$cluster <- as.factor(cl$cluster)
print(cl$cluster)
x[,par1] <- cl$cluster
}
if (par2 == 'quantiles') {
x[,par1] <- cut2(x[,par1],g=par3)
}
if (par2 == 'hclust') {
hc <- hclust(dist(x[,par1])^2, 'cen')
print(hc)
memb <- cutree(hc, k = par3)
dum <- c(mean(x[memb==1,par1]))
for (i in 2:par3) {
dum <- c(dum, mean(x[memb==i,par1]))
}
hcm <- matrix(cbind(dum,1:par3),ncol=2)
hcm <- hcm[sort.list(hcm[,1]),]
for (i in 1:par3) {
memb[memb==hcm[i,2]] <- paste('C',i,sep='')
}
memb <- as.factor(memb)
print(memb)
x[,par1] <- memb
}
if (par2=='equal') {
ed <- cut(as.numeric(x[,par1]),par3,labels=paste('C',1:par3,sep=''))
x[,par1] <- as.factor(ed)
}
table(x[,par1])
colnames(x)
colnames(x)[par1]
x[,par1]
if (par2 == 'none') {
m <- ctree(as.formula(paste(colnames(x)[par1],' ~ .',sep='')),data = x)
}
load(file='createtable')
if (par2 != 'none') {
m <- ctree(as.formula(paste('as.factor(',colnames(x)[par1],') ~ .',sep='')),data = x)
if (par4=='yes') {
a<-table.start()
a<-table.row.start(a)
a<-table.element(a,'10-Fold Cross Validation',3+2*par3,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'',1,TRUE)
a<-table.element(a,'Prediction (training)',par3+1,TRUE)
a<-table.element(a,'Prediction (testing)',par3+1,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'Actual',1,TRUE)
for (jjj in 1:par3) a<-table.element(a,paste('C',jjj,sep=''),1,TRUE)
a<-table.element(a,'CV',1,TRUE)
for (jjj in 1:par3) a<-table.element(a,paste('C',jjj,sep=''),1,TRUE)
a<-table.element(a,'CV',1,TRUE)
a<-table.row.end(a)
for (i in 1:10) {
ind <- sample(2, nrow(x), replace=T, prob=c(0.9,0.1))
m.ct <- ctree(as.formula(paste('as.factor(',colnames(x)[par1],') ~ .',sep='')),data =x[ind==1,])
if (i==1) {
m.ct.i.pred <- predict(m.ct, newdata=x[ind==1,])
m.ct.i.actu <- x[ind==1,par1]
m.ct.x.pred <- predict(m.ct, newdata=x[ind==2,])
m.ct.x.actu <- x[ind==2,par1]
} else {
m.ct.i.pred <- c(m.ct.i.pred,predict(m.ct, newdata=x[ind==1,]))
m.ct.i.actu <- c(m.ct.i.actu,x[ind==1,par1])
m.ct.x.pred <- c(m.ct.x.pred,predict(m.ct, newdata=x[ind==2,]))
m.ct.x.actu <- c(m.ct.x.actu,x[ind==2,par1])
}
}
print(m.ct.i.tab <- table(m.ct.i.actu,m.ct.i.pred))
numer <- 0
for (i in 1:par3) {
print(m.ct.i.tab[i,i] / sum(m.ct.i.tab[i,]))
numer <- numer + m.ct.i.tab[i,i]
}
print(m.ct.i.cp <- numer / sum(m.ct.i.tab))
print(m.ct.x.tab <- table(m.ct.x.actu,m.ct.x.pred))
numer <- 0
for (i in 1:par3) {
print(m.ct.x.tab[i,i] / sum(m.ct.x.tab[i,]))
numer <- numer + m.ct.x.tab[i,i]
}
print(m.ct.x.cp <- numer / sum(m.ct.x.tab))
for (i in 1:par3) {
a<-table.row.start(a)
a<-table.element(a,paste('C',i,sep=''),1,TRUE)
for (jjj in 1:par3) a<-table.element(a,m.ct.i.tab[i,jjj])
a<-table.element(a,round(m.ct.i.tab[i,i]/sum(m.ct.i.tab[i,]),4))
for (jjj in 1:par3) a<-table.element(a,m.ct.x.tab[i,jjj])
a<-table.element(a,round(m.ct.x.tab[i,i]/sum(m.ct.x.tab[i,]),4))
a<-table.row.end(a)
}
a<-table.row.start(a)
a<-table.element(a,'Overall',1,TRUE)
for (jjj in 1:par3) a<-table.element(a,'-')
a<-table.element(a,round(m.ct.i.cp,4))
for (jjj in 1:par3) a<-table.element(a,'-')
a<-table.element(a,round(m.ct.x.cp,4))
a<-table.row.end(a)
a<-table.end(a)
table.save(a,file='mytable3.tab')
}
}
m
bitmap(file='test1.png')
plot(m)
dev.off()
bitmap(file='test1a.png')
plot(x[,par1] ~ as.factor(where(m)),main='Response by Terminal Node',xlab='Terminal Node',ylab='Response')
dev.off()
if (par2 == 'none') {
forec <- predict(m)
result <- as.data.frame(cbind(x[,par1],forec,x[,par1]-forec))
colnames(result) <- c('Actuals','Forecasts','Residuals')
print(result)
}
if (par2 != 'none') {
print(cbind(as.factor(x[,par1]),predict(m)))
myt <- table(as.factor(x[,par1]),predict(m))
print(myt)
}
bitmap(file='test2.png')
if(par2=='none') {
op <- par(mfrow=c(2,2))
plot(density(result$Actuals),main='Kernel Density Plot of Actuals')
plot(density(result$Residuals),main='Kernel Density Plot of Residuals')
plot(result$Forecasts,result$Actuals,main='Actuals versus Predictions',xlab='Predictions',ylab='Actuals')
plot(density(result$Forecasts),main='Kernel Density Plot of Predictions')
par(op)
}
if(par2!='none') {
plot(myt,main='Confusion Matrix',xlab='Actual',ylab='Predicted')
}
dev.off()
if (par2 == 'none') {
detcoef <- cor(result$Forecasts,result$Actuals)
a<-table.start()
a<-table.row.start(a)
a<-table.element(a,'Goodness of Fit',2,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'Correlation',1,TRUE)
a<-table.element(a,round(detcoef,4))
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'R-squared',1,TRUE)
a<-table.element(a,round(detcoef*detcoef,4))
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'RMSE',1,TRUE)
a<-table.element(a,round(sqrt(mean((result$Residuals)^2)),4))
a<-table.row.end(a)
a<-table.end(a)
table.save(a,file='mytable1.tab')
a<-table.start()
a<-table.row.start(a)
a<-table.element(a,'Actuals, Predictions, and Residuals',4,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'#',header=TRUE)
a<-table.element(a,'Actuals',header=TRUE)
a<-table.element(a,'Forecasts',header=TRUE)
a<-table.element(a,'Residuals',header=TRUE)
a<-table.row.end(a)
for (i in 1:length(result$Actuals)) {
a<-table.row.start(a)
a<-table.element(a,i,header=TRUE)
a<-table.element(a,result$Actuals[i])
a<-table.element(a,result$Forecasts[i])
a<-table.element(a,result$Residuals[i])
a<-table.row.end(a)
}
a<-table.end(a)
table.save(a,file='mytable.tab')
}
if (par2 != 'none') {
a<-table.start()
a<-table.row.start(a)
a<-table.element(a,'Confusion Matrix (predicted in columns / actuals in rows)',par3+1,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,'',1,TRUE)
for (i in 1:par3) {
a<-table.element(a,paste('C',i,sep=''),1,TRUE)
}
a<-table.row.end(a)
for (i in 1:par3) {
a<-table.row.start(a)
a<-table.element(a,paste('C',i,sep=''),1,TRUE)
for (j in 1:par3) {
a<-table.element(a,myt[i,j])
}
a<-table.row.end(a)
}
a<-table.end(a)
table.save(a,file='mytable2.tab')
}