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 computationTue, 20 Dec 2011 15:47:54 -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/2011/Dec/20/t1324414101l8h81de8qluyqz0.htm/, Retrieved Sun, 05 May 2024 22:30:42 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=158251, Retrieved Sun, 05 May 2024 22:30:42 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact80
Family? (F = Feedback message, R = changed R code, M = changed R Module, P = changed Parameters, D = changed Data)
-       [Recursive Partitioning (Regression Trees)] [Recursive Partiti...] [2011-12-20 20:47:54] [e5e604418bec6ffe5109fb01f8a59ccb] [Current]
Feedback Forum

Post a new message
Dataseries X:
146283	30	79	56	1418
98364	28	58	56	869
86146	38	60	54	1530
96933	30	108	89	2172
79234	22	49	40	901
42551	26	0	25	463
195663	25	121	92	3201
6853	18	1	18	371
21529	11	20	63	1192
95757	26	43	44	1583
85584	25	69	33	1439
143983	38	78	84	1764
75851	44	86	88	1495
59238	30	44	55	1373
93163	40	104	60	2187
96037	34	63	66	1491
151511	47	158	154	4041
136368	30	102	53	1706
112642	31	77	119	2152
94728	23	82	41	1036
105499	36	115	61	1882
121527	36	101	58	1929
127766	30	80	75	2242
98958	25	50	33	1220
77900	39	83	40	1289
85646	34	123	92	2515
98579	31	73	100	2147
130767	31	81	112	2352
131741	33	105	73	1638
53907	25	47	40	1222
178812	33	105	45	1812
146761	35	94	60	1677
82036	42	44	62	1579
163253	43	114	75	1731
27032	30	38	31	807
171975	33	107	77	2452
65990	13	30	34	829
86572	32	71	46	1940
159676	36	84	99	2662
1929	0	0	17	186
85371	28	59	66	1499
58391	14	33	30	865
31580	17	42	76	1793
136815	32	96	146	2527
120642	30	106	67	2747
69107	35	56	56	1324
50495	20	57	107	2702
108016	28	59	58	1383
46341	28	39	34	1179
78348	39	34	61	2099
79336	34	76	119	4308
56968	26	20	42	918
93176	39	91	66	1831
161632	39	115	89	3373
87850	33	85	44	1713
127969	28	76	66	1438
15049	4	8	24	496
155135	39	79	259	2253
25109	18	21	17	744
45824	14	30	64	1161
102996	29	76	41	2352
160604	44	101	68	2144
158051	21	94	168	4691
44547	16	27	43	1112
162647	28	92	132	2694
174141	35	123	105	1973
60622	28	75	71	1769
179566	38	128	112	3148
184301	23	105	94	2474
75661	36	55	82	2084
96144	32	56	70	1954
129847	29	41	57	1226
117286	25	72	53	1389
71180	27	67	103	1496
109377	36	75	121	2269
85298	28	114	62	1833
73631	23	118	52	1268
86767	40	77	52	1943
23824	23	22	32	893
93487	40	66	62	1762
82981	28	69	45	1403
73815	34	105	46	1425
94552	33	116	63	1857
132190	28	88	75	1840
128754	34	73	88	1502
66363	30	99	46	1441
67808	33	62	53	1420
61724	22	53	37	1416
131722	38	118	90	2970
68580	26	30	63	1317
106175	35	100	78	1644
55792	8	49	25	870
25157	24	24	45	1654
76669	29	67	46	1054
57283	20	46	41	937
105805	29	57	144	3004
129484	45	75	82	2008
72413	37	135	91	2547
87831	33	68	71	1885
96971	33	124	63	1626
71299	25	33	53	1468
77494	32	98	62	2445
120336	29	58	63	1964
93913	28	68	32	1381
136048	28	81	39	1369
181248	31	131	62	1659
146123	52	110	117	2888
32036	21	37	34	1290
186646	24	130	92	2845
102255	41	93	93	1982
168237	33	118	54	1904
64219	32	39	144	1391
19630	19	13	14	602
76825	20	74	61	1743
115338	31	81	109	1559
109427	31	109	38	2014
118168	32	151	73	2143
84845	18	51	75	2146
153197	23	28	50	874
29877	17	40	61	1590
63506	20	56	55	1590
22445	12	27	77	1210
47695	17	37	75	2072
68370	30	83	72	1281
146304	31	54	50	1401
38233	10	27	32	834
42071	13	28	53	1105
50517	22	59	42	1272
103950	42	133	71	1944
5841	1	12	10	391
2341	9	0	35	761
84396	32	106	65	1605
24610	11	23	25	530
35753	25	44	66	1988
55515	36	71	41	1386
209056	31	116	86	2395
6622	0	4	16	387
115814	24	62	42	1742
11609	13	12	19	620
13155	8	18	19	449
18274	13	14	45	800
72875	19	60	65	1684
10112	18	7	35	1050
142775	33	98	95	2699
68847	40	64	49	1606
17659	22	29	37	1502
20112	38	32	64	1204
61023	24	25	38	1138
13983	8	16	34	568
65176	35	48	32	1459
132432	43	100	65	2158
112494	43	46	52	1111
45109	14	45	62	1421
170875	41	129	65	2833
180759	38	130	83	1955
214921	45	136	95	2922
100226	31	59	29	1002
32043	13	25	18	1060
54454	28	32	33	956
78876	31	63	247	2186
170745	40	95	139	3604
6940	30	14	29	1035
49025	16	36	118	1417
122037	37	113	110	3261
53782	30	47	67	1587
127748	35	92	42	1424
86839	32	70	65	1701
44830	27	19	94	1249
77395	20	50	64	946
89324	18	41	81	1926
103300	31	91	95	3352
112283	31	111	67	1641
10901	21	41	63	2035
120691	39	120	83	2312
58106	41	135	45	1369
57140	13	27	30	1577
122422	32	87	70	2201
25899	18	25	32	961
139296	39	131	83	1900
52678	14	45	31	1254
23853	7	29	67	1335
17306	17	58	66	1597
7953	0	4	10	207
89455	30	47	70	1645
147866	37	109	103	2429
4245	0	7	5	151
21509	5	12	20	474
7670	1	0	5	141
66675	16	37	36	1639
14336	32	37	34	872
53608	24	46	48	1318
30059	17	15	40	1018
29668	11	42	43	1383
22097	24	7	31	1314
96841	22	54	42	1335
41907	12	54	46	1403
27080	19	14	33	910
35885	13	16	18	616
41247	17	33	55	1407
28313	15	32	35	771
36845	16	21	59	766
16548	24	15	19	473
36134	15	38	66	1376
55764	17	22	60	1232
28910	18	28	36	1521
13339	20	10	25	572
25319	16	31	47	1059
66956	16	32	54	1544
47487	18	32	53	1230
52785	22	43	40	1206
44683	8	27	40	1205
35619	17	37	39	1255
21920	18	20	14	613
45608	16	32	45	721
7721	23	0	36	1109
20634	22	5	28	740
29788	13	26	44	1126
31931	13	10	30	728
37754	16	27	22	689
32505	16	11	17	592
40557	20	29	31	995
94238	22	25	55	1613
44197	17	55	54	2048
43228	18	23	21	705
4103	17	5	14	301
44144	12	43	81	1803
32868	7	23	35	799
27640	17	34	43	861
14063	14	36	46	1186
28990	23	35	30	1451
4694	17	0	23	628
42648	14	37	38	1161
64329	15	28	54	1463
21928	17	16	20	742
25836	21	26	53	979
22779	18	38	45	675
40820	18	23	39	1241
27530	17	22	20	676
32378	17	30	24	1049
10824	16	16	31	620
39613	15	18	35	1081
60865	21	28	151	1688
19787	16	32	52	736
20107	14	21	30	617
36605	15	23	31	812
40961	17	29	29	1051
48231	15	50	57	1656
39725	15	12	40	705
21455	10	21	44	945
23430	6	18	25	554
62991	22	27	77	1597
49363	21	41	35	982
9604	1	13	11	222
24552	18	12	63	1212
31493	17	21	44	1143
3439	4	8	19	435
19555	10	26	13	532
21228	16	27	42	882
23177	16	13	38	608
22094	9	16	29	459
2342	16	2	20	578
38798	17	42	27	826
3255	7	5	20	509
24261	15	37	19	717
18511	14	17	37	637
40798	14	38	26	857
28893	18	37	42	830
21425	12	29	49	652
50276	16	32	30	707
37643	21	35	49	954
30377	19	17	67	1461
27126	16	20	28	672
13	1	7	19	778
42097	16	46	49	1141
24451	10	24	27	680
14335	19	40	30	1090
5084	12	3	22	616
9927	2	10	12	285
43527	14	37	31	1145
27184	17	17	20	733
21610	19	28	20	888
20484	14	19	39	849
20156	11	29	29	1182
6012	4	8	16	528
18475	16	10	27	642
12645	20	15	21	947
11017	12	15	19	819
37623	15	28	35	757
35873	16	17	14	894




Summary of computational transaction
Raw Inputview raw input (R code)
Raw Outputview raw output of R engine
Computing time5 seconds
R Server'Gwilym Jenkins' @ jenkins.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 & 5 seconds \tabularnewline
R Server & 'Gwilym Jenkins' @ jenkins.wessa.net \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=158251&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]5 seconds[/C][/ROW]
[ROW][C]R Server[/C][C]'Gwilym Jenkins' @ jenkins.wessa.net[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=158251&T=0

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=158251&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 time5 seconds
R Server'Gwilym Jenkins' @ jenkins.wessa.net







10-Fold Cross Validation
Prediction (training)Prediction (testing)
ActualC1C2CVC1C2CV
C111871120.9138125260.8278
C213311460.896251360.8447
Overall--0.905--0.8365

\begin{tabular}{lllllllll}
\hline
10-Fold Cross Validation \tabularnewline
 & Prediction (training) & Prediction (testing) \tabularnewline
Actual & C1 & C2 & CV & C1 & C2 & CV \tabularnewline
C1 & 1187 & 112 & 0.9138 & 125 & 26 & 0.8278 \tabularnewline
C2 & 133 & 1146 & 0.896 & 25 & 136 & 0.8447 \tabularnewline
Overall & - & - & 0.905 & - & - & 0.8365 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=158251&T=1

[TABLE]
[ROW][C]10-Fold Cross Validation[/C][/ROW]
[ROW][C][/C][C]Prediction (training)[/C][C]Prediction (testing)[/C][/ROW]
[ROW][C]Actual[/C][C]C1[/C][C]C2[/C][C]CV[/C][C]C1[/C][C]C2[/C][C]CV[/C][/ROW]
[ROW][C]C1[/C][C]1187[/C][C]112[/C][C]0.9138[/C][C]125[/C][C]26[/C][C]0.8278[/C][/ROW]
[ROW][C]C2[/C][C]133[/C][C]1146[/C][C]0.896[/C][C]25[/C][C]136[/C][C]0.8447[/C][/ROW]
[ROW][C]Overall[/C][C]-[/C][C]-[/C][C]0.905[/C][C]-[/C][C]-[/C][C]0.8365[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=158251&T=1

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

As an alternative you can also use a QR Code:  

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

10-Fold Cross Validation
Prediction (training)Prediction (testing)
ActualC1C2CVC1C2CV
C111871120.9138125260.8278
C213311460.896251360.8447
Overall--0.905--0.8365







Confusion Matrix (predicted in columns / actuals in rows)
C1C2
C113213
C215129

\begin{tabular}{lllllllll}
\hline
Confusion Matrix (predicted in columns / actuals in rows) \tabularnewline
 & C1 & C2 \tabularnewline
C1 & 132 & 13 \tabularnewline
C2 & 15 & 129 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=158251&T=2

[TABLE]
[ROW][C]Confusion Matrix (predicted in columns / actuals in rows)[/C][/ROW]
[ROW][C][/C][C]C1[/C][C]C2[/C][/ROW]
[ROW][C]C1[/C][C]132[/C][C]13[/C][/ROW]
[ROW][C]C2[/C][C]15[/C][C]129[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=158251&T=2

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

As an alternative you can also use a QR Code:  

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

Confusion Matrix (predicted in columns / actuals in rows)
C1C2
C113213
C215129



Parameters (Session):
par1 = 1 ; par2 = quantiles ; par3 = 2 ; par4 = yes ;
Parameters (R input):
par1 = 1 ; par2 = quantiles ; par3 = 2 ; par4 = yes ;
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')
}