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 13:57:12 -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/t1324407471kugmdd16gpaop7o.htm/, Retrieved Mon, 06 May 2024 06:52:06 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=158155, Retrieved Mon, 06 May 2024 06:52:06 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact95
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 18:57:12] [e5e604418bec6ffe5109fb01f8a59ccb] [Current]
Feedback Forum

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




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

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=158155&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'Herman Ole Andreas Wold' @ wold.wessa.net







10-Fold Cross Validation
Prediction (training)Prediction (testing)
ActualC1C2CVC1C2CV
C11268390.9702126170.8811
C223710380.8141421230.7455
Overall--0.8931--0.8084

\begin{tabular}{lllllllll}
\hline
10-Fold Cross Validation \tabularnewline
 & Prediction (training) & Prediction (testing) \tabularnewline
Actual & C1 & C2 & CV & C1 & C2 & CV \tabularnewline
C1 & 1268 & 39 & 0.9702 & 126 & 17 & 0.8811 \tabularnewline
C2 & 237 & 1038 & 0.8141 & 42 & 123 & 0.7455 \tabularnewline
Overall & - & - & 0.8931 & - & - & 0.8084 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=158155&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]1268[/C][C]39[/C][C]0.9702[/C][C]126[/C][C]17[/C][C]0.8811[/C][/ROW]
[ROW][C]C2[/C][C]237[/C][C]1038[/C][C]0.8141[/C][C]42[/C][C]123[/C][C]0.7455[/C][/ROW]
[ROW][C]Overall[/C][C]-[/C][C]-[/C][C]0.8931[/C][C]-[/C][C]-[/C][C]0.8084[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=158155&T=1

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=158155&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
C11268390.9702126170.8811
C223710380.8141421230.7455
Overall--0.8931--0.8084







Confusion Matrix (predicted in columns / actuals in rows)
C1C2
C11432
C228116

\begin{tabular}{lllllllll}
\hline
Confusion Matrix (predicted in columns / actuals in rows) \tabularnewline
 & C1 & C2 \tabularnewline
C1 & 143 & 2 \tabularnewline
C2 & 28 & 116 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=158155&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]143[/C][C]2[/C][/ROW]
[ROW][C]C2[/C][C]28[/C][C]116[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=158155&T=2

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=158155&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
C11432
C228116



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')
}