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 computationFri, 16 Dec 2011 08:34:33 -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/16/t1324042556fwk07mtytnef1az.htm/, Retrieved Sun, 05 May 2024 11:08:56 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=155914, Retrieved Sun, 05 May 2024 11:08:56 +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)] [] [2011-12-16 13:34:33] [5988e21ec0676b551e455a86717edc1d] [Current]
- R P     [Recursive Partitioning (Regression Trees)] [] [2011-12-20 10:08:08] [74be16979710d4c4e7c6647856088456]
Feedback Forum

Post a new message
Dataseries X:
140824	186099	165	0	474	38	144	83899
110459	113854	132	3	421	34	133	62711
105079	99776	121	0	673	42	162	122597
112098	106194	145	3	1137	38	148	112249
43929	100792	71	2	333	27	88	56414
76173	47552	47	2	179	35	129	23297
187326	250931	177	8	2146	33	128	231677
22807	6853	5	0	111	18	67	26333
144408	115466	124	1	735	34	132	92356
66485	110896	92	1	585	33	120	100802
79089	169351	149	5	754	42	155	123523
81625	94853	93	5	650	55	210	141038
68788	72591	70	0	615	35	115	84032
103297	101345	148	0	1117	52	179	242821
69446	113713	100	0	599	42	158	98074
114948	165354	142	8	1638	59	223	204399
167949	164263	194	3	724	36	140	127837
125081	135213	113	1	1139	39	144	179805
125818	111669	162	7	491	29	111	57017
136588	134163	186	14	675	46	179	121853
112431	140303	147	1	819	45	171	128937
103037	150773	137	3	1203	39	144	274771
82317	111848	71	3	421	25	89	50114
118906	102509	123	5	601	52	208	87388
83515	96785	134	6	1156	41	153	103760
104581	116136	115	1	923	38	146	87587
103129	158376	138	9	1061	41	158	108822
83243	153990	125	7	593	39	142	109222
37110	64057	66	4	559	32	117	91858
113344	230054	137	7	1016	41	158	96751
139165	184531	152	3	886	45	175	87130
86652	114198	159	6	605	47	174	82994
112302	198299	159	2	779	48	185	120264
69652	33750	31	0	310	37	141	63967
119442	189723	185	14	1135	39	151	157208
69867	100826	78	0	1186	42	159	173124
101629	188355	117	4	1287	41	151	223454
70168	104470	109	3	585	36	139	103722
31081	58391	41	0	276	17	55	57078
103925	164808	149	9	1139	39	151	163531
92622	134097	123	0	1490	39	145	190081
79011	80238	103	1	590	38	138	77659
93487	133252	87	7	632	36	115	59631
64520	54518	71	2	464	42	157	118932
93473	121850	51	1	1022	45	73	31928
114360	79367	70	1	2005	38	138	366195
33032	56968	21	0	330	26	82	21832
96125	106314	155	0	648	52	201	101737
151911	191889	172	2	1305	47	181	131263
89256	104864	133	3	868	45	164	70659
95671	160791	125	3	554	40	158	52259
5950	15049	7	0	218	4	12	9139
149695	191179	158	7	832	44	163	181046
32551	25109	21	0	255	18	67	39920
31701	45824	35	0	454	14	52	55273
100087	129711	133	4	1074	37	134	139882
169707	210012	169	5	642	56	210	92206
150491	194679	256	1	1057	36	134	121210
120192	197680	190	17	992	41	150	124866
95893	81180	100	3	814	36	139	165693
151715	197765	171	0	1288	46	178	162900
176225	214738	267	12	1128	28	101	81448
59900	96252	80	3	1061	42	165	136139
104767	124527	126	4	897	42	163	130023
114799	153242	132	-1	557	37	139	75353
72128	145707	121	5	436	30	116	70320
143592	113963	156	2	562	35	137	73996
89626	134904	133	5	799	44	167	92795
131072	114268	199	1	826	36	135	115430
126817	94333	98	6	600	28	102	72458
81351	102204	109	2	863	45	173	137073
22618	23824	25	1	385	23	88	49742
88977	111563	113	2	712	45	175	130935
92059	91313	126	1	705	38	133	95854
81897	89770	137	3	606	38	148	88511
108146	100125	121	0	965	42	157	248935
126372	165278	178	5	992	36	140	157848
249771	181712	63	5	522	41	154	24347
71154	80906	109	3	648	38	148	104064
71571	75881	101	2	588	37	134	93109
55918	83963	61	2	622	28	109	69650
160141	175721	157	9	1197	45	175	253760
38692	68580	38	0	651	26	99	77339
102812	136323	159	4	656	44	122	144020
56622	55792	58	1	437	8	28	25161
15986	25157	27	0	792	27	101	122949
123534	100922	108	0	342	35	129	45855
108535	118845	83	5	1353	37	143	217209
93879	170492	88	4	891	57	206	136994
144551	81716	164	6	1038	41	155	96779
56750	115750	96	2	786	37	138	135716
127654	105590	192	13	618	38	141	125371
65594	92795	94	2	545	31	114	82449
59938	82390	107	0	1061	36	140	179104
146975	135599	144	6	928	36	140	166284
143372	111542	123	0	555	36	140	77710
168553	162519	170	6	552	35	127	59985
183500	211381	210	3	741	39	141	66789
165986	189944	193	15	1251	58	223	177779
184923	226168	297	10	1389	30	114	166178
140358	117495	125	0	833	51	198	167160
149959	195894	204	4	812	41	155	77748
57224	80684	70	3	640	36	138	106172
43750	19630	49	0	214	19	71	23657
48029	88634	82	0	713	23	84	96668
104978	139292	205	1	686	40	151	63796
100046	128602	111	1	1140	40	155	131090
101047	135848	135	4	1028	40	150	165608
197426	178377	59	1	349	30	112	-58408
160902	106330	70	0	892	41	161	46698
147172	178303	108	4	606	40	149	128649
109432	116938	141	1	682	45	164	180869
1168	5841	11	0	156	1	0	17782
83248	106020	130	0	656	36	139	69512
25162	24610	28	3	192	11	32	37247
45724	74151	101	31	457	45	169	89615
110529	232241	216	3	1162	38	140	151812
855	6622	4	0	146	0	0	14432
101382	127097	97	5	866	30	111	125708
14116	13155	39	0	200	8	25	18806
89506	160501	119	6	1163	39	146	134108
135356	91502	118	3	693	46	175	143567
116066	24469	41	1	485	48	181	150393
144244	88229	107	4	670	29	107	63814
8773	13983	16	0	276	8	27	24231
102153	80716	69	1	646	39	147	108735
117440	157384	160	2	993	47	178	187418
104128	122975	158	15	441	50	193	67968
134238	191469	161	10	1548	48	187	204691
134047	231257	165	7	819	48	187	82955
279488	258287	246	8	1151	50	186	138425
79756	122531	89	1	473	40	151	65461
66089	61394	49	1	401	36	131	41030
102070	86480	107	6	943	40	155	196912
146760	195791	182	5	1429	46	172	205469
154771	18284	16	0	529	39	148	117652
165933	147581	173	2	1654	42	156	225565
64593	72558	90	0	689	39	143	84871
92280	147341	140	0	528	41	151	89029
67150	114651	142	3	873	42	145	144308
128692	100187	126	15	601	32	125	114151
124089	130332	123	2	1545	39	145	232822
125386	134218	239	2	747	36	133	98121
37238	10901	15	1	716	21	79	162359
140015	145758	170	5	940	45	174	171918
150047	75767	123	9	720	50	192	93227
154451	134969	151	3	980	36	132	98324
156349	169216	194	4	815	44	159	132369
0	0	0	0	0	0	0	1
6023	7953	5	0	85	0	0	6735
0	0	0	0	0	0	0	98
0	0	0	0	0	0	0	455
0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	0
84601	105406	122	3	662	37	133	111397
68946	174586	173	1	1041	47	185	190644
0	0	0	0	0	0	0	0
0	0	0	0	0	0	0	203
1644	4245	6	0	74	0	0	2954
6179	21509	13	0	259	5	15	25151
3926	7670	3	0	69	1	4	9877
52789	15673	35	0	285	43	152	101005
0	0	0	0	0	0	0	969
100350	75882	72	8	573	31	113	119710




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

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







Confusion Matrix (predicted in columns / actuals in rows)
C1C2
C16220
C21567

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

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



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