R version 2.8.0 (2008-10-20) Copyright (C) 2008 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. Natural language support but running in an English locale 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 = '' > par2 = 'none' > 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 10900 11000 11100 11200 11300 11400 11500 11600 1 2 11 19 10 11 7 9 2 > colnames(x) [1] "Mineraalwater" "Vruchtesappen" "Appelen" "Sinaasappelen" [5] "Citroenen" "Pompelmoezen" "Bananen" > 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 == 'none') { + m <- ctree(as.formula(paste(colnames(x)[par1],' ~ .',sep='')),data = x) + } > > #Note: the /var/www/html/freestat/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/freestat/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/freestat/rcomp/tmp/1psi31292356521.tab") + } + } > m Conditional inference tree with 2 terminal nodes Response: Vruchtesappen Inputs: Mineraalwater, Appelen, Sinaasappelen, Citroenen, Pompelmoezen, Bananen Number of observations: 72 1) Mineraalwater <= 6400; criterion = 1, statistic = 32.693 2)* weights = 33 1) Mineraalwater > 6400 3)* weights = 39 > postscript(file="/var/www/html/freestat/rcomp/tmp/2psi31292356521.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/freestat/rcomp/tmp/3psi31292356521.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) + } Actuals Forecasts Residuals 1 10800 11069.70 -269.69697 2 10900 11069.70 -169.69697 3 11000 11069.70 -69.69697 4 11000 11069.70 -69.69697 5 11100 11069.70 30.30303 6 11000 11069.70 -69.69697 7 11000 11069.70 -69.69697 8 11100 11069.70 30.30303 9 11100 11069.70 30.30303 10 11100 11069.70 30.30303 11 11100 11069.70 30.30303 12 11100 11069.70 30.30303 13 11200 11069.70 130.30303 14 11100 11069.70 30.30303 15 11100 11069.70 30.30303 16 11200 11069.70 130.30303 17 11200 11069.70 130.30303 18 11100 11069.70 30.30303 19 11200 11069.70 130.30303 20 11100 11069.70 30.30303 21 11100 11069.70 30.30303 22 11000 11069.70 -69.69697 23 11000 11069.70 -69.69697 24 11000 11069.70 -69.69697 25 11100 11069.70 30.30303 26 11000 11069.70 -69.69697 27 11000 11069.70 -69.69697 28 10900 11069.70 -169.69697 29 11000 11069.70 -69.69697 30 11000 11069.70 -69.69697 31 11100 11069.70 30.30303 32 11300 11069.70 230.30303 33 11300 11069.70 230.30303 34 11300 11333.33 -33.33333 35 11300 11333.33 -33.33333 36 11400 11333.33 66.66667 37 11400 11333.33 66.66667 38 11400 11333.33 66.66667 39 11500 11333.33 166.66667 40 11500 11333.33 166.66667 41 11500 11333.33 166.66667 42 11500 11333.33 166.66667 43 11500 11333.33 166.66667 44 11500 11333.33 166.66667 45 11400 11333.33 66.66667 46 11400 11333.33 66.66667 47 11400 11333.33 66.66667 48 11300 11333.33 -33.33333 49 11200 11333.33 -133.33333 50 11300 11333.33 -33.33333 51 11300 11333.33 -33.33333 52 11300 11333.33 -33.33333 53 11200 11333.33 -133.33333 54 11300 11333.33 -33.33333 55 11200 11333.33 -133.33333 56 11200 11333.33 -133.33333 57 11100 11333.33 -233.33333 58 11100 11333.33 -233.33333 59 11100 11333.33 -233.33333 60 11100 11333.33 -233.33333 61 11400 11333.33 66.66667 62 11500 11333.33 166.66667 63 11500 11333.33 166.66667 64 11600 11333.33 266.66667 65 11500 11333.33 166.66667 66 11600 11333.33 266.66667 67 11300 11333.33 -33.33333 68 11300 11333.33 -33.33333 69 11200 11333.33 -133.33333 70 11200 11333.33 -133.33333 71 11100 11333.33 -233.33333 72 11100 11333.33 -233.33333 > if (par2 != 'none') { + print(cbind(as.factor(x[,par1]),predict(m))) + myt <- table(as.factor(x[,par1]),predict(m)) + print(myt) + } > postscript(file="/var/www/html/freestat/rcomp/tmp/40jh61292356521.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/freestat/rcomp/tmp/53jxb1292356521.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/freestat/rcomp/tmp/66keh1292356521.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/freestat/rcomp/tmp/7s3vn1292356521.tab") + } > > try(system("convert tmp/2psi31292356521.ps tmp/2psi31292356521.png",intern=TRUE)) character(0) > try(system("convert tmp/3psi31292356521.ps tmp/3psi31292356521.png",intern=TRUE)) character(0) > try(system("convert tmp/40jh61292356521.ps tmp/40jh61292356521.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.655 0.718 3.823