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 15:04:28 -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/t1324414439q7f7ywvzxk332yz.htm/, Retrieved Mon, 06 May 2024 01:16:43 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=158256, Retrieved Mon, 06 May 2024 01:16:43 +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)] [] [2011-12-20 20:04:28] [13d85cac30d4a10947636c080219d4f4] [Current]
Feedback Forum

Post a new message
Dataseries X:
124252	165119	85	1527	104
98956	107269	58	917	111
98073	93497	62	1668	93
106816	100269	108	2283	119
41449	91627	55	992	57
76173	47552	8	577	80
177551	233933	134	3916	107
22807	6853	1	381	22
126938	104380	63	1769	103
61680	98431	77	1606	72
72117	156949	86	1885	123
79738	81817	93	1633	164
57793	59238	44	1433	100
91677	101138	106	2369	143
64631	107158	63	1644	79
106385	155499	160	4197	183
161961	156274	104	1769	123
112669	121777	86	2352	81
114029	105037	92	1217	74
124550	118661	119	2015	158
105416	131187	107	2109	133
72875	145026	86	2448	128
81964	107016	50	1253	84
104880	87242	92	1431	184
76302	91699	123	2582	127
96740	110087	81	2293	128
93071	145447	93	2647	118
78912	143307	113	1709	125
35224	61678	52	1360	89
90694	210080	113	2051	122
125369	165005	109	1858	151
80849	97806	44	1621	122
104434	184471	123	1933	162
65702	27786	38	849	121
108179	184458	111	2640	132
63583	98765	77	2229	110
95066	178441	92	2892	129
62486	100619	74	1664	80
31081	58391	33	917	46
94584	151672	105	2740	127
87408	124437	108	2897	103
68966	79929	66	1413	95
88766	123064	69	1500	100
57139	50466	62	1443	102
90586	100991	50	2369	45
109249	79367	91	4798	116
33032	56968	20	918	66
96056	106257	101	2085	159
146648	178412	129	3655	153
80613	98520	93	1923	131
87026	153670	89	1616	113
5950	15049	8	496	7
131106	174478	79	2306	147
32551	25109	21	744	61
31701	45824	30	1161	41
91072	116772	86	2552	108
159803	189150	116	2273	184
143950	194404	106	3185	115
112368	185881	127	2134	132
82124	67508	75	1863	113
144068	188597	138	3518	141
162627	203618	114	2735	65
55062	87232	55	2151	79
95329	110875	67	2144	121
105612	144756	43	1288	112
62853	129825	88	1540	81
125976	92189	67	1614	116
79146	121158	75	2402	132
108461	96219	114	1955	104
99971	84128	119	1366	80
77826	97960	86	2292	145
22618	23824	22	893	67
84892	103515	67	1935	159
92059	91313	77	1538	82
77993	85407	105	1494	120
104155	95871	119	1994	126
109840	143846	88	1904	118
238712	155387	75	1645	112
67486	74429	112	1700	123
68007	74004	66	1467	98
48194	71987	58	1538	78
134796	150629	132	3320	119
38692	68580	30	1345	99
93587	119855	100	1929	81
56622	55792	49	870	27
15986	25157	26	1713	77
113402	90895	67	1086	118
97967	117510	57	3173	122
74844	144774	95	2234	103
136051	77529	139	2676	129
50548	103123	70	1977	69
112215	104669	134	1782	121
59591	82414	37	1560	81
59938	82390	98	2539	119
137639	128446	58	2118	116
143372	111542	78	1521	123
138599	136048	88	1460	111
174110	197257	142	1865	100
135062	162079	127	3191	197
175681	206286	139	3091	95
130307	109858	108	2232	153
139141	182125	128	2052	118
44244	74168	62	1786	50
43750	19630	13	602	64
48029	88634	89	1966	34
95216	128321	83	1723	76
92288	118936	116	2282	112
94588	127044	157	2338	115
197426	178377	28	923	69
151244	69581	83	1388	108
139206	168019	72	1673	130
106271	113598	134	2074	110
1168	5841	12	398	0
71764	93116	106	1605	83
25162	24610	23	530	30
45635	60611	83	1503	106
101817	226620	125	2622	91
855	6622	4	387	0
100174	121996	71	1842	69
14116	13155	18	449	9
85008	154158	98	2890	123
124254	78489	66	1701	140
105793	22007	44	1401	125
117129	72530	29	1257	81
8773	13983	16	568	21
94747	73397	56	1512	124
107549	143878	112	2359	164
97392	119956	46	1144	139
126893	181558	129	3041	144
118850	208236	139	2117	130
234853	237085	136	2992	168
74783	110297	66	1127	126
66089	61394	42	1045	89
95684	81420	70	2417	137
139537	191154	97	3839	149
144253	11798	49	1412	121
153824	135724	113	3382	133
63995	68614	55	1728	93
84891	139926	100	1506	119
61263	105203	80	1905	102
106221	80338	29	1511	39
113587	121376	95	3602	104
113864	124922	114	1849	111
37238	10901	41	2035	78
119906	135471	128	2503	120
135096	66395	142	1574	169
151611	134041	88	2260	109
144645	153554	142	2045	132
0	0	0	2	0
6023	7953	4	207	0
0	0	0	5	0
0	0	0	8	0
0	0	0	0	0
0	0	0	0	0
77457	98922	56	1777	78
62464	165395	120	2762	104
0	0	0	0	0
0	0	0	4	0
1644	4245	7	151	0
6179	21509	12	474	13
3926	7670	0	141	4
42087	15167	37	969	65
0	0	0	29	0
87656	63891	46	1485	55




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

\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
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=158256&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]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=158256&T=0

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







Confusion Matrix (predicted in columns / actuals in rows)
C1C2C3C4C5
C1245000
C20472000
C30123800
C4011400
C500300

\begin{tabular}{lllllllll}
\hline
Confusion Matrix (predicted in columns / actuals in rows) \tabularnewline
 & C1 & C2 & C3 & C4 & C5 \tabularnewline
C1 & 24 & 5 & 0 & 0 & 0 \tabularnewline
C2 & 0 & 47 & 20 & 0 & 0 \tabularnewline
C3 & 0 & 12 & 38 & 0 & 0 \tabularnewline
C4 & 0 & 1 & 14 & 0 & 0 \tabularnewline
C5 & 0 & 0 & 3 & 0 & 0 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=158256&T=1

[TABLE]
[ROW][C]Confusion Matrix (predicted in columns / actuals in rows)[/C][/ROW]
[ROW][C][/C][C]C1[/C][C]C2[/C][C]C3[/C][C]C4[/C][C]C5[/C][/ROW]
[ROW][C]C1[/C][C]24[/C][C]5[/C][C]0[/C][C]0[/C][C]0[/C][/ROW]
[ROW][C]C2[/C][C]0[/C][C]47[/C][C]20[/C][C]0[/C][C]0[/C][/ROW]
[ROW][C]C3[/C][C]0[/C][C]12[/C][C]38[/C][C]0[/C][C]0[/C][/ROW]
[ROW][C]C4[/C][C]0[/C][C]1[/C][C]14[/C][C]0[/C][C]0[/C][/ROW]
[ROW][C]C5[/C][C]0[/C][C]0[/C][C]3[/C][C]0[/C][C]0[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=158256&T=1

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=158256&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)
C1C2C3C4C5
C1245000
C20472000
C30123800
C4011400
C500300



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