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, 13 Dec 2011 04:34:24 -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/13/t13237688760aj1tt3a5b868aq.htm/, Retrieved Fri, 03 May 2024 00:56:10 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=154311, Retrieved Fri, 03 May 2024 00:56:10 +0000
QR Codes:

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact167
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)] [] [2011-12-13 09:34:24] [888ed98a09d01be7e0be9dfdea403736] [Current]
Feedback Forum

Post a new message
Dataseries X:
79	30	146283	3
58	28	98364	4
60	38	86146	12
108	30	96933	2
49	22	79234	1
0	26	42551	3
121	25	195663	0
1	18	6853	0
20	11	21529	0
43	26	95757	5
69	25	85584	0
78	38	143983	0
86	44	75851	7
44	30	59238	7
104	40	93163	3
63	34	96037	9
158	47	151511	0
102	30	136368	4
77	31	112642	3
82	23	94728	0
115	36	105499	7
101	36	121527	0
80	30	127766	1
50	25	98958	5
83	39	77900	7
123	34	85646	0
73	31	98579	0
81	31	130767	5
105	33	131741	0
47	25	53907	0
105	33	178812	0
94	35	146761	3
44	42	82036	4
114	43	163253	1
38	30	27032	4
107	33	171975	2
30	13	65990	0
71	32	86572	0
84	36	159676	0
0	0	1929	0
59	28	85371	2
33	14	58391	1
42	17	31580	0
96	32	136815	2
106	30	120642	10
56	35	69107	6
57	20	50495	0
59	28	108016	5
39	28	46341	4
34	39	78348	1
76	34	79336	2
20	26	56968	2
91	39	93176	0
115	39	161632	8
85	33	87850	3
76	28	127969	0
8	4	15049	0
79	39	155135	8
21	18	25109	5
30	14	45824	3
76	29	102996	1
101	44	160604	5
94	21	158051	1
27	16	44547	1
92	28	162647	5
123	35	174141	0
75	28	60622	12
128	38	179566	8
105	23	184301	8
55	36	75661	8
56	32	96144	8
41	29	129847	2
72	25	117286	0
67	27	71180	5
75	36	109377	8
114	28	85298	2
118	23	73631	5
77	40	86767	12
22	23	23824	6
66	40	93487	7
69	28	82981	2
105	34	73815	0
116	33	94552	4
88	28	132190	3
73	34	128754	6
99	30	66363	2
62	33	67808	0
53	22	61724	1
118	38	131722	0
30	26	68580	5
100	35	106175	2
49	8	55792	0
24	24	25157	0
67	29	76669	5
46	20	57283	0
57	29	105805	1
75	45	129484	0
135	37	72413	1
68	33	87831	1
124	33	96971	2
33	25	71299	6
98	32	77494	1
58	29	120336	4
68	28	93913	2
81	28	136048	3
131	31	181248	0
110	52	146123	10
37	21	32036	0
130	24	186646	9
93	41	102255	7
118	33	168237	0
39	32	64219	0
13	19	19630	4
74	20	76825	4
81	31	115338	0
109	31	109427	0
151	32	118168	0
51	18	84845	1
28	23	153197	0
40	17	29877	1
56	20	63506	0
27	12	22445	0
37	17	47695	4
83	30	68370	0
54	31	146304	4
27	10	38233	4
28	13	42071	3
59	22	50517	0
133	42	103950	0
12	1	5841	0
0	9	2341	5
106	32	84396	0
23	11	24610	4
44	25	35753	0
71	36	55515	0
116	31	209056	1
4	0	6622	0
62	24	115814	5
12	13	11609	0
18	8	13155	0
14	13	18274	0
60	19	72875	0
7	18	10112	0
98	33	142775	2
64	40	68847	7
29	22	17659	1
32	38	20112	8
25	24	61023	2
16	8	13983	0
48	35	65176	2
100	43	132432	0
46	43	112494	0
45	14	45109	1
129	41	170875	3
130	38	180759	0
136	45	214921	3
59	31	100226	0
25	13	32043	0
32	28	54454	0
63	31	78876	4
95	40	170745	4
14	30	6940	11
36	16	49025	0
113	37	122037	0
47	30	53782	4
92	35	127748	0
70	32	86839	1
19	27	44830	0
50	20	77395	0
41	18	89324	0
91	31	103300	9
111	31	112283	1
41	21	10901	3
120	39	120691	10
135	41	58106	5
27	13	57140	0
87	32	122422	2
25	18	25899	0
131	39	139296	1
45	14	52678	2
29	7	23853	4
58	17	17306	0
4	0	7953	0
47	30	89455	2
109	37	147866	1
7	0	4245	0
12	5	21509	0
0	1	7670	0
37	16	66675	1
37	32	14336	0
46	24	53608	2
15	17	30059	0
42	11	29668	3
7	24	22097	6
54	22	96841	0
54	12	41907	2
14	19	27080	0
16	13	35885	2
33	17	41247	1
32	15	28313	1
21	16	36845	2
15	24	16548	1
38	15	36134	0
22	17	55764	1
28	18	28910	3
10	20	13339	0
31	16	25319	0
32	16	66956	0
32	18	47487	0
43	22	52785	1
27	8	44683	4
37	17	35619	0
20	18	21920	0
32	16	45608	0
0	23	7721	7
5	22	20634	2
26	13	29788	0
10	13	31931	7
27	16	37754	3
11	16	32505	0
29	20	40557	0
25	22	94238	6
55	17	44197	2
23	18	43228	0
5	17	4103	0
43	12	44144	3
23	7	32868	0
34	17	27640	1
36	14	14063	1
35	23	28990	0
0	17	4694	1
37	14	42648	0
28	15	64329	0
16	17	21928	0
26	21	25836	0
38	18	22779	0
23	18	40820	0
22	17	27530	0
30	17	32378	0
16	16	10824	0
18	15	39613	0
28	21	60865	0
32	16	19787	0
21	14	20107	2
23	15	36605	0
29	17	40961	1
50	15	48231	1
12	15	39725	0
21	10	21455	0
18	6	23430	0
27	22	62991	0
41	21	49363	0
13	1	9604	0
12	18	24552	1
21	17	31493	0
8	4	3439	0
26	10	19555	0
27	16	21228	0
13	16	23177	1
16	9	22094	0
2	16	2342	0
42	17	38798	0
5	7	3255	0
37	15	24261	0
17	14	18511	0
38	14	40798	0
37	18	28893	0
29	12	21425	0
32	16	50276	0
35	21	37643	0
17	19	30377	1
20	16	27126	0
7	1	13	0
46	16	42097	1
24	10	24451	0
40	19	14335	6
3	12	5084	3
10	2	9927	1
37	14	43527	2
17	17	27184	0
28	19	21610	0
19	14	20484	0
29	11	20156	3
8	4	6012	1
10	16	18475	0
15	20	12645	0
15	12	11017	1
28	15	37623	0
17	16	35873	0




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=154311&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=154311&T=0

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







Confusion Matrix (predicted in columns / actuals in rows)
C1C2
C11423
C228116

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

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



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