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, 12 Dec 2011 13:21:51 -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/12/t132371412716fxxxmb0gkzgqe.htm/, Retrieved Fri, 03 May 2024 11:39:11 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=154135, Retrieved Fri, 03 May 2024 11:39:11 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact79
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 19:35:21] [b98453cac15ba1066b407e146608df68]
- R PD    [Recursive Partitioning (Regression Trees)] [] [2011-12-12 18:21:51] [05d3841c0e91f0207133db830e88168b] [Current]
-   PD      [Recursive Partitioning (Regression Trees)] [RFC: analyse 1] [2011-12-23 17:16:43] [e51846b5e808727784baa8d5c183dcd5]
Feedback Forum

Post a new message
Dataseries X:
1418	56	210907
869	56	120982
1530	54	176508
2172	89	179321
901	40	123185
463	25	52746
3201	92	385534
371	18	33170
1192	63	101645
1583	44	149061
1439	33	165446
1764	84	237213
1495	88	173326
1373	55	133131
2187	60	258873
1491	66	180083
4041	154	324799
1706	53	230964
2152	119	236785
1036	41	135473
1882	61	202925
1929	58	215147
2242	75	344297
1220	33	153935
1289	40	132943
2515	92	174724
2147	100	174415
2352	112	225548
1638	73	223632
1222	40	124817
1812	45	221698
1677	60	210767
1579	62	170266
1731	75	260561
807	31	84853
2452	77	294424
829	34	101011
1940	46	215641
2662	99	325107
186	17	7176
1499	66	167542
865	30	106408
1793	76	96560
2527	146	265769
2747	67	269651
1324	56	149112
2702	107	175824
1383	58	152871
1179	34	111665
2099	61	116408
4308	119	362301
918	42	78800
1831	66	183167
3373	89	277965
1713	44	150629
1438	66	168809
496	24	24188
2253	259	329267
744	17	65029
1161	64	101097
2352	41	218946
2144	68	244052
4691	168	341570
1112	43	103597
2694	132	233328
1973	105	256462
1769	71	206161
3148	112	311473
2474	94	235800
2084	82	177939
1954	70	207176
1226	57	196553
1389	53	174184
1496	103	143246
2269	121	187559
1833	62	187681
1268	52	119016
1943	52	182192
893	32	73566
1762	62	194979
1403	45	167488
1425	46	143756
1857	63	275541
1840	75	243199
1502	88	182999
1441	46	135649
1420	53	152299
1416	37	120221
2970	90	346485
1317	63	145790
1644	78	193339
870	25	80953
1654	45	122774
1054	46	130585
937	41	112611
3004	144	286468
2008	82	241066
2547	91	148446
1885	71	204713
1626	63	182079
1468	53	140344
2445	62	220516
1964	63	243060
1381	32	162765
1369	39	182613
1659	62	232138
2888	117	265318
1290	34	85574
2845	92	310839
1982	93	225060
1904	54	232317
1391	144	144966
602	14	43287
1743	61	155754
1559	109	164709
2014	38	201940
2143	73	235454
2146	75	220801
874	50	99466
1590	61	92661
1590	55	133328
1210	77	61361
2072	75	125930
1281	72	100750
1401	50	224549
834	32	82316
1105	53	102010
1272	42	101523
1944	71	243511
391	10	22938
761	35	41566
1605	65	152474
530	25	61857
1988	66	99923
1386	41	132487
2395	86	317394
387	16	21054
1742	42	209641
620	19	22648
449	19	31414
800	45	46698
1684	65	131698
1050	35	91735
2699	95	244749
1606	49	184510
1502	37	79863
1204	64	128423
1138	38	97839
568	34	38214
1459	32	151101
2158	65	272458
1111	52	172494
1421	62	108043
2833	65	328107
1955	83	250579
2922	95	351067
1002	29	158015
1060	18	98866
956	33	85439
2186	247	229242
3604	139	351619
1035	29	84207
1417	118	120445
3261	110	324598
1587	67	131069
1424	42	204271
1701	65	165543
1249	94	141722
946	64	116048
1926	81	250047
3352	95	299775
1641	67	195838
2035	63	173260
2312	83	254488
1369	45	104389
1577	30	136084
2201	70	199476
961	32	92499
1900	83	224330
1254	31	135781
1335	67	74408
1597	66	81240
207	10	14688
1645	70	181633
2429	103	271856
151	5	7199
474	20	46660
141	5	17547
1639	36	133368
872	34	95227
1318	48	152601
1018	40	98146
1383	43	79619
1314	31	59194
1335	42	139942
1403	46	118612
910	33	72880
	18	65475
	55	99643
	35	71965
	59	77272
	19	49289
	66	135131
	60	108446
	36	89746
	25	44296
	47	77648
	54	181528
	53	134019
	40	124064
	40	92630
	39	121848
	14	52915
	45	81872
	36	58981
	28	53515
	44	60812
	30	56375
	22	65490
	17	80949
	31	76302
	55	104011
	54	98104
	21	67989
	14	30989
	81	135458
	35	73504
	43	63123
	46	61254
	30	74914
	23	31774
	38	81437
	54	87186
	20	50090
	53	65745
	45	56653
	39	158399
	20	46455
	24	73624
	31	38395
	35	91899
	151	139526
	52	52164
	30	51567
	31	70551
	29	84856
	57	102538
	40	86678
	44	85709
	25	34662
	77	150580
	35	99611
	11	19349
	63	99373
	44	86230
	19	30837
	13	31706
	42	89806
	38	62088
	29	40151
	20	27634
	27	76990
	20	37460
	19	54157
	37	49862
	26	84337
	42	64175
	49	59382
	30	119308
	49	76702
	67	103425
	28	70344
	19	43410
	49	104838
	27	62215
	30	69304
	22	53117
	12	19764
	31	86680
	20	84105
	20	77945
	39	89113
	29	91005
	16	40248
	27	64187
	21	50857
	19	56613
	35	62792
	14	72535





Summary of computational transaction
Raw Inputview raw input (R code)
Raw Outputview raw output of R engine
Computing time3 seconds
R Server'Gertrude Mary Cox' @ cox.wessa.net
R Framework error message
Warning: there are blank lines in the 'Data X' field.
Please, use NA for missing data - blank lines are simply
 deleted and are NOT treated as missing values.

\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 & 3 seconds \tabularnewline
R Server & 'Gertrude Mary Cox' @ cox.wessa.net \tabularnewline
R Framework error message & 
Warning: there are blank lines in the 'Data X' field.
Please, use NA for missing data - blank lines are simply
 deleted and are NOT treated as missing values.
\tabularnewline \hline \end{tabular} %Source: https://freestatistics.org/blog/index.php?pk=154135&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]3 seconds[/C][/ROW]
[ROW][C]R Server[/C][C]'Gertrude Mary Cox' @ cox.wessa.net[/C][/ROW]
[ROW][C]R Framework error message[/C][C]
Warning: there are blank lines in the 'Data X' field.
Please, use NA for missing data - blank lines are simply
 deleted and are NOT treated as missing values.
[/C][/ROW] [/TABLE] Source: https://freestatistics.org/blog/index.php?pk=154135&T=0

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=154135&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 time3 seconds
R Server'Gertrude Mary Cox' @ cox.wessa.net
R Framework error message
Warning: there are blank lines in the 'Data X' field.
Please, use NA for missing data - blank lines are simply
 deleted and are NOT treated as missing values.







Confusion Matrix (predicted in columns / actuals in rows)
C1C2
C112817
C212132

\begin{tabular}{lllllllll}
\hline
Confusion Matrix (predicted in columns / actuals in rows) \tabularnewline
 & C1 & C2 \tabularnewline
C1 & 128 & 17 \tabularnewline
C2 & 12 & 132 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=154135&T=1

[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]128[/C][C]17[/C][/ROW]
[ROW][C]C2[/C][C]12[/C][C]132[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=154135&T=1

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

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
C112817
C212132



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