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 10:45:39 -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/t1324655223p3f8sp22uckyg2h.htm/, Retrieved Mon, 29 Apr 2024 18:16:17 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=160518, Retrieved Mon, 29 Apr 2024 18:16:17 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact108
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 18:59:57] [b98453cac15ba1066b407e146608df68]
-   PD  [Recursive Partitioning (Regression Trees)] [WS10 - Recursive ...] [2011-12-14 15:18:50] [2628f630b839c9d14ba9c3627ab0414a]
- R P     [Recursive Partitioning (Regression Trees)] [paper] [2011-12-22 14:34:01] [2628f630b839c9d14ba9c3627ab0414a]
-   P       [Recursive Partitioning (Regression Trees)] [paper] [2011-12-22 15:01:36] [2628f630b839c9d14ba9c3627ab0414a]
-   P           [Recursive Partitioning (Regression Trees)] [] [2011-12-23 15:45:39] [d41d8cd98f00b204e9800998ecf8427e] [Current]
Feedback Forum

Post a new message
Dataseries X:
127476	20	17	59	22622
130358	38	17	50	73570
7215	0	0	0	1929
112861	49	22	51	36294
210171	74	30	112	62378
393802	104	31	118	167760
117604	37	19	59	52443
126029	53	25	90	57283
99729	42	30	50	36614
256310	62	26	79	93268
113066	50	20	49	35439
156212	65	25	74	72405
69952	28	15	32	24044
152673	48	22	82	55909
125841	42	12	43	44689
125769	47	19	65	49319
123467	71	28	111	62075
56232	0	12	36	2341
108244	50	28	89	40551
22762	12	13	28	11621
48554	16	14	35	18741
178697	76	27	78	84202
139115	29	25	67	15334
93773	38	30	61	28024
133398	50	21	58	53306
113933	33	17	49	37918
144781	45	22	77	54819
140711	59	28	71	89058
283337	49	25	82	103354
158146	40	16	53	70239
123344	40	23	71	33045
157640	51	20	58	63852
91279	41	11	25	30905
189374	73	20	59	24242
167915	43	21	77	78907
0	0	0	0	0
175403	46	27	75	36005
92342	44	14	39	31972
100023	31	29	83	35853
178277	71	31	123	115301
145062	61	19	67	47689
110980	28	30	105	34223
86039	21	23	76	43431
119514	42	20	54	52220
95535	44	22	82	33863
109894	34	19	57	46879
61554	15	32	57	23228
156520	46	18	72	42827
159121	43	26	94	65765
129362	47	25	72	38167
48188	12	22	39	14812
91198	42	19	60	32615
229864	56	24	84	82188
180317	41	26	69	51763
150640	48	27	102	59325
104416	30	10	28	48976
159645	44	26	65	43384
63205	25	23	67	26692
100056	42	21	80	53279
137214	28	34	79	20652
99630	33	29	107	38338
84557	32	18	57	36735
91199	28	16	44	42764
83419	31	23	59	44331
101723	13	22	80	41354
94982	38	29	89	47879
129700	39	31	115	103793
110708	68	21	59	52235
81518	32	21	66	49825
31970	5	21	42	4105
192268	53	15	35	58687
87611	33	9	3	40745
77890	48	21	68	33187
83261	36	18	38	14063
116290	52	31	107	37407
55254	0	24	69	7190
116173	52	24	80	49562
111488	45	22	69	76324
60138	16	21	46	21928
73422	33	26	52	27860
67751	48	22	58	28078
213351	33	26	85	49577
51185	24	20	13	28145
97181	37	25	61	36241
42311	16	19	49	10824
115801	32	22	47	46892
183637	55	25	93	61264
68161	36	22	65	22933
76441	29	21	64	20787
103613	26	20	64	43978
98707	37	23	57	51305
126527	58	22	61	55593
136781	35	21	71	51648
105863	24	12	43	30552
38775	18	9	18	23470
179984	37	32	103	77530
164808	86	24	76	57299
19349	13	1	0	9604
143902	20	24	83	34684
108660	32	22	70	41094
43803	8	4	4	3439
47062	38	15	41	25171
110845	45	21	57	23437
92517	24	23	52	34086
58660	23	12	24	24649
27676	2	16	17	2342
98550	52	24	89	45571
43284	5	9	20	3255
0	0	0	0	0
66016	43	22	45	30002
57359	18	17	63	19360
96933	41	18	48	43320
70369	45	21	70	35513
65494	29	17	32	23536
3616	0	0	0	0
0	0	0	0	0
143931	32	20	72	54438
109894	58	26	56	56812
122973	17	26	64	33838
84336	24	20	77	32366
43410	7	1	3	13
136250	62	24	73	55082
79015	30	14	37	31334
92937	49	26	54	16612
57586	3	12	32	5084
19764	10	2	4	9927
105757	42	16	55	47413
96410	18	22	81	27389
113402	40	28	90	30425
11796	1	2	1	0
7627	0	0	0	0
121085	29	17	38	33510
6836	0	1	0	0
139563	46	17	36	40389
5118	5	0	0	0
40248	8	4	7	6012
0	0	0	0	0
95079	21	25	75	22205
80750	21	26	52	17231
7131	0	0	0	0
4194	0	0	0	0
60378	15	15	45	11017
96971	40	18	60	46741
83484	17	19	48	39869




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

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







10-Fold Cross Validation
Prediction (training)Prediction (testing)
ActualC1C2CVC1C2CV
C14721700.735248300.6154
C2575920.91226650.9155
Overall--0.8242--0.7584

\begin{tabular}{lllllllll}
\hline
10-Fold Cross Validation \tabularnewline
 & Prediction (training) & Prediction (testing) \tabularnewline
Actual & C1 & C2 & CV & C1 & C2 & CV \tabularnewline
C1 & 472 & 170 & 0.7352 & 48 & 30 & 0.6154 \tabularnewline
C2 & 57 & 592 & 0.9122 & 6 & 65 & 0.9155 \tabularnewline
Overall & - & - & 0.8242 & - & - & 0.7584 \tabularnewline
\hline
\end{tabular}
%Source: https://freestatistics.org/blog/index.php?pk=160518&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]472[/C][C]170[/C][C]0.7352[/C][C]48[/C][C]30[/C][C]0.6154[/C][/ROW]
[ROW][C]C2[/C][C]57[/C][C]592[/C][C]0.9122[/C][C]6[/C][C]65[/C][C]0.9155[/C][/ROW]
[ROW][C]Overall[/C][C]-[/C][C]-[/C][C]0.8242[/C][C]-[/C][C]-[/C][C]0.7584[/C][/ROW]
[/TABLE]
Source: https://freestatistics.org/blog/index.php?pk=160518&T=1

Globally Unique Identifier (entire table): ba.freestatistics.org/blog/index.php?pk=160518&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
C14721700.735248300.6154
C2575920.91226650.9155
Overall--0.8242--0.7584







Confusion Matrix (predicted in columns / actuals in rows)
C1C2
C15418
C2765

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

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



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