R version 2.9.0 (2009-04-17) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > x <- array(list(6000 + ,10800 + ,10100 + ,16100 + ,17700 + ,13900 + ,17700 + ,6000 + ,10900 + ,10000 + ,15800 + ,17700 + ,13500 + ,19800 + ,6000 + ,11000 + ,10000 + ,16900 + ,17700 + ,13900 + ,19400 + ,6000 + ,11000 + ,10000 + ,17800 + ,17700 + ,13700 + ,18500 + ,6000 + ,11100 + ,10600 + ,17600 + ,17400 + ,13800 + ,18400 + ,6000 + ,11000 + ,12200 + ,18300 + ,17800 + ,15100 + ,18200 + ,6000 + ,11000 + ,12400 + ,18000 + ,17800 + ,15100 + ,18300 + ,6000 + ,11100 + ,13400 + ,15700 + ,17800 + ,14500 + ,19100 + ,6100 + ,11100 + ,13000 + ,14500 + ,17800 + ,13000 + ,18500 + ,6100 + ,11100 + ,10500 + ,14000 + ,18100 + ,12900 + ,18100 + ,6100 + ,11100 + ,10000 + ,15500 + ,18400 + ,14400 + ,18300 + ,6100 + ,11100 + ,10000 + ,15800 + ,18000 + ,14600 + ,17900 + ,6100 + ,11200 + ,10100 + ,15800 + ,17800 + ,15000 + ,18000 + ,6100 + ,11100 + ,10200 + ,15900 + ,17600 + ,13900 + ,18200 + ,6200 + ,11100 + ,10600 + ,18000 + ,17400 + ,14800 + ,18800 + ,6200 + ,11200 + ,10900 + ,19900 + ,17200 + ,15200 + ,20100 + ,6200 + ,11200 + ,10900 + ,20600 + ,17300 + ,16800 + ,19700 + ,6300 + ,11100 + ,11500 + ,20600 + ,17700 + ,17400 + ,19200 + ,6300 + ,11200 + ,12500 + ,20800 + ,18100 + ,17200 + ,19800 + ,6300 + ,11100 + ,13700 + ,20000 + ,18300 + ,17400 + ,20200 + ,6300 + ,11100 + ,15100 + ,18500 + ,18700 + ,18300 + ,19000 + ,6300 + ,11000 + ,13500 + ,17700 + ,18900 + ,19900 + ,19400 + ,6300 + ,11000 + ,13200 + ,17000 + ,18200 + ,18500 + ,19600 + ,6400 + ,11000 + ,13000 + ,16600 + ,17900 + ,16800 + ,18400 + ,6300 + ,11100 + ,13900 + ,16700 + ,17900 + ,16200 + ,18700 + ,6300 + ,11000 + ,14000 + ,17300 + ,18200 + ,16200 + ,18400 + ,6300 + ,11000 + ,13900 + ,19100 + ,18200 + ,16400 + ,20700 + ,6300 + ,10900 + ,14200 + ,20200 + ,18100 + ,15900 + ,20800 + ,6300 + ,11000 + ,14400 + ,20700 + ,18100 + ,16300 + ,21400 + ,6300 + ,11000 + ,14400 + ,21500 + ,17800 + ,16800 + ,21500 + ,6400 + ,11100 + ,14500 + ,21000 + ,18000 + ,15900 + ,20500 + ,6400 + ,11300 + ,13900 + ,16800 + ,17900 + ,15400 + ,20500 + ,6400 + ,11300 + ,14800 + ,16800 + ,18300 + ,15100 + ,19500 + ,6500 + ,11300 + ,13200 + ,16500 + ,18200 + ,15000 + ,20200 + ,6500 + ,11300 + ,12900 + ,17200 + ,18000 + ,17100 + ,20200 + ,6500 + ,11400 + ,13100 + ,17300 + ,18200 + ,16000 + ,18800 + ,6500 + ,11400 + ,12700 + ,17600 + ,18400 + ,15500 + ,19600 + ,6500 + ,11400 + ,13800 + ,18400 + ,18200 + ,16300 + ,19300 + ,6500 + ,11500 + ,13800 + ,19900 + ,18100 + ,16400 + ,20300 + ,6500 + ,11500 + ,14500 + ,20500 + ,17900 + ,16800 + ,21000 + ,6500 + ,11500 + ,15000 + ,21200 + ,18700 + ,17200 + ,19500 + ,6500 + ,11500 + ,16300 + ,21300 + ,18900 + ,17600 + ,20700 + ,6600 + ,11500 + ,17300 + ,20800 + ,19200 + ,18400 + ,20900 + ,6600 + ,11500 + ,18400 + ,18800 + ,19000 + ,18900 + ,20100 + ,6600 + ,11400 + ,17500 + ,18100 + ,19100 + ,18600 + ,19200 + ,6500 + ,11400 + ,13400 + ,18100 + ,19500 + ,18100 + ,19900 + ,6500 + ,11400 + ,13600 + ,18800 + ,20400 + ,18300 + ,21100 + ,6500 + ,11300 + ,13300 + ,18700 + ,19900 + ,17200 + ,20000 + ,6500 + ,11200 + ,13700 + ,18700 + ,19400 + ,15900 + ,20900 + ,6500 + ,11300 + ,13900 + ,19000 + ,19300 + ,16600 + ,20400 + ,6500 + ,11300 + ,14000 + ,20100 + ,18900 + ,15900 + ,20900 + ,6500 + ,11300 + ,14000 + ,20500 + ,18700 + ,16000 + ,20900 + ,6600 + ,11200 + ,14300 + ,21600 + ,18900 + ,15600 + ,21300 + ,6700 + ,11300 + ,15200 + ,21800 + ,19000 + ,16000 + ,21300 + ,6600 + ,11200 + ,15400 + ,21500 + ,19300 + ,16200 + ,21700 + ,6700 + ,11200 + ,18500 + ,21200 + ,19400 + ,16000 + ,21300 + ,6600 + ,11100 + ,18300 + ,20400 + ,18800 + ,16000 + ,20000 + ,6600 + ,11100 + ,12900 + ,20400 + ,18900 + ,16800 + ,20500 + ,6600 + ,11100 + ,12000 + ,20600 + ,19200 + ,17700 + ,20800 + ,6600 + ,11100 + ,12000 + ,19300 + ,19100 + ,17500 + ,20700 + ,7100 + ,11400 + ,12100 + ,18600 + ,18900 + ,17600 + ,21200 + ,7400 + ,11500 + ,12100 + ,19400 + ,18900 + ,18900 + ,21300 + ,7500 + ,11500 + ,11900 + ,23500 + ,19800 + ,18800 + ,21600 + ,7500 + ,11600 + ,11800 + ,24600 + ,20200 + ,19000 + ,22500 + ,7500 + ,11500 + ,11700 + ,25900 + ,20200 + ,19100 + ,22600 + ,7500 + ,11600 + ,12200 + ,26600 + ,19900 + ,19100 + ,23900 + ,7000 + ,11300 + ,12500 + ,24100 + ,19700 + ,18400 + ,23600 + ,6900 + ,11300 + ,13000 + ,21800 + ,19600 + ,16900 + ,22600 + ,6900 + ,11200 + ,13300 + ,21300 + ,19500 + ,16100 + ,22600 + ,6800 + ,11200 + ,11800 + ,21100 + ,19800 + ,16700 + ,22700 + ,6800 + ,11100 + ,11800 + ,21200 + ,20000 + ,18400 + ,22900 + ,6800 + ,11100 + ,11900 + ,21600 + ,20000 + ,18400 + ,22100) + ,dim=c(7 + ,72) + ,dimnames=list(c('Mineraalwater' + ,'Vruchtesappen' + ,'Appelen' + ,'Sinaasappelen' + ,'Citroenen' + ,'Pompelmoezen' + ,'Bananen') + ,1:72)) > y <- array(NA,dim=c(7,72),dimnames=list(c('Mineraalwater','Vruchtesappen','Appelen','Sinaasappelen','Citroenen','Pompelmoezen','Bananen'),1:72)) > for (i in 1:dim(x)[1]) + { + for (j in 1:dim(x)[2]) + { + y[i,j] <- as.numeric(x[i,j]) + } + } > par4 = 'no' > par3 = '2' > par2 = 'quantiles' > par1 = '2' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Dr. Ian E. Holliday > #To cite this work: Ian E. Holliday, 2009, YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/ > #Source of accompanying publication: > #Technical description: > library(party) Loading required package: survival Loading required package: splines Loading required package: grid Loading required package: modeltools Loading required package: stats4 Loading required package: coin Loading required package: mvtnorm Loading required package: zoo Attaching package: 'zoo' The following object(s) are masked from package:base : as.Date.numeric Loading required package: sandwich Loading required package: strucchange Loading required package: vcd Loading required package: MASS Loading required package: colorspace > library(Hmisc) Attaching package: 'Hmisc' The following object(s) are masked from package:survival : untangle.specials The following object(s) are masked from package:base : format.pval, round.POSIXt, trunc.POSIXt, units > par1 <- as.numeric(par1) > par3 <- as.numeric(par3) > x <- data.frame(t(y)) > is.data.frame(x) [1] TRUE > x <- x[!is.na(x[,par1]),] > k <- length(x[1,]) > n <- length(x[,1]) > colnames(x)[par1] [1] "Vruchtesappen" > x[,par1] [1] 10800 10900 11000 11000 11100 11000 11000 11100 11100 11100 11100 11100 [13] 11200 11100 11100 11200 11200 11100 11200 11100 11100 11000 11000 11000 [25] 11100 11000 11000 10900 11000 11000 11100 11300 11300 11300 11300 11400 [37] 11400 11400 11500 11500 11500 11500 11500 11500 11400 11400 11400 11300 [49] 11200 11300 11300 11300 11200 11300 11200 11200 11100 11100 11100 11100 [61] 11400 11500 11500 11600 11500 11600 11300 11300 11200 11200 11100 11100 > 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]) [10800,11300) [11300,11600] 43 29 > colnames(x) [1] "Mineraalwater" "Vruchtesappen" "Appelen" "Sinaasappelen" [5] "Citroenen" "Pompelmoezen" "Bananen" > colnames(x)[par1] [1] "Vruchtesappen" > x[,par1] [1] [10800,11300) [10800,11300) [10800,11300) [10800,11300) [10800,11300) [6] [10800,11300) [10800,11300) [10800,11300) [10800,11300) [10800,11300) [11] [10800,11300) [10800,11300) [10800,11300) [10800,11300) [10800,11300) [16] [10800,11300) [10800,11300) [10800,11300) [10800,11300) [10800,11300) [21] [10800,11300) [10800,11300) [10800,11300) [10800,11300) [10800,11300) [26] [10800,11300) [10800,11300) [10800,11300) [10800,11300) [10800,11300) [31] [10800,11300) [11300,11600] [11300,11600] [11300,11600] [11300,11600] [36] [11300,11600] [11300,11600] [11300,11600] [11300,11600] [11300,11600] [41] [11300,11600] [11300,11600] [11300,11600] [11300,11600] [11300,11600] [46] [11300,11600] [11300,11600] [11300,11600] [10800,11300) [11300,11600] [51] [11300,11600] [11300,11600] [10800,11300) [11300,11600] [10800,11300) [56] [10800,11300) [10800,11300) [10800,11300) [10800,11300) [10800,11300) [61] [11300,11600] [11300,11600] [11300,11600] [11300,11600] [11300,11600] [66] [11300,11600] [11300,11600] [11300,11600] [10800,11300) [10800,11300) [71] [10800,11300) [10800,11300) Levels: [10800,11300) [11300,11600] > if (par2 == 'none') { + m <- ctree(as.formula(paste(colnames(x)[par1],' ~ .',sep='')),data = x) + } > > #Note: the /var/www/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/rcomp/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="/var/www/html/rcomp/tmp/1y1vg1292361335.tab") + } + } > m Conditional inference tree with 2 terminal nodes Response: as.factor(Vruchtesappen) Inputs: Mineraalwater, Appelen, Sinaasappelen, Citroenen, Pompelmoezen, Bananen Number of observations: 72 1) Mineraalwater <= 6300; criterion = 1, statistic = 21.1 2)* weights = 29 1) Mineraalwater > 6300 3)* weights = 43 > postscript(file="/var/www/html/rcomp/tmp/2y1vg1292361335.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(m) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/3rbv11292361335.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(x[,par1] ~ as.factor(where(m)),main='Response by Terminal Node',xlab='Terminal Node',ylab='Response') > dev.off() null device 1 > 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) + } [,1] [,2] [1,] 1 1 [2,] 1 1 [3,] 1 1 [4,] 1 1 [5,] 1 1 [6,] 1 1 [7,] 1 1 [8,] 1 1 [9,] 1 1 [10,] 1 1 [11,] 1 1 [12,] 1 1 [13,] 1 1 [14,] 1 1 [15,] 1 1 [16,] 1 1 [17,] 1 1 [18,] 1 1 [19,] 1 1 [20,] 1 1 [21,] 1 1 [22,] 1 1 [23,] 1 1 [24,] 1 2 [25,] 1 1 [26,] 1 1 [27,] 1 1 [28,] 1 1 [29,] 1 1 [30,] 1 1 [31,] 1 2 [32,] 2 2 [33,] 2 2 [34,] 2 2 [35,] 2 2 [36,] 2 2 [37,] 2 2 [38,] 2 2 [39,] 2 2 [40,] 2 2 [41,] 2 2 [42,] 2 2 [43,] 2 2 [44,] 2 2 [45,] 2 2 [46,] 2 2 [47,] 2 2 [48,] 2 2 [49,] 1 2 [50,] 2 2 [51,] 2 2 [52,] 2 2 [53,] 1 2 [54,] 2 2 [55,] 1 2 [56,] 1 2 [57,] 1 2 [58,] 1 2 [59,] 1 2 [60,] 1 2 [61,] 2 2 [62,] 2 2 [63,] 2 2 [64,] 2 2 [65,] 2 2 [66,] 2 2 [67,] 2 2 [68,] 2 2 [69,] 1 2 [70,] 1 2 [71,] 1 2 [72,] 1 2 [10800,11300) [11300,11600] [10800,11300) 29 14 [11300,11600] 0 29 > postscript(file="/var/www/html/rcomp/tmp/412c31292361335.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > 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() null device 1 > 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="/var/www/html/rcomp/tmp/5fuv41292361336.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="/var/www/html/rcomp/tmp/6ivta1292361336.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="/var/www/html/rcomp/tmp/7t4bd1292361336.tab") + } > > try(system("convert tmp/2y1vg1292361335.ps tmp/2y1vg1292361335.png",intern=TRUE)) character(0) > try(system("convert tmp/3rbv11292361335.ps tmp/3rbv11292361335.png",intern=TRUE)) character(0) > try(system("convert tmp/412c31292361335.ps tmp/412c31292361335.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.020 0.474 4.728