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(1.35,75.53,1.91,75.75,1.31,76.57,1.19,77.59,1.3,77.15,1.14,79.08,1.1,80.29,1.02,79.94,1.11,80.19,1.18,79.70,1.24,79.14,1.36,78.23,1.29,77.16,1.73,76.77,1.41,76.19,1.15,74.83,1.31,74.33,1.15,72.71,1.08,71.32,1.1,71.88,1.14,71.78,1.24,71.77,1.33,72.17,1.49,70.84,1.38,70.64,1.96,70.85,1.36,71.43,1.24,78.52,1.35,81.12,1.23,84.16,1.09,84.36,1.08,84.13,1.33,83.59,1.35,82.13,1.38,83.03,1.5,83.91,1.47,83.01,2.09,82.36,1.52,82.01,1.29,81.83,1.52,80.89,1.27,82.86,1.35,83.28,1.29,82.63,1.41,81.52,1.39,82.20,1.45,81.97,1.53,81.60,1.45,82.36,2.11,82.55,1.53,81.27,1.38,79.89,1.54,74.44,1.35,73.47,1.29,73.16,1.33,73.16,1.47,72.94,1.47,72.89,1.54,73.26,1.59,73.93,1.5,72.58,2,72.00,1.51,72.79,1.4,71.86,1.62,69.74,1.44,69.73,1.29,69.05,1.28,69.63,1.4,70.48,1.39,72.49,1.46,72.66,1.49,74.77),dim=c(2,72),dimnames=list(c('Tulp','olie'),1:72)) > y <- array(NA,dim=c(2,72),dimnames=list(c('Tulp','olie'),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 = '1' > #'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] "Tulp" > x[,par1] [1] 1.35 1.91 1.31 1.19 1.30 1.14 1.10 1.02 1.11 1.18 1.24 1.36 1.29 1.73 1.41 [16] 1.15 1.31 1.15 1.08 1.10 1.14 1.24 1.33 1.49 1.38 1.96 1.36 1.24 1.35 1.23 [31] 1.09 1.08 1.33 1.35 1.38 1.50 1.47 2.09 1.52 1.29 1.52 1.27 1.35 1.29 1.41 [46] 1.39 1.45 1.53 1.45 2.11 1.53 1.38 1.54 1.35 1.29 1.33 1.47 1.47 1.54 1.59 [61] 1.50 2.00 1.51 1.40 1.62 1.44 1.29 1.28 1.40 1.39 1.46 1.49 > 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]) 1.02 1.08 1.09 1.1 1.11 1.14 1.15 1.18 1.19 1.23 1.24 1.27 1.28 1.29 1.3 1.31 1 2 1 2 1 2 2 1 1 1 3 1 1 5 1 2 1.33 1.35 1.36 1.38 1.39 1.4 1.41 1.44 1.45 1.46 1.47 1.49 1.5 1.51 1.52 1.53 3 5 2 3 2 2 2 1 2 1 3 2 2 1 2 2 1.54 1.59 1.62 1.73 1.91 1.96 2 2.09 2.11 2 1 1 1 1 1 1 1 1 > colnames(x) [1] "Tulp" "olie" > colnames(x)[par1] [1] "Tulp" > x[,par1] [1] 1.35 1.91 1.31 1.19 1.30 1.14 1.10 1.02 1.11 1.18 1.24 1.36 1.29 1.73 1.41 [16] 1.15 1.31 1.15 1.08 1.10 1.14 1.24 1.33 1.49 1.38 1.96 1.36 1.24 1.35 1.23 [31] 1.09 1.08 1.33 1.35 1.38 1.50 1.47 2.09 1.52 1.29 1.52 1.27 1.35 1.29 1.41 [46] 1.39 1.45 1.53 1.45 2.11 1.53 1.38 1.54 1.35 1.29 1.33 1.47 1.47 1.54 1.59 [61] 1.50 2.00 1.51 1.40 1.62 1.44 1.29 1.28 1.40 1.39 1.46 1.49 > 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/1zxyq1293209704.tab") + } + } > m Conditional inference tree with 1 terminal nodes Response: Tulp Input: olie Number of observations: 72 1)* weights = 72 > postscript(file="/var/www/html/rcomp/tmp/2zxyq1293209704.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/3a7yb1293209704.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 1.35 1.392917 -0.042916667 2 1.91 1.392917 0.517083333 3 1.31 1.392917 -0.082916667 4 1.19 1.392917 -0.202916667 5 1.30 1.392917 -0.092916667 6 1.14 1.392917 -0.252916667 7 1.10 1.392917 -0.292916667 8 1.02 1.392917 -0.372916667 9 1.11 1.392917 -0.282916667 10 1.18 1.392917 -0.212916667 11 1.24 1.392917 -0.152916667 12 1.36 1.392917 -0.032916667 13 1.29 1.392917 -0.102916667 14 1.73 1.392917 0.337083333 15 1.41 1.392917 0.017083333 16 1.15 1.392917 -0.242916667 17 1.31 1.392917 -0.082916667 18 1.15 1.392917 -0.242916667 19 1.08 1.392917 -0.312916667 20 1.10 1.392917 -0.292916667 21 1.14 1.392917 -0.252916667 22 1.24 1.392917 -0.152916667 23 1.33 1.392917 -0.062916667 24 1.49 1.392917 0.097083333 25 1.38 1.392917 -0.012916667 26 1.96 1.392917 0.567083333 27 1.36 1.392917 -0.032916667 28 1.24 1.392917 -0.152916667 29 1.35 1.392917 -0.042916667 30 1.23 1.392917 -0.162916667 31 1.09 1.392917 -0.302916667 32 1.08 1.392917 -0.312916667 33 1.33 1.392917 -0.062916667 34 1.35 1.392917 -0.042916667 35 1.38 1.392917 -0.012916667 36 1.50 1.392917 0.107083333 37 1.47 1.392917 0.077083333 38 2.09 1.392917 0.697083333 39 1.52 1.392917 0.127083333 40 1.29 1.392917 -0.102916667 41 1.52 1.392917 0.127083333 42 1.27 1.392917 -0.122916667 43 1.35 1.392917 -0.042916667 44 1.29 1.392917 -0.102916667 45 1.41 1.392917 0.017083333 46 1.39 1.392917 -0.002916667 47 1.45 1.392917 0.057083333 48 1.53 1.392917 0.137083333 49 1.45 1.392917 0.057083333 50 2.11 1.392917 0.717083333 51 1.53 1.392917 0.137083333 52 1.38 1.392917 -0.012916667 53 1.54 1.392917 0.147083333 54 1.35 1.392917 -0.042916667 55 1.29 1.392917 -0.102916667 56 1.33 1.392917 -0.062916667 57 1.47 1.392917 0.077083333 58 1.47 1.392917 0.077083333 59 1.54 1.392917 0.147083333 60 1.59 1.392917 0.197083333 61 1.50 1.392917 0.107083333 62 2.00 1.392917 0.607083333 63 1.51 1.392917 0.117083333 64 1.40 1.392917 0.007083333 65 1.62 1.392917 0.227083333 66 1.44 1.392917 0.047083333 67 1.29 1.392917 -0.102916667 68 1.28 1.392917 -0.112916667 69 1.40 1.392917 0.007083333 70 1.39 1.392917 -0.002916667 71 1.46 1.392917 0.067083333 72 1.49 1.392917 0.097083333 > 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/rcomp/tmp/4kgfw1293209704.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/5oyv21293209704.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/6rzcq1293209704.tab") + } Warning message: In cor(result$Forecasts, result$Actuals) : the standard deviation is zero > 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/7dhae1293209704.tab") + } > > try(system("convert tmp/2zxyq1293209704.ps tmp/2zxyq1293209704.png",intern=TRUE)) character(0) > try(system("convert tmp/3a7yb1293209704.ps tmp/3a7yb1293209704.png",intern=TRUE)) character(0) > try(system("convert tmp/4kgfw1293209704.ps tmp/4kgfw1293209704.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.053 0.570 10.721