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.504208603 + ,0.397232704 + ,0.457969746 + ,0.382767296 + ,0.509923035 + ,0.396037736 + ,0.606622221 + ,0.441761006 + ,0.626210885 + ,0.445220126 + ,0.626631316 + ,0.438490566 + ,0.676731276 + ,0.467484277 + ,0.613117455 + ,0.465786164 + ,0.486215861 + ,0.402075472 + ,0.452529881 + ,0.376163522 + ,0.467150592 + ,0.37591195 + ,0.494624486 + ,0.392955975 + ,0.444567428 + ,0.34490566 + ,0.478862605 + ,0.368553459 + ,0.544458459 + ,0.390880503 + ,0.628201498 + ,0.424842767 + ,0.672578445 + ,0.426855346 + ,0.652706633 + ,0.442327044 + ,0.645430599 + ,0.474842767 + ,0.576334011 + ,0.447610063 + ,0.618334234 + ,0.480754717 + ,0.639896351 + ,0.516037736 + ,0.72850438 + ,0.580628931 + ,0.694655375 + ,0.573522013 + ,0.689773225 + ,0.578867925 + ,0.712244845 + ,0.593584906 + ,0.760337031 + ,0.645974843 + ,0.837816503 + ,0.690503145 + ,0.90688735 + ,0.782201258 + ,0.976018259 + ,0.839056604 + ,0.962066806 + ,0.847484277 + ,0.837593417 + ,0.726855346 + ,0.767638807 + ,0.635534591 + ,0.580006349 + ,0.470943396 + ,0.387740568 + ,0.346163522 + ,0.331274078 + ,0.272327044 + ,0.345251272 + ,0.286792453 + ,0.380172806 + ,0.27672956 + ,0.399838692 + ,0.297421384 + ,0.425742404 + ,0.321698113 + ,0.524183377 + ,0.365597484 + ,0.597115327 + ,0.435220126 + ,0.541489699 + ,0.412893082 + ,0.615039426 + ,0.458679245 + ,0.547924872 + ,0.428427673 + ,0.574540743 + ,0.463522013 + ,0.603438956 + ,0.487169811 + ,0.577492342 + ,0.473584906 + ,0.614198564 + ,0.491886792 + ,0.584776957 + ,0.474842767 + ,0.62752366 + ,0.502327044 + ,0.676859979 + ,0.539371069 + ,0.645996894 + ,0.484402516 + ,0.596059959 + ,0.474654088 + ,0.585961029 + ,0.473522013 + ,0.607617528 + ,0.48754717 + ,0.598462423 + ,0.493333333 + ,0.638703699 + ,0.525157233 + ,0.64923164 + ,0.542704403) + ,dim=c(2 + ,59) + ,dimnames=list(c('benzine' + ,'olie') + ,1:59)) > y <- array(NA,dim=c(2,59),dimnames=list(c('benzine','olie'),1:59)) > 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 = '2' > #'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] "olie" > x[,par1] [1] 0.3972327 0.3827673 0.3960377 0.4417610 0.4452201 0.4384906 0.4674843 [8] 0.4657862 0.4020755 0.3761635 0.3759119 0.3929560 0.3449057 0.3685535 [15] 0.3908805 0.4248428 0.4268553 0.4423270 0.4748428 0.4476101 0.4807547 [22] 0.5160377 0.5806289 0.5735220 0.5788679 0.5935849 0.6459748 0.6905031 [29] 0.7822013 0.8390566 0.8474843 0.7268553 0.6355346 0.4709434 0.3461635 [36] 0.2723270 0.2867925 0.2767296 0.2974214 0.3216981 0.3655975 0.4352201 [43] 0.4128931 0.4586792 0.4284277 0.4635220 0.4871698 0.4735849 0.4918868 [50] 0.4748428 0.5023270 0.5393711 0.4844025 0.4746541 0.4735220 0.4875472 [57] 0.4933333 0.5251572 0.5427044 > 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.272327044 0.27672956 0.286792453 0.297421384 0.321698113 0.34490566 1 1 1 1 1 1 0.346163522 0.365597484 0.368553459 0.37591195 0.376163522 0.382767296 1 1 1 1 1 1 0.390880503 0.392955975 0.396037736 0.397232704 0.402075472 0.412893082 1 1 1 1 1 1 0.424842767 0.426855346 0.428427673 0.435220126 0.438490566 0.441761006 1 1 1 1 1 1 0.442327044 0.445220126 0.447610063 0.458679245 0.463522013 0.465786164 1 1 1 1 1 1 0.467484277 0.470943396 0.473522013 0.473584906 0.474654088 0.474842767 1 1 1 1 1 2 0.480754717 0.484402516 0.487169811 0.48754717 0.491886792 0.493333333 1 1 1 1 1 1 0.502327044 0.516037736 0.525157233 0.539371069 0.542704403 0.573522013 1 1 1 1 1 1 0.578867925 0.580628931 0.593584906 0.635534591 0.645974843 0.690503145 1 1 1 1 1 1 0.726855346 0.782201258 0.839056604 0.847484277 1 1 1 1 > colnames(x) [1] "benzine" "olie" > colnames(x)[par1] [1] "olie" > x[,par1] [1] 0.3972327 0.3827673 0.3960377 0.4417610 0.4452201 0.4384906 0.4674843 [8] 0.4657862 0.4020755 0.3761635 0.3759119 0.3929560 0.3449057 0.3685535 [15] 0.3908805 0.4248428 0.4268553 0.4423270 0.4748428 0.4476101 0.4807547 [22] 0.5160377 0.5806289 0.5735220 0.5788679 0.5935849 0.6459748 0.6905031 [29] 0.7822013 0.8390566 0.8474843 0.7268553 0.6355346 0.4709434 0.3461635 [36] 0.2723270 0.2867925 0.2767296 0.2974214 0.3216981 0.3655975 0.4352201 [43] 0.4128931 0.4586792 0.4284277 0.4635220 0.4871698 0.4735849 0.4918868 [50] 0.4748428 0.5023270 0.5393711 0.4844025 0.4746541 0.4735220 0.4875472 [57] 0.4933333 0.5251572 0.5427044 > 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/1o3df1292370625.tab") + } + } > m Conditional inference tree with 3 terminal nodes Response: olie Input: benzine Number of observations: 59 1) benzine <= 0.67686; criterion = 1, statistic = 53.629 2) benzine <= 0.5444585; criterion = 1, statistic = 38.747 3)* weights = 18 2) benzine > 0.5444585 4)* weights = 30 1) benzine > 0.67686 5)* weights = 11 > postscript(file="/var/www/html/rcomp/tmp/2o3df1292370625.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/3o3df1292370625.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.3972327 0.3559504 0.0412823196 2 0.3827673 0.3559504 0.0268169116 3 0.3960377 0.3559504 0.0400873516 4 0.4417610 0.4726436 -0.0308825999 5 0.4452201 0.4726436 -0.0274234799 6 0.4384906 0.4726436 -0.0341530399 7 0.4674843 0.4726436 -0.0051593289 8 0.4657862 0.4726436 -0.0068574419 9 0.4020755 0.3559504 0.0461250876 10 0.3761635 0.3559504 0.0202131376 11 0.3759119 0.3559504 0.0199615656 12 0.3929560 0.3559504 0.0370055906 13 0.3449057 0.3559504 -0.0110447244 14 0.3685535 0.3559504 0.0126030746 15 0.3908805 0.3559504 0.0349301186 16 0.4248428 0.4726436 -0.0478008389 17 0.4268553 0.4726436 -0.0457882599 18 0.4423270 0.4726436 -0.0303165619 19 0.4748428 0.4726436 0.0021991611 20 0.4476101 0.4726436 -0.0250335429 21 0.4807547 0.4726436 0.0081111111 22 0.5160377 0.4726436 0.0433941301 23 0.5806289 0.6812922 -0.1006632362 24 0.5735220 0.6812922 -0.1077701542 25 0.5788679 0.6812922 -0.1024242422 26 0.5935849 0.6812922 -0.0877072612 27 0.6459748 0.6812922 -0.0353173242 28 0.6905031 0.6812922 0.0092109778 29 0.7822013 0.6812922 0.1009090908 30 0.8390566 0.6812922 0.1577644368 31 0.8474843 0.6812922 0.1661921098 32 0.7268553 0.6812922 0.0455631788 33 0.6355346 0.6812922 -0.0457575762 34 0.4709434 0.4726436 -0.0017002099 35 0.3461635 0.3559504 -0.0097868624 36 0.2723270 0.3559504 -0.0836233404 37 0.2867925 0.3559504 -0.0691579314 38 0.2767296 0.3559504 -0.0792208244 39 0.2974214 0.3559504 -0.0585290004 40 0.3216981 0.3559504 -0.0342522714 41 0.3655975 0.3559504 0.0096470996 42 0.4352201 0.4726436 -0.0374234799 43 0.4128931 0.3559504 0.0569426976 44 0.4586792 0.4726436 -0.0139643609 45 0.4284277 0.4726436 -0.0442159329 46 0.4635220 0.4726436 -0.0091215929 47 0.4871698 0.4726436 0.0145262051 48 0.4735849 0.4726436 0.0009413001 49 0.4918868 0.4726436 0.0192431861 50 0.4748428 0.4726436 0.0021991611 51 0.5023270 0.4726436 0.0296834381 52 0.5393711 0.4726436 0.0667274631 53 0.4844025 0.4726436 0.0117589101 54 0.4746541 0.4726436 0.0020104821 55 0.4735220 0.4726436 0.0008784071 56 0.4875472 0.4726436 0.0149035641 57 0.4933333 0.4726436 0.0206897271 58 0.5251572 0.4726436 0.0525136271 59 0.5427044 0.4726436 0.0700607971 > 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/4yvu01292370625.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/5umaq1292370625.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/6nw9c1292370625.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/79wqz1292370625.tab") + } > > try(system("convert tmp/2o3df1292370625.ps tmp/2o3df1292370625.png",intern=TRUE)) character(0) > try(system("convert tmp/3o3df1292370625.ps tmp/3o3df1292370625.png",intern=TRUE)) character(0) > try(system("convert tmp/4yvu01292370625.ps tmp/4yvu01292370625.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.205 0.602 5.319