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

Original text written by user:
IsPrivate?No (this computation is public)
User-defined keywords
Estimated Impact53
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]
-   PD    [Recursive Partitioning (Regression Trees)] [Recursive partiti...] [2011-12-23 22:10:25] [4a884731c0d5b018eba30cab82c9416a] [Current]
Feedback Forum

Post a new message
Dataseries X:
94	30	112285	79	146283
103	28	84786	58	98364
93	38	83123	60	86146
103	30	101193	108	96933
51	22	38361	49	79234
70	26	68504	0	42551
91	25	119182	121	195663
22	18	22807	1	6853
38	11	17140	20	21529
93	26	116174	43	95757
60	25	57635	69	85584
123	38	66198	78	143983
148	44	71701	86	75851
90	30	57793	44	59238
124	40	80444	104	93163
70	34	53855	63	96037
168	47	97668	158	151511
115	30	133824	102	136368
71	31	101481	77	112642
66	23	99645	82	94728
134	36	114789	115	105499
117	36	99052	101	121527
108	30	67654	80	127766
84	25	65553	50	98958
156	39	97500	83	77900
120	34	69112	123	85646
114	31	82753	73	98579
94	31	85323	81	130767
120	33	72654	105	131741
81	25	30727	47	53907
110	33	77873	105	178812
133	35	117478	94	146761
122	42	74007	44	82036
158	43	90183	114	163253
109	30	61542	38	27032
124	33	101494	107	171975
39	13	27570	30	65990
92	32	55813	71	86572
126	36	79215	84	159676
0	0	1423	0	1929
70	28	55461	59	85371
37	14	31081	33	58391
38	17	22996	42	31580
120	32	83122	96	136815
93	30	70106	106	120642
95	35	60578	56	69107
77	20	39992	57	50495
90	28	79892	59	108016
80	28	49810	39	46341
31	39	71570	34	78348
110	34	100708	76	79336
66	26	33032	20	56968
138	39	82875	91	93176
133	39	139077	115	161632
113	33	71595	85	87850
100	28	72260	76	127969
7	4	5950	8	15049
140	39	115762	79	155135
61	18	32551	21	25109
41	14	31701	30	45824
96	29	80670	76	102996
164	44	143558	101	160604
78	21	117105	94	158051
49	16	23789	27	44547
102	28	120733	92	162647
124	35	105195	123	174141
99	28	73107	75	60622
129	38	132068	128	179566
62	23	149193	105	184301
73	36	46821	55	75661
114	32	87011	56	96144
99	29	95260	41	129847
70	25	55183	72	117286
104	27	106671	67	71180
116	36	73511	75	109377
91	28	92945	114	85298
74	23	78664	118	73631
138	40	70054	77	86767
67	23	22618	22	23824
151	40	74011	66	93487
72	28	83737	69	82981
120	34	69094	105	73815
115	33	93133	116	94552
105	28	95536	88	132190
104	34	225920	73	128754
108	30	62133	99	66363
98	33	61370	62	67808
69	22	43836	53	61724
111	38	106117	118	131722
99	26	38692	30	68580
71	35	84651	100	106175
27	8	56622	49	55792
69	24	15986	24	25157
107	29	95364	67	76669
73	20	26706	46	57283
107	29	89691	57	105805
93	45	67267	75	129484
129	37	126846	135	72413
69	33	41140	68	87831
118	33	102860	124	96971
73	25	51715	33	71299
119	32	55801	98	77494
104	29	111813	58	120336
107	28	120293	68	93913
99	28	138599	81	136048
90	31	161647	131	181248
197	52	115929	110	146123
36	21	24266	37	32036
85	24	162901	130	186646
139	41	109825	93	102255
106	33	129838	118	168237
50	32	37510	39	64219
64	19	43750	13	19630
31	20	40652	74	76825
63	31	87771	81	115338
92	31	85872	109	109427
106	32	89275	151	118168
63	18	44418	51	84845
69	23	192565	28	153197
41	17	35232	40	29877
56	20	40909	56	63506
25	12	13294	27	22445
65	17	32387	37	47695
93	30	140867	83	68370
114	31	120662	54	146304
38	10	21233	27	38233
44	13	44332	28	42071
87	22	61056	59	50517
110	42	101338	133	103950
0	1	1168	12	5841
27	9	13497	0	2341
83	32	65567	106	84396
30	11	25162	23	24610
80	25	32334	44	35753
98	36	40735	71	55515
82	31	91413	116	209056
0	0	855	4	6622
60	24	97068	62	115814
28	13	44339	12	11609
9	8	14116	18	13155
33	13	10288	14	18274
59	19	65622	60	72875
49	18	16563	7	10112
115	33	76643	98	142775
140	40	110681	64	68847
49	22	29011	29	17659
120	38	92696	32	20112
66	24	94785	25	61023
21	8	8773	16	13983
124	35	83209	48	65176
152	43	93815	100	132432
139	43	86687	46	112494
38	14	34553	45	45109
144	41	105547	129	170875
120	38	103487	130	180759
160	45	213688	136	214921
114	31	71220	59	100226
39	13	23517	25	32043
78	28	56926	32	54454
119	31	91721	63	78876
141	40	115168	95	170745
101	30	111194	14	6940
56	16	51009	36	49025
133	37	135777	113	122037
83	30	51513	47	53782
116	35	74163	92	127748
90	32	51633	70	86839
36	27	75345	19	44830
50	20	33416	50	77395
61	18	83305	41	89324
97	31	98952	91	103300
98	31	102372	111	112283
78	21	37238	41	10901
117	39	103772	120	120691
148	41	123969	135	58106
41	13	27142	27	57140
105	32	135400	87	122422
55	18	21399	25	25899
132	39	130115	131	139296
44	14	24874	45	52678
21	7	34988	29	23853
50	17	45549	58	17306
0	0	6023	4	7953
73	30	64466	47	89455
86	37	54990	109	147866
0	0	1644	7	4245
13	5	6179	12	21509
4	1	3926	0	7670
57	16	32755	37	66675
48	32	34777	37	14336
46	24	73224	46	53608
48	17	27114	15	30059
32	11	20760	42	29668
68	24	37636	7	22097
87	22	65461	54	96841
43	12	30080	54	41907
67	19	24094	14	27080
46	13	69008	16	35885
46	17	54968	33	41247
56	15	46090	32	28313
48	16	27507	21	36845
44	24	10672	15	16548
60	15	34029	38	36134
65	17	46300	22	55764
55	18	24760	28	28910
38	20	18779	10	13339
52	16	21280	31	25319
60	16	40662	32	66956
54	18	28987	32	47487
86	22	22827	43	52785
24	8	18513	27	44683
52	17	30594	37	35619
49	18	24006	20	21920
61	16	27913	32	45608
61	23	42744	0	7721
81	22	12934	5	20634
43	13	22574	26	29788
40	13	41385	10	31931
40	16	18653	27	37754
56	16	18472	11	32505
68	20	30976	29	40557
79	22	63339	25	94238
47	17	25568	55	44197
57	18	33747	23	43228
41	17	4154	5	4103
29	12	19474	43	44144
3	7	35130	23	32868
60	17	39067	34	27640
30	14	13310	36	14063
79	23	65892	35	28990
47	17	4143	0	4694
40	14	28579	37	42648
48	15	51776	28	64329
36	17	21152	16	21928
42	21	38084	26	25836
49	18	27717	38	22779
57	18	32928	23	40820
12	17	11342	22	27530
40	17	19499	30	32378
43	16	16380	16	10824
33	15	36874	18	39613
77	21	48259	28	60865
43	16	16734	32	19787
45	14	28207	21	20107
47	15	30143	23	36605
43	17	41369	29	40961
45	15	45833	50	48231
50	15	29156	12	39725
35	10	35944	21	21455
7	6	36278	18	23430
71	22	45588	27	62991
67	21	45097	41	49363
0	1	3895	13	9604
62	18	28394	12	24552
54	17	18632	21	31493
4	4	2325	8	3439
25	10	25139	26	19555
40	16	27975	27	21228
38	16	14483	13	23177
19	9	13127	16	22094
17	16	5839	2	2342
67	17	24069	42	38798
14	7	3738	5	3255
30	15	18625	37	24261
54	14	36341	17	18511
35	14	24548	38	40798
59	18	21792	37	28893
24	12	26263	29	21425
58	16	23686	32	50276
42	21	49303	35	37643
46	19	25659	17	30377
61	16	28904	20	27126
3	1	2781	7	13
52	16	29236	46	42097
25	10	19546	24	24451
40	19	22818	40	14335
32	12	32689	3	5084
4	2	5752	10	9927
49	14	22197	37	43527
63	17	20055	17	27184
67	19	25272	28	21610
32	14	82206	19	20484
23	11	32073	29	20156
7	4	5444	8	6012
54	16	20154	10	18475
37	20	36944	15	12645
35	12	8019	15	11017
51	15	30884	28	37623
39	16	19540	17	35873




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

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







Confusion Matrix (predicted in columns / actuals in rows)
C1C2
C112619
C26138

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

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



Parameters (Session):
par1 = kendall ; par2 = equal ; 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')
}