Free Statistics

of Irreproducible Research!

Author's title

Author*The author of this computation has been verified*
R Software Module--
Title produced by softwareRecursive Partitioning (Regression Trees)
Date of computationFri, 23 Dec 2011 08:47:49 -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/23/t132464808927mwgjxeq71okkh.htm/, Retrieved Thu, 31 Oct 2024 22:47:15 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=160408, Retrieved Thu, 31 Oct 2024 22:47:15 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact110
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)] [WS X-recursive pa...] [2011-12-13 20:04:30] [7c680a04865e75aa8ab422cdbfd97ac3]
-  MP       [Recursive Partitioning (Regression Trees)] [Paper with categ] [2011-12-23 13:47:49] [c18e83883fa784c15a15b4fbc0636edd] [Current]
Feedback Forum

Post a new message
Dataseries X:
252101	62	438	92	34	104	165119

134577	59	330	58	30	111	107269

198520	62	609	62	38	93	93497

189326	94	1015	108	34	119	100269

137449	43	294	55	25	57	91627

65295	27	164	8	31	80	47552

439387	103	1912	134	29	107	233933

33186	19	111	1	18	22	6853

178368	51	698	64	30	103	104380

186657	38	556	77	29	72	98431

261949	96	711	86	38	123	156949

191051	95	495	93	49	164	81817

138866	57	544	44	33	100	59238

296878	66	959	106	46	143	101138

192648	72	540	63	38	79	107158

333462	162	1486	160	52	183	155499

243571	58	635	104	32	123	156274

263451	130	940	86	35	81	121777

155679	48	452	93	25	74	105037

227053	70	617	119	42	158	118661

240028	63	695	107	40	133	131187

388549	90	1046	86	35	128	145026

156540	34	405	50	25	84	107016

148421	43	477	92	46	184	87242

177732	97	1012	123	36	127	91699

191441	105	842	81	35	128	110087

249893	122	994	93	38	118	145447

236812	76	530	113	35	125	143307

142329	45	515	52	28	89	61678

259667	53	766	113	37	122	210080

231625	65	734	112	40	151	165005

176062	67	551	44	42	122	97806

286683	79	718	123	44	162	184471

87485	33	280	38	33	121	27786

322865	83	1055	111	35	132	184458

247082	51	950	77	37	110	98765

344092	104	1035	92	39	135	178441

191653	74	552	74	32	80	100619

114673	31	275	33	17	46	58391

284224	161	986	105	34	127	151672

284195	72	1336	108	33	103	124437

155363	59	565	66	35	95	79929

177306	67	571	69	32	100	123064

144571	49	404	62	35	102	50466

140319	73	985	50	45	45	100991

405267	135	1851	91	38	122	79367

78800	42	330	20	26	66	56968

201970	69	611	101	45	159	106257

302674	99	1249	129	44	153	178412

164733	50	812	93	40	131	98520

194221	68	501	89	33	113	153670

24188	24	218	8	4	7	15049

342263	279	785	79	41	147	174478

65029	17	255	21	18	61	25109

101097	64	454	30	14	41	45824

246088	46	944	86	33	108	116772

273108	75	600	116	49	184	189150

282220	160	977	106	32	115	194404

273495	119	863	127	37	132	185881

214872	74	690	75	32	113	67508

335121	123	1176	138	41	141	188597

267171	106	1013	114	25	65	203618

187938	88	890	55	40	87	87232

229512	78	777	67	35	121	110875

209798	61	521	45	33	112	144756

201345	60	409	88	28	81	129825

163833	113	493	67	31	116	92189

204250	129	757	75	40	132	121158

197813	67	736	114	32	104	96219

132955	60	511	123	25	80	84128

216092	59	789	86	42	145	97960

73566	32	385	22	23	67	23824

213198	67	644	67	42	159	103515

181713	49	664	77	38	90	91313

148698	49	505	105	34	120	85407

300103	70	878	119	38	126	95871

251437	78	769	88	32	118	143846

197295	101	499	78	37	112	155387

158163	55	546	112	34	123	74429

155529	57	551	66	33	98	74004

132672	41	565	58	25	78	71987

377205	100	1086	132	40	119	150629

145905	66	649	30	26	99	68580

223701	86	540	100	40	81	119855

80953	25	437	49	8	27	55792

130805	47	732	26	27	77	25157

135082	48	308	67	32	118	90895

300170	154	1236	57	33	122	117510

271806	95	783	95	50	103	144774

150949	96	933	139	37	129	77529

225805	79	710	73	33	69	103123

197389	67	563	134	34	121	104669

156583	56	508	37	28	81	82414

222599	66	936	98	32	119	82390

261601	70	838	58	32	116	128446

178489	35	523	78	32	123	111542

200657	43	500	88	31	111	136048

259084	67	691	142	35	100	197257

313075	130	1060	127	58	221	162079

346933	100	1232	139	27	95	206286

246440	104	735	108	45	153	109858

252444	58	757	128	37	118	182125

159965	159	574	62	32	50	74168

43287	14	214	13	19	64	19630

172239	68	661	89	22	34	88634

181897	119	630	83	35	76	128321

227681	43	1015	116	36	112	118936

260464	81	893	157	36	115	127044

106288	54	293	28	23	69	178377

109632	76	446	83	36	108	69581

268905	58	538	72	36	130	168019

266805	78	627	134	42	110	113598

23623	11	156	12	1	0	5841

152474	65	577	106	32	83	93116

61857	25	192	23	11	30	24610

144889	43	437	83	40	106	60611

346600	99	1054	126	34	91	226620

21054	16	146	4	0	0	6622

224051	45	751	71	27	69	121996

31414	19	200	18	8	9	13155

261043	105	1050	98	35	123	154158

197819	57	590	66	41	143	78489

154984	73	430	44	40	125	22007

112933	45	467	29	28	81	72530

38214	34	276	16	8	21	13983

158671	33	528	56	35	124	73397

302148	70	898	112	47	168	143878

177918	55	411	46	46	149	119956

350552	70	1362	129	42	147	181558

275578	91	743	139	48	145	208236

366217	105	1068	136	49	172	237085

172464	31	431	66	35	126	110297

94381	35	380	42	32	89	61394

243875	278	788	70	36	137	81420

382487	153	1367	97	42	149	191154

114525	40	449	49	35	121	11798

335681	119	1461	113	37	133	135724

147989	72	651	55	34	93	68614

216638	44	494	100	36	119	139926

192862	72	667	80	36	102	105203

184818	107	510	29	32	45	80338

336707	105	1472	95	33	104	121376

215836	76	675	114	35	111	124922

173260	63	716	41	21	78	10901

271773	89	814	128	40	120	135471

130908	52	556	142	49	176	66395

204009	75	887	88	33	109	134041

245514	92	663	147	39	132	153554

1	0	0	0	0	0	0

14688	10	85	4	0	0	7953

98	1	0	0	0	0	0

455	2	0	0	0	0	0

0	0	0	0	0	0	0

0	0	0	0	0	0	0

195765	75	607	56	33	78	98922

326038	121	934	121	42	104	165395

0	0	0	0	0	0	0

203	4	0	0	0	0	0

7199	5	74	7	0	0	4245

46660	20	259	12	5	13	21509

17547	5	69	0	1	4	7670

107465	38	267	37	38	65	15167

969	2	0	0	0	0	0

173102	58	517	47	28	55	63891




Summary of computational transaction
Raw Inputview raw input (R code)
Raw Outputview raw output of R engine
Computing time3 seconds
R Server'Gwilym Jenkins' @ jenkins.wessa.net
R Framework error message
Warning: there are blank lines in the 'Data' 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 & 'Gwilym Jenkins' @ jenkins.wessa.net \tabularnewline
R Framework error message & 
Warning: there are blank lines in the 'Data' 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=160408&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]'Gwilym Jenkins' @ jenkins.wessa.net[/C][/ROW]
[ROW][C]R Framework error message[/C][C]
Warning: there are blank lines in the 'Data' 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=160408&T=0

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=160408&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'Gwilym Jenkins' @ jenkins.wessa.net
R Framework error message
Warning: there are blank lines in the 'Data' 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
C16517
C2577

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

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



Parameters (Session):
par1 = 1 ; par2 = Do not include Seasonal Dummies ; par3 = No Linear Trend ;
Parameters (R input):
par1 = 1 ; par2 = quantiles ; par3 = 2 ; par4 = no ; par5 = ; par6 = ; par7 = ; par8 = ; par9 = ; par10 = ; par11 = ; par12 = ; par13 = ; par14 = ; par15 = ; par16 = ; par17 = ; par18 = ; par19 = ; par20 = ;
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')
}