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 computationThu, 22 Dec 2011 06:37:36 -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/22/t1324553896ui8goy4z3u66tcu.htm/, Retrieved Fri, 03 May 2024 05:57:15 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=159336, Retrieved Fri, 03 May 2024 05:57:15 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact77
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)] [Recursive Partiti...] [2011-12-22 11:37:36] [22431204c416bf26bfe4de00cd8c0d22] [Current]
Feedback Forum

Post a new message
Dataseries X:
140824	32033	186099	165	165
110459	20654	113854	135	132
105079	16346	99776	121	121
112098	35926	106194	148	145
43929	10621	100792	73	71
76173	10024	47552	49	47
187326	43068	250931	185	177
22807	1271	6853	5	5
144408	34416	115466	125	124
66485	20318	110896	93	92
79089	24409	169351	154	149
81625	20648	94853	98	93
68788	12347	72591	70	70
103297	21857	101345	148	148
69446	11034	113713	100	100
114948	33433	165354	150	142
167949	35902	164263	197	194
125081	22355	135213	114	113
125818	31219	111669	169	162
136588	21983	134163	200	186
112431	40085	140303	148	147
103037	18507	150773	140	137
82317	16278	111848	74	71
118906	24662	102509	128	123
83515	31452	96785	140	134
104581	32580	116136	116	115
103129	22883	158376	147	138
83243	27652	153990	132	125
37110	9845	64057	70	66
113344	20190	230054	144	137
139165	46201	184531	155	152
86652	10971	114198	165	159
112302	34811	198299	161	159
69652	3029	33750	31	31
119442	38941	189723	199	185
69867	4958	100826	78	78
101629	32344	188355	121	117
70168	19433	104470	112	109
31081	12558	58391	41	41
103925	36524	164808	158	149
92622	26041	134097	123	123
79011	16637	80238	104	103
93487	28395	133252	94	87
64520	16747	54518	73	71
93473	9105	121850	52	51
114360	11941	79367	71	70
33032	7935	56968	21	21
96125	19499	106314	155	155
151911	22938	191889	174	172
89256	25314	104864	136	133
95676	28527	160792	128	125
5950	2694	15049	7	7
149695	20867	191179	165	158
32551	3597	25109	21	21
31701	5296	45824	35	35
100087	32982	129711	137	133
169707	38975	210012	174	169
150491	42721	194679	257	256
120192	41455	197680	207	190
95893	23923	81180	103	100
151715	26719	197765	171	171
176225	53405	214738	279	267
59900	12526	96252	83	80
104767	26584	124527	130	126
114799	37062	153242	131	132
72128	25696	145707	126	121
143592	24634	113963	158	156
89626	27269	134904	138	133
131072	25270	114268	200	199
126817	24634	94333	104	98
81351	17828	102204	111	109
22618	3007	23824	26	25
88977	20065	111563	115	113
92059	24648	91313	127	126
81897	21588	89770	140	137
108146	25217	100125	121	121
126372	30927	165278	183	178
249771	18487	181712	68	63
71154	18050	80906	112	109
71571	17696	75881	103	101
55918	17326	83963	63	61
160141	39361	175721	166	157
38692	9648	68580	38	38
102812	26759	136323	163	159
56622	7905	55792	59	58
15986	4527	25157	27	27
123534	41517	100922	108	108
108535	21261	118845	88	83
93879	36099	170492	92	88
144551	39039	81716	170	164
56750	13841	115750	98	96
127654	23841	105590	205	192
65594	8589	92795	96	94
59938	15049	82390	107	107
146975	39038	135599	150	144
165904	36774	127667	138	136
169265	40076	163073	177	171
183500	43840	211381	213	210
165986	43146	189944	208	193
184923	50099	226168	307	297
140358	40312	117495	125	125
149959	32616	195894	208	204
57224	11338	80684	73	70
43750	7409	19630	49	49
48029	18213	88634	82	82
104978	45873	139292	206	205
100046	39844	128602	112	111
101047	28317	135848	139	135
197426	24797	178377	60	59
160902	7471	106330	70	70
147172	27259	178303	112	108
109432	23201	116938	142	141
1168	238	5841	11	11
83248	28830	106020	130	130
25162	3913	24610	31	28
45724	9935	74151	132	101
110529	27738	232241	219	216
855	338	6622	4	4
101382	13326	127097	102	97
14116	3988	13155	39	39
89506	24347	160501	125	119
135356	27111	91502	121	118
116066	3938	24469	42	41
144244	17416	88229	111	107
8773	1888	13983	16	16
102153	18700	80716	70	69
117440	36809	157384	162	160
104128	24959	122975	173	158
134238	37343	191469	171	161
134047	21849	231257	172	165
279488	49809	258287	254	246
79756	21654	122531	90	89
66089	8728	61394	50	49
102070	20920	86480	113	107
146760	27195	195791	187	182
154771	1037	18284	16	16
165933	42570	147581	175	173
64593	17672	72558	90	90
92280	34245	147341	140	140
67150	16786	114651	145	142
128692	20954	100187	141	126
124089	16378	130332	125	123
125386	31852	134218	241	239
37238	2805	10901	16	15
140015	38086	145758	175	170
150047	21166	75767	132	123
154451	34672	134969	154	151
156349	36171	169216	198	194
0	0	0	0	0
6023	2065	7953	5	5
0	0	0	0	0
0	0	0	0	0
0	0	0	0	0
0	0	0	0	0
84601	19354	105406	125	122
68946	22124	174586	174	173
0	0	0	0	0
0	0	0	0	0
1644	556	4245	6	6
6179	2089	21509	13	13
3926	2658	7670	3	3
52789	1813	15673	35	35
0	0	0	0	0
100350	17372	75882	80	72




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

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=159336&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'Herman Ole Andreas Wold' @ wold.wessa.net







Confusion Matrix (predicted in columns / actuals in rows)
C1C2
C1775
C23250

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

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



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')
}