R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-pc-linux-gnu (32-bit) 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(6.8 + ,225 + ,0.442 + ,0.672 + ,9.2 + ,6.3 + ,180 + ,0.435 + ,0.797 + ,11.7 + ,6.4 + ,190 + ,0.456 + ,0.761 + ,15.8 + ,6.2 + ,180 + ,0.416 + ,0.651 + ,8.6 + ,6.9 + ,205 + ,0.449 + ,0.9 + ,23.2 + ,6.4 + ,225 + ,0.431 + ,0.78 + ,27.4 + ,6.3 + ,185 + ,0.487 + ,0.771 + ,9.3 + ,6.8 + ,235 + ,0.469 + ,0.75 + ,16 + ,6.9 + ,235 + ,0.435 + ,0.818 + ,4.7 + ,6.7 + ,210 + ,0.48 + ,0.825 + ,12.5 + ,6.9 + ,245 + ,0.516 + ,0.632 + ,20.1 + ,6.9 + ,245 + ,0.493 + ,0.757 + ,9.1 + ,6.3 + ,185 + ,0.374 + ,0.709 + ,8.1 + ,6.1 + ,185 + ,0.424 + ,0.782 + ,8.6 + ,6.2 + ,180 + ,0.441 + ,0.775 + ,20.3 + ,6.8 + ,220 + ,0.503 + ,0.88 + ,25 + ,6.5 + ,194 + ,0.503 + ,0.833 + ,19.2 + ,7.6 + ,225 + ,0.425 + ,0.571 + ,3.3 + ,6.3 + ,210 + ,0.371 + ,0.816 + ,11.2 + ,7.1 + ,240 + ,0.504 + ,0.714 + ,10.5 + ,6.8 + ,225 + ,0.4 + ,0.765 + ,10.1 + ,7.3 + ,263 + ,0.482 + ,0.655 + ,7.2 + ,6.4 + ,210 + ,0.475 + ,0.244 + ,13.6 + ,6.8 + ,235 + ,0.428 + ,0.728 + ,9 + ,7.2 + ,230 + ,0.559 + ,0.721 + ,24.6 + ,6.4 + ,190 + ,0.441 + ,0.757 + ,12.6 + ,6.6 + ,220 + ,0.492 + ,0.747 + ,5.6 + ,6.8 + ,210 + ,0.402 + ,0.739 + ,8.7 + ,6.1 + ,180 + ,0.415 + ,0.713 + ,7.7 + ,6.5 + ,235 + ,0.492 + ,0.742 + ,24.1 + ,6.4 + ,185 + ,0.484 + ,0.861 + ,11.7 + ,6 + ,175 + ,0.387 + ,0.721 + ,7.7 + ,6 + ,192 + ,0.436 + ,0.785 + ,9.6 + ,7.3 + ,263 + ,0.482 + ,0.655 + ,7.2 + ,6.1 + ,180 + ,0.34 + ,0.821 + ,12.3 + ,6.7 + ,240 + ,0.516 + ,0.728 + ,8.9 + ,6.4 + ,210 + ,0.475 + ,0.846 + ,13.6 + ,5.8 + ,160 + ,0.412 + ,0.813 + ,11.2 + ,6.9 + ,230 + ,0.411 + ,0.595 + ,2.8 + ,7 + ,245 + ,0.407 + ,0.573 + ,3.2 + ,7.3 + ,228 + ,0.445 + ,0.726 + ,9.4 + ,5.9 + ,155 + ,0.291 + ,0.707 + ,11.9 + ,6.2 + ,200 + ,0.449 + ,0.804 + ,15.4 + ,6.8 + ,235 + ,0.546 + ,0.784 + ,7.4 + ,7 + ,235 + ,0.48 + ,0.744 + ,18.9 + ,5.9 + ,105 + ,0.359 + ,0.839 + ,7.9 + ,6.1 + ,180 + ,0.528 + ,0.79 + ,12.2 + ,5.7 + ,185 + ,0.352 + ,0.701 + ,11 + ,7.1 + ,245 + ,0.414 + ,0.778 + ,2.8 + ,5.8 + ,180 + ,0.425 + ,0.872 + ,11.8 + ,7.4 + ,240 + ,0.599 + ,0.713 + ,17.1 + ,6.8 + ,225 + ,0.482 + ,0.701 + ,11.6 + ,6.8 + ,215 + ,0.457 + ,0.734 + ,5.8 + ,7 + ,230 + ,0.435 + ,0.764 + ,8.3) + ,dim=c(5 + ,54) + ,dimnames=list(c('X1' + ,'X2' + ,'X3' + ,'X4' + ,'X5') + ,1:54)) > y <- array(NA,dim=c(5,54),dimnames=list(c('X1','X2','X3','X4','X5'),1:54)) > 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 = '4' > par2 = 'none' > par1 = '5' > 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, 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) Hmisc library by Frank E Harrell Jr Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview') to see overall documentation. NOTE:Hmisc no longer redefines [.factor to drop unused levels when subsetting. To get the old behavior of Hmisc type dropUnusedLevels(). 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] "X5" > x[,par1] [1] 9.2 11.7 15.8 8.6 23.2 27.4 9.3 16.0 4.7 12.5 20.1 9.1 8.1 8.6 20.3 [16] 25.0 19.2 3.3 11.2 10.5 10.1 7.2 13.6 9.0 24.6 12.6 5.6 8.7 7.7 24.1 [31] 11.7 7.7 9.6 7.2 12.3 8.9 13.6 11.2 2.8 3.2 9.4 11.9 15.4 7.4 18.9 [46] 7.9 12.2 11.0 2.8 11.8 17.1 11.6 5.8 8.3 > 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]) 2.8 3.2 3.3 4.7 5.6 5.8 7.2 7.4 7.7 7.9 8.1 8.3 8.6 8.7 8.9 9 2 1 1 1 1 1 2 1 2 1 1 1 2 1 1 1 9.1 9.2 9.3 9.4 9.6 10.1 10.5 11 11.2 11.6 11.7 11.8 11.9 12.2 12.3 12.5 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 12.6 13.6 15.4 15.8 16 17.1 18.9 19.2 20.1 20.3 23.2 24.1 24.6 25 27.4 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 > colnames(x) [1] "X1" "X2" "X3" "X4" "X5" > colnames(x)[par1] [1] "X5" > x[,par1] [1] 9.2 11.7 15.8 8.6 23.2 27.4 9.3 16.0 4.7 12.5 20.1 9.1 8.1 8.6 20.3 [16] 25.0 19.2 3.3 11.2 10.5 10.1 7.2 13.6 9.0 24.6 12.6 5.6 8.7 7.7 24.1 [31] 11.7 7.7 9.6 7.2 12.3 8.9 13.6 11.2 2.8 3.2 9.4 11.9 15.4 7.4 18.9 [46] 7.9 12.2 11.0 2.8 11.8 17.1 11.6 5.8 8.3 > if (par2 == 'none') { + m <- ctree(as.formula(paste(colnames(x)[par1],' ~ .',sep='')),data = x) + } > > #Note: the /var/fisher/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/fisher/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/fisher/rcomp/tmp/1s0xe1355258301.tab") + } + } > m Conditional inference tree with 1 terminal nodes Response: X5 Inputs: X1, X2, X3, X4 Number of observations: 54 1)* weights = 54 > postscript(file="/var/fisher/rcomp/tmp/27h2l1355258301.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/fisher/rcomp/tmp/3cna31355258301.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 9.2 11.79074 -2.590740741 2 11.7 11.79074 -0.090740741 3 15.8 11.79074 4.009259259 4 8.6 11.79074 -3.190740741 5 23.2 11.79074 11.409259259 6 27.4 11.79074 15.609259259 7 9.3 11.79074 -2.490740741 8 16.0 11.79074 4.209259259 9 4.7 11.79074 -7.090740741 10 12.5 11.79074 0.709259259 11 20.1 11.79074 8.309259259 12 9.1 11.79074 -2.690740741 13 8.1 11.79074 -3.690740741 14 8.6 11.79074 -3.190740741 15 20.3 11.79074 8.509259259 16 25.0 11.79074 13.209259259 17 19.2 11.79074 7.409259259 18 3.3 11.79074 -8.490740741 19 11.2 11.79074 -0.590740741 20 10.5 11.79074 -1.290740741 21 10.1 11.79074 -1.690740741 22 7.2 11.79074 -4.590740741 23 13.6 11.79074 1.809259259 24 9.0 11.79074 -2.790740741 25 24.6 11.79074 12.809259259 26 12.6 11.79074 0.809259259 27 5.6 11.79074 -6.190740741 28 8.7 11.79074 -3.090740741 29 7.7 11.79074 -4.090740741 30 24.1 11.79074 12.309259259 31 11.7 11.79074 -0.090740741 32 7.7 11.79074 -4.090740741 33 9.6 11.79074 -2.190740741 34 7.2 11.79074 -4.590740741 35 12.3 11.79074 0.509259259 36 8.9 11.79074 -2.890740741 37 13.6 11.79074 1.809259259 38 11.2 11.79074 -0.590740741 39 2.8 11.79074 -8.990740741 40 3.2 11.79074 -8.590740741 41 9.4 11.79074 -2.390740741 42 11.9 11.79074 0.109259259 43 15.4 11.79074 3.609259259 44 7.4 11.79074 -4.390740741 45 18.9 11.79074 7.109259259 46 7.9 11.79074 -3.890740741 47 12.2 11.79074 0.409259259 48 11.0 11.79074 -0.790740741 49 2.8 11.79074 -8.990740741 50 11.8 11.79074 0.009259259 51 17.1 11.79074 5.309259259 52 11.6 11.79074 -0.190740741 53 5.8 11.79074 -5.990740741 54 8.3 11.79074 -3.490740741 > if (par2 != 'none') { + print(cbind(as.factor(x[,par1]),predict(m))) + myt <- table(as.factor(x[,par1]),predict(m)) + print(myt) + } > postscript(file="/var/fisher/rcomp/tmp/4fxb71355258301.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/fisher/rcomp/tmp/5glec1355258301.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/fisher/rcomp/tmp/6ddfx1355258301.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/fisher/rcomp/tmp/7ge3t1355258301.tab") + } > > try(system("convert tmp/27h2l1355258301.ps tmp/27h2l1355258301.png",intern=TRUE)) character(0) > try(system("convert tmp/3cna31355258301.ps tmp/3cna31355258301.png",intern=TRUE)) character(0) > try(system("convert tmp/4fxb71355258301.ps tmp/4fxb71355258301.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.487 0.564 4.039