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(0 + ,3289.5 + ,0.66 + ,0.814 + ,0.526 + ,1 + ,6 + ,25299.2 + ,0.384 + ,0.743 + ,0.587 + ,2 + ,1 + ,32642.4 + ,0.681 + ,0.813 + ,0.612 + ,0 + ,64 + ,17096.2 + ,0.952 + ,0.895 + ,0.779 + ,0 + ,4 + ,7670.5 + ,0.709 + ,0.875 + ,0.793 + ,0 + ,0 + ,492.9 + ,0.602 + ,0.825 + ,0.754 + ,1 + ,0 + ,105256 + ,0.253 + ,0.623 + ,0.277 + ,0 + ,4 + ,9949 + ,0.764 + ,0.884 + ,0.791 + ,0 + ,0 + ,190.2 + ,0.615 + ,0.828 + ,0.54 + ,0 + ,0 + ,4773.1 + ,0.203 + ,0.453 + ,0.342 + ,0 + ,0 + ,6658.5 + ,0.604 + ,0.612 + ,0.476 + ,0 + ,0 + ,1382.4 + ,0.497 + ,0.696 + ,0.607 + ,0 + ,0 + ,12180.8 + ,0.346 + ,0.525 + ,0.428 + ,2 + ,47 + ,27700.9 + ,0.875 + ,0.904 + ,0.796 + ,0 + ,0 + ,2934.8 + ,0.219 + ,0.455 + ,0.3 + ,1 + ,0 + ,13187.8 + ,0.677 + ,0.847 + ,0.592 + ,0 + ,1 + ,33203.3 + ,0.39 + ,0.762 + ,0.582 + ,1 + ,0 + ,3070.2 + ,0.548 + ,0.879 + ,0.587 + ,0 + ,93 + ,10570.3 + ,0.69 + ,0.859 + ,0.523 + ,2 + ,0 + ,766.7 + ,0.626 + ,0.892 + ,0.747 + ,0 + ,11 + ,5141 + ,0.774 + ,0.866 + ,0.79 + ,0 + ,0 + ,7194.7 + ,0.499 + ,0.751 + ,0.513 + ,0 + ,0 + ,10260.6 + ,0.486 + ,0.771 + ,0.557 + ,0 + ,0 + ,56843.3 + ,0.376 + ,0.663 + ,0.493 + ,1 + ,0 + ,5332.8 + ,0.386 + ,0.726 + ,0.513 + ,1 + ,6 + ,1567.6 + ,0.716 + ,0.78 + ,0.661 + ,1 + ,0 + ,728.4 + ,0.674 + ,0.718 + ,0.503 + ,1 + ,11 + ,4986.4 + ,0.74 + ,0.871 + ,0.776 + ,0 + ,66 + ,56708.3 + ,0.666 + ,0.895 + ,0.787 + ,0 + ,0 + ,929 + ,0.484 + ,0.652 + ,0.702 + ,1 + ,235 + ,79098.1 + ,0.721 + ,0.874 + ,0.796 + ,0 + ,1 + ,14793.4 + ,0.406 + ,0.581 + ,0.31 + ,1 + ,43 + ,57214.5 + ,0.688 + ,0.877 + ,0.781 + ,0 + ,10 + ,10160.5 + ,0.671 + ,0.9 + ,0.742 + ,0 + ,0 + ,8923.1 + ,0.296 + ,0.666 + ,0.499 + ,1 + ,0 + ,724.9 + ,0.541 + ,0.646 + ,0.335 + ,1 + ,0 + ,7124.9 + ,0.294 + ,0.554 + ,0.384 + ,2 + ,0 + ,4889.3 + ,0.405 + ,0.731 + ,0.457 + ,0 + ,86 + ,10376.3 + ,0.661 + ,0.778 + ,0.683 + ,0 + ,0 + ,254.8 + ,0.727 + ,0.917 + ,0.79 + ,0 + ,0 + ,873785.4 + ,0.318 + ,0.605 + ,0.359 + ,1 + ,15 + ,184345.9 + ,0.39 + ,0.664 + ,0.43 + ,1 + ,7 + ,3531.2 + ,0.76 + ,0.863 + ,0.729 + ,0 + ,3 + ,4499.9 + ,0.784 + ,0.891 + ,0.739 + ,0 + ,48 + ,56832.3 + ,0.636 + ,0.897 + ,0.781 + ,0 + ,7 + ,2364.9 + ,0.592 + ,0.8 + ,0.571 + ,0 + ,42 + ,122251.2 + ,0.761 + ,0.931 + ,0.798 + ,0 + ,0 + ,3415.6 + ,0.526 + ,0.795 + ,0.493 + ,1 + ,20 + ,23447.2 + ,0.408 + ,0.621 + ,0.375 + ,1 + ,82 + ,42980.4 + ,0.738 + ,0.816 + ,0.678 + ,0 + ,0 + ,2087.7 + ,0.514 + ,0.828 + ,0.848 + ,1 + ,5 + ,2663.9 + ,0.652 + ,0.772 + ,0.661 + ,1 + ,0 + ,1639.2 + ,0.431 + ,0.623 + ,0.388 + ,1 + ,0 + ,381.2 + ,0.656 + ,0.868 + ,0.86 + ,0 + ,0 + ,9380.9 + ,0.239 + ,0.428 + ,0.242 + ,2 + ,1 + ,18208.6 + ,0.534 + ,0.789 + ,0.595 + ,1 + ,0 + ,8672.9 + ,0.082 + ,0.382 + ,0.27 + ,0 + ,0 + ,367.5 + ,0.686 + ,0.872 + ,0.713 + ,0 + ,0 + ,1995.5 + ,0.194 + ,0.568 + ,0.4 + ,2 + ,2 + ,84306.6 + ,0.518 + ,0.802 + ,0.657 + ,1 + ,2 + ,2192.6 + ,0.58 + ,0.639 + ,0.426 + ,0 + ,8 + ,24781.1 + ,0.254 + ,0.696 + ,0.466 + ,1 + ,0 + ,13547.1 + ,0.116 + ,0.367 + ,0.189 + ,1 + ,4 + ,1414.8 + ,0.524 + ,0.644 + ,0.53 + ,0 + ,0 + ,19081.1 + ,0.257 + ,0.536 + ,0.287 + ,0 + ,29 + ,14891.7 + ,0.814 + ,0.899 + ,0.797 + ,0 + ,18 + ,3398 + ,0.873 + ,0.871 + ,0.745 + ,0 + ,0 + ,7788.2 + ,0.079 + ,0.338 + ,0.27 + ,1 + ,19 + ,4241.5 + ,0.82 + ,0.891 + ,0.823 + ,0 + ,0 + ,1868.1 + ,0.71 + ,0.798 + ,0.718 + ,1 + ,1 + ,111844.7 + ,0.241 + ,0.642 + ,0.411 + ,1 + ,0 + ,2415.9 + ,0.599 + ,0.825 + ,0.581 + ,1 + ,0 + ,4157.7 + ,0.222 + ,0.561 + ,0.4 + ,0 + ,0 + ,4243.9 + ,0.466 + ,0.757 + ,0.532 + ,1 + ,140 + ,1145195.2 + ,0.437 + ,0.78 + ,0.345 + ,2 + ,1 + ,61628.7 + ,0.578 + ,0.712 + ,0.452 + ,1 + ,0 + ,9925.5 + ,0.568 + ,0.856 + ,0.729 + ,0 + ,40 + ,23206.7 + ,0.705 + ,0.779 + ,0.624 + ,1 + ,0 + ,7109.5 + ,0.217 + ,0.202 + ,0.286 + ,2 + ,0 + ,16139.1 + ,0.57 + ,0.767 + ,0.762 + ,2 + ,0 + ,7241.6 + ,0.247 + ,0.524 + ,0.375 + ,1 + ,0 + ,3981.6 + ,0.182 + ,0.296 + ,0.258 + ,2 + ,4 + ,36793.9 + ,0.572 + ,0.655 + ,0.622 + ,1 + ,81 + ,38889.2 + ,0.619 + ,0.9 + ,0.756 + ,0 + ,0 + ,17337 + ,0.59 + ,0.781 + ,0.43 + ,1 + ,0 + ,107.4 + ,0.665 + ,0.777 + ,0.536 + ,0 + ,0 + ,26494.2 + ,0.163 + ,0.513 + ,0.315 + ,2 + ,0 + ,862.9 + ,0.451 + ,0.622 + ,0.517 + ,1 + ,23 + ,8558.8 + ,0.759 + ,0.909 + ,0.786 + ,0 + ,5 + ,6673.7 + ,0.762 + ,0.909 + ,0.836 + ,0 + ,0 + ,12324.1 + ,0.425 + ,0.806 + ,0.48 + ,2 + ,1 + ,57072.1 + ,0.417 + ,0.828 + ,0.526 + ,1 + ,0 + ,966.2 + ,0.179 + ,0.522 + ,0.34 + ,0 + ,0 + ,3665.5 + ,0.312 + ,0.521 + ,0.306 + ,2 + ,0 + ,1215.5 + ,0.609 + ,0.771 + ,0.659 + ,0 + ,0 + ,8215.1 + ,0.396 + ,0.767 + ,0.524 + ,1 + ,16 + ,54130.3 + ,0.41 + ,0.679 + ,0.622 + ,1 + ,0 + ,17699.7 + ,0.262 + ,0.431 + ,0.235 + ,2 + ,0 + ,1808.6 + ,0.462 + ,0.817 + ,0.871 + ,1 + ,290 + ,253339.1 + ,0.917 + ,0.871 + ,0.825 + ,0 + ,0 + ,3109.1 + ,0.64 + ,0.828 + ,0.609 + ,0 + ,0 + ,19685.2 + ,0.476 + ,0.805 + ,0.651 + ,1 + ,0 + ,7860.1 + ,0.406 + ,0.434 + ,0.346 + ,0 + ,0 + ,10469.2 + ,0.451 + ,0.64 + ,0.266 + ,1) + ,dim=c(6 + ,104) + ,dimnames=list(c('Totalpoints' + ,'POP' + ,'Education' + ,'Health' + ,'GNI/Cap' + ,'Democracy') + ,1:104)) > y <- array(NA,dim=c(6,104),dimnames=list(c('Totalpoints','POP','Education','Health','GNI/Cap','Democracy'),1:104)) > 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 = '1' > par4 <- 'no' > par3 <- '3' > par2 <- 'none' > par1 <- '1' > #'GNU S' R Code compiled by R2WASP v. 1.2.291 () > #Author: root > #To cite this work: Wessa P., 2012, Recursive Partitioning (Regression Trees) (v1.0.3) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_regression_trees.wasp/ > #Source of accompanying publication: > # > 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] "Totalpoints" > x[,par1] [1] 0 6 1 64 4 0 0 4 0 0 0 0 0 47 0 0 1 0 [19] 93 0 11 0 0 0 0 6 0 11 66 0 235 1 43 10 0 0 [37] 0 0 86 0 0 15 7 3 48 7 42 0 20 82 0 5 0 0 [55] 0 1 0 0 0 2 2 8 0 4 0 29 18 0 19 0 1 0 [73] 0 0 140 1 0 40 0 0 0 0 4 81 0 0 0 0 23 5 [91] 0 1 0 0 0 0 16 0 0 290 0 0 0 0 > 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 1 2 3 4 5 6 7 8 10 11 15 16 18 19 20 23 29 40 42 59 7 2 1 4 2 2 2 1 1 2 1 1 1 1 1 1 1 1 1 43 47 48 64 66 81 82 86 93 140 235 290 1 1 1 1 1 1 1 1 1 1 1 1 > colnames(x) [1] "Totalpoints" "POP" "Education" "Health" "GNI.Cap" [6] "Democracy" > colnames(x)[par1] [1] "Totalpoints" > x[,par1] [1] 0 6 1 64 4 0 0 4 0 0 0 0 0 47 0 0 1 0 [19] 93 0 11 0 0 0 0 6 0 11 66 0 235 1 43 10 0 0 [37] 0 0 86 0 0 15 7 3 48 7 42 0 20 82 0 5 0 0 [55] 0 1 0 0 0 2 2 8 0 4 0 29 18 0 19 0 1 0 [73] 0 0 140 1 0 40 0 0 0 0 4 81 0 0 0 0 23 5 [91] 0 1 0 0 0 0 16 0 0 290 0 0 0 0 > if (par2 == 'none') { + m <- ctree(as.formula(paste(colnames(x)[par1],' ~ .',sep='')),data = x) + } > > #Note: the /var/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/1b8on1356613114.tab") + } + } > m Conditional inference tree with 4 terminal nodes Response: Totalpoints Inputs: POP, Education, Health, GNI.Cap, Democracy Number of observations: 104 1) Education <= 0.686; criterion = 0.999, statistic = 13.57 2) POP <= 36793.9; criterion = 1, statistic = 24.527 3)* weights = 68 2) POP > 36793.9 4)* weights = 13 1) Education > 0.686 5) POP <= 9949; criterion = 0.999, statistic = 14.863 6)* weights = 13 5) POP > 9949 7)* weights = 10 > postscript(file="/var/wessaorg/rcomp/tmp/2w2h41356613114.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/wessaorg/rcomp/tmp/32mxd1356613114.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 2.294118 -2.2941176 2 6 2.294118 3.7058824 3 1 2.294118 -1.2941176 4 64 96.500000 -32.5000000 5 4 8.538462 -4.5384615 6 0 2.294118 -2.2941176 7 0 28.538462 -28.5384615 8 4 8.538462 -4.5384615 9 0 2.294118 -2.2941176 10 0 2.294118 -2.2941176 11 0 2.294118 -2.2941176 12 0 2.294118 -2.2941176 13 0 2.294118 -2.2941176 14 47 96.500000 -49.5000000 15 0 2.294118 -2.2941176 16 0 2.294118 -2.2941176 17 1 2.294118 -1.2941176 18 0 2.294118 -2.2941176 19 93 96.500000 -3.5000000 20 0 2.294118 -2.2941176 21 11 8.538462 2.4615385 22 0 2.294118 -2.2941176 23 0 2.294118 -2.2941176 24 0 28.538462 -28.5384615 25 0 2.294118 -2.2941176 26 6 8.538462 -2.5384615 27 0 2.294118 -2.2941176 28 11 8.538462 2.4615385 29 66 28.538462 37.4615385 30 0 2.294118 -2.2941176 31 235 96.500000 138.5000000 32 1 2.294118 -1.2941176 33 43 96.500000 -53.5000000 34 10 2.294118 7.7058824 35 0 2.294118 -2.2941176 36 0 2.294118 -2.2941176 37 0 2.294118 -2.2941176 38 0 2.294118 -2.2941176 39 86 2.294118 83.7058824 40 0 8.538462 -8.5384615 41 0 28.538462 -28.5384615 42 15 28.538462 -13.5384615 43 7 8.538462 -1.5384615 44 3 8.538462 -5.5384615 45 48 28.538462 19.4615385 46 7 2.294118 4.7058824 47 42 96.500000 -54.5000000 48 0 2.294118 -2.2941176 49 20 2.294118 17.7058824 50 82 96.500000 -14.5000000 51 0 2.294118 -2.2941176 52 5 2.294118 2.7058824 53 0 2.294118 -2.2941176 54 0 2.294118 -2.2941176 55 0 2.294118 -2.2941176 56 1 2.294118 -1.2941176 57 0 2.294118 -2.2941176 58 0 2.294118 -2.2941176 59 0 2.294118 -2.2941176 60 2 28.538462 -26.5384615 61 2 2.294118 -0.2941176 62 8 2.294118 5.7058824 63 0 2.294118 -2.2941176 64 4 2.294118 1.7058824 65 0 2.294118 -2.2941176 66 29 96.500000 -67.5000000 67 18 8.538462 9.4615385 68 0 2.294118 -2.2941176 69 19 8.538462 10.4615385 70 0 8.538462 -8.5384615 71 1 28.538462 -27.5384615 72 0 2.294118 -2.2941176 73 0 2.294118 -2.2941176 74 0 2.294118 -2.2941176 75 140 28.538462 111.4615385 76 1 28.538462 -27.5384615 77 0 2.294118 -2.2941176 78 40 96.500000 -56.5000000 79 0 2.294118 -2.2941176 80 0 2.294118 -2.2941176 81 0 2.294118 -2.2941176 82 0 2.294118 -2.2941176 83 4 2.294118 1.7058824 84 81 28.538462 52.4615385 85 0 2.294118 -2.2941176 86 0 2.294118 -2.2941176 87 0 2.294118 -2.2941176 88 0 2.294118 -2.2941176 89 23 8.538462 14.4615385 90 5 8.538462 -3.5384615 91 0 2.294118 -2.2941176 92 1 28.538462 -27.5384615 93 0 2.294118 -2.2941176 94 0 2.294118 -2.2941176 95 0 2.294118 -2.2941176 96 0 2.294118 -2.2941176 97 16 28.538462 -12.5384615 98 0 2.294118 -2.2941176 99 0 2.294118 -2.2941176 100 290 96.500000 193.5000000 101 0 2.294118 -2.2941176 102 0 2.294118 -2.2941176 103 0 2.294118 -2.2941176 104 0 2.294118 -2.2941176 > if (par2 != 'none') { + print(cbind(as.factor(x[,par1]),predict(m))) + myt <- table(as.factor(x[,par1]),predict(m)) + print(myt) + } > postscript(file="/var/wessaorg/rcomp/tmp/4ldty1356613114.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/wessaorg/rcomp/tmp/5oiqc1356613114.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/wessaorg/rcomp/tmp/6v3581356613114.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/wessaorg/rcomp/tmp/703pb1356613114.tab") + } > > try(system("convert tmp/2w2h41356613114.ps tmp/2w2h41356613114.png",intern=TRUE)) character(0) > try(system("convert tmp/32mxd1356613114.ps tmp/32mxd1356613114.png",intern=TRUE)) character(0) > try(system("convert tmp/4ldty1356613114.ps tmp/4ldty1356613114.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 4.271 0.421 4.694