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, 23 Dec 2011 09:48: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/23/t1324651968lnwg17vxp14u0kh.htm/, Retrieved Mon, 29 Apr 2024 18:40:20 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=160469, Retrieved Mon, 29 Apr 2024 18:40:20 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact55
Family? (F = Feedback message, R = changed R code, M = changed R Module, P = changed Parameters, D = changed Data)
-       [Recursive Partitioning (Regression Trees)] [paper - deel III ...] [2011-12-23 14:48:33] [5d2b4a0922f8ef6cb228a07f27aed6b6] [Current]
Feedback Forum

Post a new message
Dataseries X:
140824	96	275243	151	71	32033
110459	71	180141	133	66	20654
105079	70	228925	170	75	16346
112098	134	218443	148	104	35926
43929	67	171533	88	52	10621
76173	8	70849	129	28	10024
187326	160	532492	128	125	43068
22807	1	33186	67	19	1271
144408	83	217320	132	59	34416
66485	82	213274	120	44	20318
79089	92	309323	169	111	24409
81625	117	242739	218	122	20648
68788	56	194882	122	76	12347
103297	139	364569	191	81	21857
69446	80	255231	162	86	11034
114948	176	391748	227	181	33433
167949	114	334118	156	75	35902
125081	105	374892	144	163	22355
125818	103	176082	111	56	31219
136588	135	266736	199	87	21983
112431	123	278265	187	70	40085
103037	87	442703	144	104	18507
82317	66	180393	89	42	16278
118906	103	189897	208	55	24662
83515	149	242176	165	125	31452
104581	113	241883	146	129	32580
103129	99	267318	158	129	22883
83243	117	277501	154	88	27652
37110	57	155915	117	52	9845
113344	141	365373	158	72	20190
139165	130	291907	195	80	46201
86652	50	247188	186	81	10971
112302	140	342856	197	95	34811
69652	43	101014	141	39	3029
119442	141	409551	168	100	38941
69867	83	273950	159	56	4958
101629	112	425253	161	122	32344
70168	79	227636	139	84	19433
31081	33	115658	55	33	12558
103925	137	375992	166	201	36524
92622	125	334004	151	82	26041
79011	76	186648	148	71	16637
93487	78	206196	115	76	28395
64520	68	182286	181	64	16747
93473	50	153778	73	82	9105
114360	101	455401	147	153	11941
33032	20	78800	82	42	7935
96125	101	208277	201	77	19499
151911	149	358127	193	121	22938
89256	108	182715	164	60	25314
95676	95	224649	158	76	28527
5950	8	24188	12	24	2694
149695	88	380576	163	326	20867
32551	21	65029	67	17	3597
31701	30	101097	52	64	5296
100087	97	279128	134	60	32982
169707	130	328024	230	86	38975
150491	132	359138	145	198	42721
120192	161	369539	153	145	41455
95893	89	266240	155	86	23923
151715	160	389724	198	147	26719
176225	139	305351	101	119	53405
59900	104	281929	169	118	12526
104767	92	264889	163	89	26584
114799	52	229585	139	68	37062
72128	117	235052	116	68	25696
143592	93	209030	145	135	24634
89626	85	240070	167	151	27269
131072	143	243937	135	84	25270
126817	143	175816	102	70	24634
81351	99	239337	173	70	17828
22618	22	73566	88	32	3007
88977	78	242622	175	86	20065
92059	83	196387	133	55	24648
81897	131	209049	148	64	21588
108146	140	363250	169	88	25217
126372	148	362030	143	96	30927
249771	80	217036	154	108	18487
71154	133	212643	164	66	18050
71571	97	202011	146	67	17696
55918	62	153654	109	48	17326
160141	161	475859	175	128	39361
38692	30	145943	99	69	9648
102812	118	287359	122	106	26759
56622	49	80953	28	25	7905
15986	52	150216	101	55	4527
123534	76	179317	139	60	41517
108535	85	394546	143	213	21261
93879	146	345373	206	120	36099
144551	165	179811	171	106	39039
56750	84	283459	150	100	13841
127654	165	274449	154	81	23841
65594	48	190312	114	65	8589
59938	149	280628	140	77	15049
146975	75	329007	156	85	39038
166616	83	194106	156	40	36918
168553	110	259365	127	59	39932
183500	164	297464	141	83	43840
165986	154	399815	251	155	43146
184923	165	402133	126	113	50099
140358	121	291970	198	138	40312
149959	150	296670	155	67	32616
57224	73	189276	138	188	11338
43750	13	43287	71	14	7409
48029	89	185969	84	83	18213
104978	105	250254	167	148	45873
100046	129	268391	155	50	39844
101047	169	314131	162	92	28317
197426	28	156967	112	81	24797
160902	118	161884	168	97	7471
147172	79	334485	157	74	27259
109432	147	300526	164	89	23201
1168	12	23623	0	11	238
83248	146	195817	155	73	28830
25162	23	61857	32	25	3913
45724	83	163871	169	50	9935
110529	163	428191	140	120	27738
855	4	21054	0	16	338
101382	81	252805	111	52	13326
14116	18	31961	25	22	3988
89506	114	333052	152	119	24347
135356	76	243223	183	68	27111
116066	55	177264	181	93	3938
144244	44	152043	107	54	17416
8773	16	38214	27	34	1888
102153	81	224597	163	43	18700
117440	137	357602	198	82	36809
104128	50	198104	205	61	24959
134238	142	423741	187	85	37343
134047	157	338606	187	99	21849
279488	141	417175	210	129	49809
79756	71	190323	151	37	21654
66089	42	102424	131	43	8728
102070	94	302158	171	347	20920
146760	117	437141	172	182	27195
154771	63	146250	164	56	1037
165933	127	395382	172	134	42570
64593	55	162575	143	79	17672
92280	117	278077	151	49	34245
67150	110	282410	158	96	16786
128692	39	219493	125	115	20954
124089	95	384177	169	122	16378
125386	128	246963	145	92	31852
37238	41	173260	79	63	2805
140015	146	333967	190	103	38086
150047	147	168994	192	58	21166
154451	119	253330	132	87	34672
156349	185	305217	168	109	36171
0	0	1	0	0	0
6023	4	14688	0	10	2065
0	0	98	0	1	0
0	0	455	0	2	0
0	0	0	0	0	0
0	0	0	0	0	0
84601	75	260345	133	88	19354
68946	157	409163	204	162	22124
0	0	0	0	0	0
0	0	203	0	4	0
1644	7	7199	0	5	556
6179	12	46660	15	20	2089
3926	0	17547	4	5	2658
52789	37	116969	152	45	1813
0	0	969	0	2	0
100350	59	229447	125	70	17372




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

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







10-Fold Cross Validation
Prediction (training)Prediction (testing)
ActualC1C2CVC1C2CV
C11079960.9183109160.872
C21391670.545822120.3529
Overall--0.8413--0.761

\begin{tabular}{lllllllll}
\hline
10-Fold Cross Validation \tabularnewline
 & Prediction (training) & Prediction (testing) \tabularnewline
Actual & C1 & C2 & CV & C1 & C2 & CV \tabularnewline
C1 & 1079 & 96 & 0.9183 & 109 & 16 & 0.872 \tabularnewline
C2 & 139 & 167 & 0.5458 & 22 & 12 & 0.3529 \tabularnewline
Overall & - & - & 0.8413 & - & - & 0.761 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=160469&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]1079[/C][C]96[/C][C]0.9183[/C][C]109[/C][C]16[/C][C]0.872[/C][/ROW]
[ROW][C]C2[/C][C]139[/C][C]167[/C][C]0.5458[/C][C]22[/C][C]12[/C][C]0.3529[/C][/ROW]
[ROW][C]Overall[/C][C]-[/C][C]-[/C][C]0.8413[/C][C]-[/C][C]-[/C][C]0.761[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=160469&T=1

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=160469&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
C11079960.9183109160.872
C21391670.545822120.3529
Overall--0.8413--0.761







Confusion Matrix (predicted in columns / actuals in rows)
C1C2
C111614
C21420

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

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



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