R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-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(391 + ,12 + ,1 + ,0 + ,1168 + ,5841 + ,12 + ,893 + ,22 + ,23 + ,67 + ,22618 + ,23824 + ,10 + ,872 + ,37 + ,32 + ,48 + ,34777 + ,14336 + ,14 + ,1138 + ,25 + ,24 + ,66 + ,94785 + ,61023 + ,9 + ,874 + ,28 + ,23 + ,69 + ,192565 + ,153197 + ,8 + ,1281 + ,83 + ,30 + ,93 + ,140867 + ,68370 + ,16 + ,865 + ,33 + ,14 + ,37 + ,31081 + ,58391 + ,11 + ,1179 + ,39 + ,28 + ,80 + ,49810 + ,46341 + ,19 + ,1654 + ,24 + ,24 + ,69 + ,15986 + ,25157 + ,10 + ,1222 + ,47 + ,25 + ,81 + ,30727 + ,53907 + ,12 + ,1204 + ,32 + ,38 + ,120 + ,92696 + ,20112 + ,11 + ,1054 + ,67 + ,29 + ,107 + ,95364 + ,76669 + ,8 + ,1587 + ,47 + ,30 + ,83 + ,51513 + ,53782 + ,14 + ,1386 + ,71 + ,36 + ,98 + ,40735 + ,55515 + ,13 + ,1373 + ,44 + ,30 + ,90 + ,57793 + ,59238 + ,14 + ,1468 + ,33 + ,25 + ,73 + ,51715 + ,71299 + ,14 + ,1496 + ,67 + ,27 + ,104 + ,106671 + ,71180 + ,17 + ,1425 + ,105 + ,34 + ,120 + ,69094 + ,73815 + ,16 + ,2547 + ,135 + ,37 + ,129 + ,126846 + ,72413 + ,12 + ,1583 + ,43 + ,26 + ,93 + ,116174 + ,95757 + ,14 + ,1324 + ,56 + ,35 + ,95 + ,60578 + ,69107 + ,15 + ,1420 + ,62 + ,33 + ,98 + ,61370 + ,67808 + ,15 + ,1605 + ,106 + ,32 + ,83 + ,65567 + ,84396 + ,14 + ,1383 + ,59 + ,28 + ,90 + ,79892 + ,108016 + ,14 + ,1381 + ,68 + ,28 + ,107 + ,120293 + ,93913 + ,16 + ,1559 + ,81 + ,31 + ,63 + ,87771 + ,115338 + ,16 + ,1439 + ,69 + ,25 + ,60 + ,57635 + ,85584 + ,13 + ,1403 + ,69 + ,28 + ,72 + ,83737 + ,82981 + ,14 + ,1579 + ,44 + ,42 + ,122 + ,74007 + ,82036 + ,15 + ,1111 + ,46 + ,43 + ,139 + ,86687 + ,112494 + ,12 + ,2035 + ,41 + ,21 + ,78 + ,37238 + ,10901 + ,13 + ,2147 + ,73 + ,31 + ,114 + ,82753 + ,98579 + ,15 + ,2515 + ,123 + ,34 + ,120 + ,69112 + ,85646 + ,17 + ,1530 + ,60 + ,38 + ,93 + ,83123 + ,86146 + ,8 + ,1645 + ,47 + ,30 + ,73 + ,64466 + ,89455 + ,16 + ,1626 + ,124 + ,33 + ,118 + ,102860 + ,96971 + ,10 + ,1831 + ,91 + ,39 + ,138 + ,82875 + ,93176 + ,17 + ,1833 + ,114 + ,28 + ,91 + ,92945 + ,85298 + ,14 + ,1644 + ,100 + ,35 + ,71 + ,84651 + ,106175 + ,16 + ,1641 + ,111 + ,31 + ,98 + ,102372 + ,112283 + ,7 + ,1226 + ,41 + ,29 + ,99 + ,95260 + ,129847 + ,15 + ,1424 + ,92 + ,35 + ,116 + ,74163 + ,127748 + ,9 + ,1677 + ,94 + ,35 + ,133 + ,117478 + ,146761 + ,9 + ,1418 + ,79 + ,30 + ,94 + ,112285 + ,146283 + ,13 + ,1929 + ,101 + ,36 + ,117 + ,99052 + ,121527 + ,16 + ,2352 + ,76 + ,29 + ,96 + ,80670 + ,102996 + ,15 + ,2445 + ,98 + ,32 + ,119 + ,55801 + ,77494 + ,12 + ,1638 + ,105 + ,33 + ,120 + ,72654 + ,131741 + ,16 + ,1900 + ,131 + ,39 + ,132 + ,130115 + ,139296 + ,15 + ,1982 + ,93 + ,41 + ,139 + ,109825 + ,102255 + ,8 + ,2352 + ,81 + ,31 + ,94 + ,85323 + ,130767 + ,16 + ,2186 + ,63 + ,31 + ,119 + ,91721 + ,78876 + ,13 + ,1706 + ,102 + ,30 + ,115 + ,133824 + ,136368 + ,15 + ,1659 + ,131 + ,31 + ,90 + ,161647 + ,181248 + ,15 + ,1904 + ,118 + ,33 + ,106 + ,129838 + ,168237 + ,17 + ,2152 + ,77 + ,31 + ,71 + ,101481 + ,112642 + ,13 + ,1764 + ,78 + ,38 + ,123 + ,66198 + ,143983 + ,16 + ,1964 + ,58 + ,29 + ,104 + ,111813 + ,120336 + ,16 + ,1840 + ,88 + ,28 + ,105 + ,95536 + ,132190 + ,18 + ,1944 + ,133 + ,42 + ,110 + ,101338 + ,103950 + ,19 + ,2144 + ,101 + ,44 + ,164 + ,143558 + ,160604 + ,14 + ,2699 + ,98 + ,33 + ,115 + ,76643 + ,142775 + ,15 + ,2312 + ,120 + ,39 + ,117 + ,103772 + ,120691 + ,15 + ,1973 + ,123 + ,35 + ,124 + ,105195 + ,174141 + ,17 + ,2888 + ,110 + ,52 + ,197 + ,115929 + ,146123 + ,11 + ,2527 + ,96 + ,32 + ,120 + ,83122 + ,136815 + ,16 + ,2429 + ,109 + ,37 + ,86 + ,54990 + ,147866 + ,16 + ,2158 + ,100 + ,43 + ,152 + ,93815 + ,132432 + ,16 + ,3004 + ,57 + ,29 + ,107 + ,89691 + ,105805 + ,14 + ,2452 + ,107 + ,33 + ,124 + ,101494 + ,171975 + ,17 + ,2395 + ,116 + ,31 + ,82 + ,91413 + ,209056 + ,16 + ,3261 + ,113 + ,37 + ,133 + ,135777 + ,122037 + ,17 + ,4041 + ,158 + ,47 + ,168 + ,97668 + ,151511 + ,13 + ,2662 + ,84 + ,36 + ,126 + ,79215 + ,159676 + ,12 + ,2833 + ,129 + ,41 + ,144 + ,105547 + ,170875 + ,14 + ,2253 + ,79 + ,39 + ,140 + ,115762 + ,155135 + ,10 + ,2242 + ,80 + ,30 + ,108 + ,67654 + ,127766 + ,20 + ,2970 + ,118 + ,38 + ,111 + ,106117 + ,131722 + ,16 + ,2922 + ,136 + ,45 + ,160 + ,213688 + ,214921 + ,14 + ,4308 + ,76 + ,34 + ,110 + ,100708 + ,79336 + ,16 + ,3201 + ,121 + ,25 + ,91 + ,119182 + ,195663 + ,14) + ,dim=c(7 + ,81) + ,dimnames=list(c('Pageviews' + ,'Blogged_comp' + ,'Reviewed_comp' + ,'Fb_messages' + ,'Comp_Size' + ,'Comp_Time' + ,'PLC') + ,1:81)) > y <- array(NA,dim=c(7,81),dimnames=list(c('Pageviews','Blogged_comp','Reviewed_comp','Fb_messages','Comp_Size','Comp_Time','PLC'),1:81)) > 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 = '3' > par2 = 'none' > par1 = '7' > 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 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] "PLC" > x[,par1] [1] 12 10 14 9 8 16 11 19 10 12 11 8 14 13 14 14 17 16 12 14 15 15 14 14 16 [26] 16 13 14 15 12 13 15 17 8 16 10 17 14 16 7 15 9 9 13 16 15 12 16 15 8 [51] 16 13 15 15 17 13 16 16 18 19 14 15 15 17 11 16 16 16 14 17 16 17 13 12 14 [76] 10 20 16 14 16 14 > 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]) 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 4 3 4 3 6 7 14 11 17 7 1 2 1 > colnames(x) [1] "Pageviews" "Blogged_comp" "Reviewed_comp" "Fb_messages" [5] "Comp_Size" "Comp_Time" "PLC" > colnames(x)[par1] [1] "PLC" > x[,par1] [1] 12 10 14 9 8 16 11 19 10 12 11 8 14 13 14 14 17 16 12 14 15 15 14 14 16 [26] 16 13 14 15 12 13 15 17 8 16 10 17 14 16 7 15 9 9 13 16 15 12 16 15 8 [51] 16 13 15 15 17 13 16 16 18 19 14 15 15 17 11 16 16 16 14 17 16 17 13 12 14 [76] 10 20 16 14 16 14 > if (par2 == 'none') { + m <- ctree(as.formula(paste(colnames(x)[par1],' ~ .',sep='')),data = x) + } > > #Note: the /var/www/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/rcomp/tmp/1rynl1323456294.tab") + } + } > m Conditional inference tree with 1 terminal nodes Response: PLC Inputs: Pageviews, Blogged_comp, Reviewed_comp, Fb_messages, Comp_Size, Comp_Time Number of observations: 81 1)* weights = 81 > postscript(file="/var/www/rcomp/tmp/25hkq1323456294.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/rcomp/tmp/3dfk61323456294.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 12 13.95062 -1.95061728 2 10 13.95062 -3.95061728 3 14 13.95062 0.04938272 4 9 13.95062 -4.95061728 5 8 13.95062 -5.95061728 6 16 13.95062 2.04938272 7 11 13.95062 -2.95061728 8 19 13.95062 5.04938272 9 10 13.95062 -3.95061728 10 12 13.95062 -1.95061728 11 11 13.95062 -2.95061728 12 8 13.95062 -5.95061728 13 14 13.95062 0.04938272 14 13 13.95062 -0.95061728 15 14 13.95062 0.04938272 16 14 13.95062 0.04938272 17 17 13.95062 3.04938272 18 16 13.95062 2.04938272 19 12 13.95062 -1.95061728 20 14 13.95062 0.04938272 21 15 13.95062 1.04938272 22 15 13.95062 1.04938272 23 14 13.95062 0.04938272 24 14 13.95062 0.04938272 25 16 13.95062 2.04938272 26 16 13.95062 2.04938272 27 13 13.95062 -0.95061728 28 14 13.95062 0.04938272 29 15 13.95062 1.04938272 30 12 13.95062 -1.95061728 31 13 13.95062 -0.95061728 32 15 13.95062 1.04938272 33 17 13.95062 3.04938272 34 8 13.95062 -5.95061728 35 16 13.95062 2.04938272 36 10 13.95062 -3.95061728 37 17 13.95062 3.04938272 38 14 13.95062 0.04938272 39 16 13.95062 2.04938272 40 7 13.95062 -6.95061728 41 15 13.95062 1.04938272 42 9 13.95062 -4.95061728 43 9 13.95062 -4.95061728 44 13 13.95062 -0.95061728 45 16 13.95062 2.04938272 46 15 13.95062 1.04938272 47 12 13.95062 -1.95061728 48 16 13.95062 2.04938272 49 15 13.95062 1.04938272 50 8 13.95062 -5.95061728 51 16 13.95062 2.04938272 52 13 13.95062 -0.95061728 53 15 13.95062 1.04938272 54 15 13.95062 1.04938272 55 17 13.95062 3.04938272 56 13 13.95062 -0.95061728 57 16 13.95062 2.04938272 58 16 13.95062 2.04938272 59 18 13.95062 4.04938272 60 19 13.95062 5.04938272 61 14 13.95062 0.04938272 62 15 13.95062 1.04938272 63 15 13.95062 1.04938272 64 17 13.95062 3.04938272 65 11 13.95062 -2.95061728 66 16 13.95062 2.04938272 67 16 13.95062 2.04938272 68 16 13.95062 2.04938272 69 14 13.95062 0.04938272 70 17 13.95062 3.04938272 71 16 13.95062 2.04938272 72 17 13.95062 3.04938272 73 13 13.95062 -0.95061728 74 12 13.95062 -1.95061728 75 14 13.95062 0.04938272 76 10 13.95062 -3.95061728 77 20 13.95062 6.04938272 78 16 13.95062 2.04938272 79 14 13.95062 0.04938272 80 16 13.95062 2.04938272 81 14 13.95062 0.04938272 > 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/rcomp/tmp/4os4m1323456294.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/rcomp/tmp/5hdnj1323456294.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/rcomp/tmp/6ftxr1323456294.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/rcomp/tmp/7lfx81323456294.tab") + } > > try(system("convert tmp/25hkq1323456294.ps tmp/25hkq1323456294.png",intern=TRUE)) character(0) > try(system("convert tmp/3dfk61323456294.ps tmp/3dfk61323456294.png",intern=TRUE)) character(0) > try(system("convert tmp/4os4m1323456294.ps tmp/4os4m1323456294.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.030 0.120 2.146