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(0.301029996 + ,3 + ,1.62324929 + ,0.255272505 + ,4 + ,2.79518459 + ,-0.15490196 + ,4 + ,2.255272505 + ,0.591064607 + ,1 + ,1.544068044 + ,0 + ,4 + ,2.593286067 + ,0.556302501 + ,1 + ,1.799340549 + ,0.146128036 + ,1 + ,2.361727836 + ,0.176091259 + ,4 + ,2.049218023 + ,-0.15490196 + ,5 + ,2.44870632 + ,0.322219295 + ,1 + ,1.62324929 + ,0.612783857 + ,2 + ,1.62324929 + ,0.079181246 + ,2 + ,2.079181246 + ,-0.301029996 + ,5 + ,2.170261715 + ,0.531478917 + ,2 + ,1.204119983 + ,0.176091259 + ,1 + ,2.491361694 + ,0.531478917 + ,3 + ,1.447158031 + ,-0.096910013 + ,4 + ,1.832508913 + ,-0.096910013 + ,5 + ,2.526339277 + ,0.301029996 + ,1 + ,1.698970004 + ,0.278753601 + ,1 + ,2.426511261 + ,0.113943352 + ,3 + ,1.278753601 + ,0.748188027 + ,1 + ,1.079181246 + ,0.491361694 + ,1 + ,2.079181246 + ,0.255272505 + ,2 + ,2.146128036 + ,-0.045757491 + ,4 + ,2.230448921 + ,0.255272505 + ,4 + ,1.230448921 + ,0.278753601 + ,5 + ,2.06069784 + ,-0.045757491 + ,3 + ,1.491361694 + ,0.414973348 + ,1 + ,1.322219295 + ,0.380211242 + ,2 + ,1.716003344 + ,0.079181246 + ,2 + ,2.214843848 + ,-0.045757491 + ,3 + ,2.352182518 + ,-0.301029996 + ,5 + ,2.352182518 + ,-0.22184875 + ,2 + ,2.178976947 + ,0.361727836 + ,3 + ,1.77815125 + ,-0.301029996 + ,2 + ,2.301029996 + ,0.414973348 + ,4 + ,1.662757832 + ,-0.22184875 + ,1 + ,2.322219295 + ,0.819543936 + ,2 + ,1.146128036) + ,dim=c(3 + ,39) + ,dimnames=list(c('logPS' + ,'ODI' + ,'logtg ') + ,1:39)) > y <- array(NA,dim=c(3,39),dimnames=list(c('logPS','ODI','logtg '),1:39)) > 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] "logPS" > x[,par1] [1] 0.30103000 0.25527250 -0.15490196 0.59106461 0.00000000 0.55630250 [7] 0.14612804 0.17609126 -0.15490196 0.32221930 0.61278386 0.07918125 [13] -0.30103000 0.53147892 0.17609126 0.53147892 -0.09691001 -0.09691001 [19] 0.30103000 0.27875360 0.11394335 0.74818803 0.49136169 0.25527250 [25] -0.04575749 0.25527250 0.27875360 -0.04575749 0.41497335 0.38021124 [31] 0.07918125 -0.04575749 -0.30103000 -0.22184875 0.36172784 -0.30103000 [37] 0.41497335 -0.22184875 0.81954394 > 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]) -0.301029996 -0.22184875 -0.15490196 -0.096910013 -0.045757491 0 3 2 2 2 3 1 0.079181246 0.113943352 0.146128036 0.176091259 0.255272505 0.278753601 2 1 1 2 3 2 0.301029996 0.322219295 0.361727836 0.380211242 0.414973348 0.491361694 2 1 1 1 2 1 0.531478917 0.556302501 0.591064607 0.612783857 0.748188027 0.819543936 2 1 1 1 1 1 > colnames(x) [1] "logPS" "ODI" "logtg." > colnames(x)[par1] [1] "logPS" > x[,par1] [1] 0.30103000 0.25527250 -0.15490196 0.59106461 0.00000000 0.55630250 [7] 0.14612804 0.17609126 -0.15490196 0.32221930 0.61278386 0.07918125 [13] -0.30103000 0.53147892 0.17609126 0.53147892 -0.09691001 -0.09691001 [19] 0.30103000 0.27875360 0.11394335 0.74818803 0.49136169 0.25527250 [25] -0.04575749 0.25527250 0.27875360 -0.04575749 0.41497335 0.38021124 [31] 0.07918125 -0.04575749 -0.30103000 -0.22184875 0.36172784 -0.30103000 [37] 0.41497335 -0.22184875 0.81954394 > 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/1gvcf1292850640.tab") + } + } > m Conditional inference tree with 3 terminal nodes Response: logPS Inputs: ODI, logtg. Number of observations: 39 1) logtg. <= 2.146128; criterion = 1, statistic = 15.835 2) ODI <= 2; criterion = 0.96, statistic = 5.38 3)* weights = 13 2) ODI > 2 4)* weights = 10 1) logtg. > 2.146128 5)* weights = 16 > postscript(file="/var/www/html/rcomp/tmp/2gvcf1292850640.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/3gvcf1292850640.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 0.30103000 0.22906033 0.07196967 2 0.25527250 -0.05684936 0.31212186 3 -0.15490196 -0.05684936 -0.09805260 4 0.59106461 0.46950855 0.12155606 5 0.00000000 -0.05684936 0.05684936 6 0.55630250 0.46950855 0.08679395 7 0.14612804 -0.05684936 0.20297740 8 0.17609126 0.22906033 -0.05296907 9 -0.15490196 -0.05684936 -0.09805260 10 0.32221930 0.46950855 -0.14728926 11 0.61278386 0.46950855 0.14327531 12 0.07918125 0.46950855 -0.39032731 13 -0.30103000 -0.05684936 -0.24418064 14 0.53147892 0.46950855 0.06197037 15 0.17609126 -0.05684936 0.23294062 16 0.53147892 0.22906033 0.30241859 17 -0.09691001 0.22906033 -0.32597034 18 -0.09691001 -0.05684936 -0.04006065 19 0.30103000 0.46950855 -0.16847856 20 0.27875360 -0.05684936 0.33560296 21 0.11394335 0.22906033 -0.11511698 22 0.74818803 0.46950855 0.27867948 23 0.49136169 0.46950855 0.02185314 24 0.25527250 0.46950855 -0.21423605 25 -0.04575749 -0.05684936 0.01109187 26 0.25527250 0.22906033 0.02621217 27 0.27875360 0.22906033 0.04969327 28 -0.04575749 0.22906033 -0.27481782 29 0.41497335 0.46950855 -0.05453520 30 0.38021124 0.46950855 -0.08929731 31 0.07918125 -0.05684936 0.13603061 32 -0.04575749 -0.05684936 0.01109187 33 -0.30103000 -0.05684936 -0.24418064 34 -0.22184875 -0.05684936 -0.16499939 35 0.36172784 0.22906033 0.13266751 36 -0.30103000 -0.05684936 -0.24418064 37 0.41497335 0.22906033 0.18591302 38 -0.22184875 -0.05684936 -0.16499939 39 0.81954394 0.46950855 0.35003538 > 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/494tj1292850640.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/55wr91292850640.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/6y58u1292850640.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/7tyrd1292850641.tab") + } > > try(system("convert tmp/2gvcf1292850640.ps tmp/2gvcf1292850640.png",intern=TRUE)) character(0) > try(system("convert tmp/3gvcf1292850640.ps tmp/3gvcf1292850640.png",intern=TRUE)) character(0) > try(system("convert tmp/494tj1292850640.ps tmp/494tj1292850640.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.027 0.627 4.523