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 05:05:29 -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/t1324375573l99hvlhvsg3c58b.htm/, Retrieved Sun, 05 May 2024 21:11:47 +0000
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL https://freestatistics.org/blog/index.php?pk=157870, Retrieved Sun, 05 May 2024 21:11:47 +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)] [] [2011-12-20 10:05:29] [542c32830549043c4555f1bd78aefedb] [Current]
-   P     [Recursive Partitioning (Regression Trees)] [] [2011-12-20 10:07:56] [ec2187f7727da5d5d939740b21b8b68a]
-   P     [Recursive Partitioning (Regression Trees)] [] [2011-12-20 10:27:55] [ec2187f7727da5d5d939740b21b8b68a]
Feedback Forum

Post a new message
Dataseries X:
1418	30	112285	145	0
869	28	84786	101	0
1530	38	83123	98	0
2172	30	101193	132	0
901	22	38361	60	0
463	26	68504	38	0
3201	25	119182	144	0
371	18	22807	5	0
1192	11	17140	28	1
1583	26	116174	84	0
1439	25	57635	79	0
1764	38	66198	127	0
1495	44	71701	78	0
1373	30	57793	60	0
2187	40	80444	131	0
1491	34	53855	84	0
4041	47	97668	133	0
1706	30	133824	150	0
2152	31	101481	91	0
1036	23	99645	132	0
1882	36	114789	136	0
1929	36	99052	124	0
2242	30	67654	118	0
1220	25	65553	70	0
1289	39	97500	107	0
2515	34	69112	119	0
2147	31	82753	89	0
2352	31	85323	112	0
1638	33	72654	108	0
1222	25	30727	52	0
1812	33	77873	112	0
1677	35	117478	116	0
1579	42	74007	123	0
1731	43	90183	125	0
807	30	61542	27	0
2452	33	101494	162	0
829	13	27570	32	1
1940	32	55813	64	0
2662	36	79215	92	0
186	0	1423	0	1
1499	28	55461	83	0
865	14	31081	41	0
1793	17	22996	47	1
2527	32	83122	120	0
2747	30	70106	105	0
1324	35	60578	79	0
2702	20	39992	65	1
1383	28	79892	70	0
1179	28	49810	55	0
2099	39	71570	39	0
4308	34	100708	67	0
918	26	33032	21	0
1831	39	82875	127	0
3373	39	139077	152	0
1713	33	71595	113	0
1438	28	72260	99	0
496	4	5950	7	0
2253	39	115762	141	0
744	18	32551	21	0
1161	14	31701	35	0
2352	29	80670	109	0
2144	44	143558	133	0
4691	21	117105	123	1
1112	16	23789	26	1
2694	28	120733	230	0
1973	35	105195	166	0
1769	28	73107	68	0
3148	38	132068	147	0
2474	23	149193	179	0
2084	36	46821	61	0
1954	32	87011	101	0
1226	29	95260	108	0
1389	25	55183	90	0
1496	27	106671	114	0
2269	36	73511	103	0
1833	28	92945	142	0
1268	23	78664	79	0
1943	40	70054	88	0
893	23	22618	25	0
1762	40	74011	83	0
1403	28	83737	113	0
1425	34	69094	118	0
1857	33	93133	110	0
1840	28	95536	129	0
1502	34	225920	51	0
1441	30	62133	93	0
1420	33	61370	76	0
1416	22	43836	49	0
2970	38	106117	118	0
1317	26	38692	38	0
1644	35	84651	141	0
870	8	56622	58	0
1654	24	15986	27	0
1054	29	95364	91	0
937	20	26706	48	1
3004	29	89691	63	0
2008	45	67267	56	0
2547	37	126846	144	0
1885	33	41140	73	0
1626	33	102860	168	0
1468	25	51715	64	0
2445	32	55801	97	0
1964	29	111813	117	0
1381	28	120293	100	0
1369	28	138599	149	0
1659	31	161647	187	0
2888	52	115929	127	0
1290	21	24266	37	1
2845	24	162901	245	0
1982	41	109825	87	0
1904	33	129838	177	0
1391	32	37510	49	0
602	19	43750	49	0
1743	20	40652	73	0
1559	31	87771	177	0
2014	31	85872	94	0
2143	32	89275	117	0
2146	18	44418	60	1
874	23	192565	55	0
1590	17	35232	39	1
1590	20	40909	64	1
1210	12	13294	26	1
2072	17	32387	64	1
1281	30	140867	58	0
1401	31	120662	95	0
834	10	21233	25	1
1105	13	44332	26	1
1272	22	61056	76	1
1944	42	101338	129	0
391	1	1168	11	0
761	9	13497	2	1
1605	32	65567	101	0
530	11	25162	28	0
1988	25	32334	36	1
1386	36	40735	89	0
2395	31	91413	193	0
387	0	855	4	0
1742	24	97068	84	0
620	13	44339	23	1
449	8	14116	39	0
800	13	10288	14	1
1684	19	65622	78	1
1050	18	16563	14	1
2699	33	76643	101	0
1606	40	110681	82	0
1502	22	29011	24	1
1204	38	92696	36	0
1138	24	94785	75	0
568	8	8773	16	0
1459	35	83209	55	0
2158	43	93815	131	0
1111	43	86687	131	0
1421	14	34553	39	1
2833	41	105547	144	0
1955	38	103487	139	0
2922	45	213688	211	0
1002	31	71220	78	0
1060	13	23517	50	1
956	28	56926	39	0
2186	31	91721	90	0
3604	40	115168	166	0
1035	30	111194	12	0
1417	16	51009	57	1
3261	37	135777	133	0
1587	30	51513	69	0
1424	35	74163	119	0
1701	32	51633	119	0
1249	27	75345	65	0
946	20	33416	61	1
1926	18	83305	49	1
3352	31	98952	101	0
1641	31	102372	196	0
2035	21	37238	15	0
2312	39	103772	136	0
1369	41	123969	89	0
1577	13	27142	40	1
2201	32	135400	123	0
961	18	21399	21	1
1900	39	130115	163	0
1254	14	24874	29	1
1335	7	34988	35	1
1597	17	45549	13	1
207	0	6023	5	0
1645	30	64466	96	0
2429	37	54990	151	0
151	0	1644	6	0
474	5	6179	13	0
141	1	3926	3	0
1639	16	32755	56	1
872	32	34777	23	0
1318	24	73224	57	0
1018	17	27114	14	1
1383	11	20760	43	1
1314	24	37636	20	1
1335	22	65461	72	1
1403	12	30080	87	1
910	19	24094	21	1
616	13	69008	56	1
1407	17	54968	59	1
771	15	46090	82	1
766	16	27507	43	1
473	24	10672	25	1
1376	15	34029	38	1
1232	17	46300	25	1
1521	18	24760	38	1
572	20	18779	12	1
1059	16	21280	29	1
1544	16	40662	47	1
1230	18	28987	45	1
1206	22	22827	40	1
1205	8	18513	30	1
1255	17	30594	41	1
613	18	24006	25	1
721	16	27913	23	1
1109	23	42744	14	1
740	22	12934	16	1
1126	13	22574	26	1
728	13	41385	21	1
689	16	18653	27	1
592	16	18472	9	1
995	20	30976	33	1
1613	22	63339	42	1
2048	17	25568	68	1
705	18	33747	32	1
301	17	4154	6	1
1803	12	19474	67	1
799	7	35130	33	1
861	17	39067	77	1
1186	14	13310	46	1
1451	23	65892	30	1
628	17	4143	0	1
1161	14	28579	36	1
1463	15	51776	46	1
742	17	21152	18	1
979	21	38084	48	1
675	18	27717	29	1
1241	18	32928	28	1
676	17	11342	34	1
1049	17	19499	33	1
620	16	16380	34	1
1081	15	36874	33	1
1688	21	48259	80	1
736	16	16734	32	1
617	14	28207	30	1
812	15	30143	41	1
1051	17	41369	41	1
1656	15	45833	51	1
705	15	29156	18	1
945	10	35944	34	1
554	6	36278	31	1
1597	22	45588	39	1
982	21	45097	54	1
222	1	3895	14	1
1212	18	28394	24	1
1143	17	18632	24	1
435	4	2325	8	1
532	10	25139	26	1
882	16	27975	19	1
608	16	14483	11	1
459	9	13127	14	1
578	16	5839	1	1
826	17	24069	39	1
509	7	3738	5	1
717	15	18625	37	1
637	14	36341	32	1
857	14	24548	38	1
830	18	21792	47	1
652	12	26263	47	1
707	16	23686	37	1
954	21	49303	51	1
1461	19	25659	45	1
672	16	28904	21	1
778	1	2781	1	1
1141	16	29236	42	1
680	10	19546	26	1
1090	19	22818	21	1
616	12	32689	4	1
285	2	5752	10	1
1145	14	22197	43	1
733	17	20055	34	1
888	19	25272	31	1
849	14	82206	19	1
1182	11	32073	34	1
528	4	5444	6	1
642	16	20154	11	1
947	20	36944	24	1
819	12	8019	16	1
757	15	30884	72	1
894	16	19540	21	1




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

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

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

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



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