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(1606 + ,6 + ,3.74 + ,16 + ,1391 + ,1634 + ,6.81 + ,4.17 + ,29 + ,1621 + ,2013 + ,9.75 + ,4.84 + ,22 + ,1837 + ,1654 + ,6.96 + ,4.21 + ,30 + ,2132 + ,1003 + ,3.94 + ,3.93 + ,20 + ,1489 + ,1029 + ,5 + ,4.9 + ,39 + ,1817 + ,1052 + ,4.9 + ,4.7 + ,18 + ,1586 + ,1653 + ,5.7 + ,3.5 + ,9.6 + ,1565 + ,1918 + ,6.5 + ,3.4 + ,10.2 + ,1787 + ,1926 + ,7.1 + ,3.7 + ,20.2 + ,1804 + ,1862 + ,7.5 + ,4 + ,50 + ,1763 + ,1816 + ,7.8 + ,4.3 + ,120 + ,1675 + ,1712 + ,7 + ,4.1 + ,19.8 + ,1575 + ,1646 + ,7.4 + ,4.5 + ,18 + ,1524 + ,1555 + ,8.55 + ,5.5 + ,3 + ,1686 + ,1402 + ,7.43 + ,5.3 + ,11 + ,1800 + ,1047 + ,4.7 + ,4.5 + ,15 + ,1442 + ,891 + ,4.7 + ,5.3 + ,27 + ,1345 + ,940 + ,5.3 + ,5.6 + ,28 + ,1500 + ,1372 + ,6.2 + ,4.5 + ,14 + ,1556 + ,2012 + ,7.4 + ,3.7 + ,5.6 + ,2012 + ,1879 + ,7.5 + ,4 + ,6.5 + ,1618 + ,1667 + ,7.32 + ,4.4 + ,8.5 + ,1487 + ,1856 + ,8.15 + ,4.4 + ,87.9 + ,1607 + ,1771 + ,7.24 + ,4.1 + ,5.8 + ,1308 + ,1721 + ,7.4 + ,4.3 + ,25.2 + ,1429 + ,1773 + ,9.4 + ,5.3 + ,7.5 + ,1596 + ,1507 + ,8.9 + ,5.9 + ,13.7 + ,1884 + ,1033 + ,4.5 + ,4.4 + ,34 + ,1262 + ,1011 + ,4.9 + ,4.9 + ,17 + ,1283 + ,1111 + ,5.6 + ,5.1 + ,9 + ,1346 + ,1736 + ,6.4 + ,3.7 + ,9.2 + ,1505 + ,1865 + ,6 + ,3.2 + ,5 + ,1151 + ,2078 + ,6.9 + ,3.3 + ,24 + ,1600 + ,1947 + ,6.7 + ,3.5 + ,40 + ,1420 + ,1428 + ,5.4 + ,3.8 + ,86.5 + ,1073 + ,1500 + ,5.6 + ,3.8 + ,0.54 + ,1076 + ,1950 + ,6.9 + ,3.5 + ,14 + ,1510 + ,1591 + ,6.9 + ,4.3 + ,4.8 + ,1345 + ,1613 + ,7 + ,4.3 + ,28 + ,1631 + ,1077 + ,4 + ,3.7 + ,16 + ,1135 + ,880 + ,3.7 + ,4.2 + ,5.8 + ,1009 + ,1128 + ,4.9 + ,4.3 + ,16 + ,1155 + ,1320 + ,5 + ,3.8 + ,9.1 + ,1184 + ,1692 + ,5.7 + ,3.4 + ,6 + ,1285 + ,1575 + ,6.1 + ,3.9 + ,17 + ,1257 + ,1478 + ,5.3 + ,3.6 + ,26 + ,1131 + ,1500 + ,5.5 + ,3.6 + ,99.6 + ,1274 + ,1368 + ,5.7 + ,4.2 + ,41 + ,235 + ,1563 + ,5.21 + ,3.3 + ,72 + ,1299 + ,1424 + ,5.4 + ,3.8 + ,23 + ,1460 + ,1274 + ,4.5 + ,3.5 + ,42 + ,1455 + ,1047 + ,3.7 + ,3.7 + ,40 + ,1113 + ,1049 + ,4.1 + ,3.9 + ,18 + ,1263 + ,1069 + ,4.8 + ,4.5 + ,45 + ,1401 + ,981 + ,4.1 + ,4.2 + ,18 + ,1135 + ,1540 + ,5 + ,3.2 + ,2 + ,1137 + ,1559 + ,5.2 + ,3.3 + ,10 + ,1140 + ,1459 + ,5.5 + ,3.8 + ,13.6 + ,1014 + ,1559 + ,5.9 + ,3.8 + ,160 + ,1220) + ,dim=c(5 + ,60) + ,dimnames=list(c('aanvoer' + ,'aanvoerwaarde' + ,'prijzen' + ,'interventie' + ,'visserijen') + ,1:60)) > y <- array(NA,dim=c(5,60),dimnames=list(c('aanvoer','aanvoerwaarde','prijzen','interventie','visserijen'),1:60)) > for (i in 1:dim(x)[1]) + { + for (j in 1:dim(x)[2]) + { + y[i,j] <- as.numeric(x[i,j]) + } + } > par4 = 'yes' > par3 = '2' > par2 = 'quantiles' > 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 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] "aanvoer" > x[,par1] [1] 1606 1634 2013 1654 1003 1029 1052 1653 1918 1926 1862 1816 1712 1646 1555 [16] 1402 1047 891 940 1372 2012 1879 1667 1856 1771 1721 1773 1507 1033 1011 [31] 1111 1736 1865 2078 1947 1428 1500 1950 1591 1613 1077 880 1128 1320 1692 [46] 1575 1478 1500 1368 1563 1424 1274 1047 1049 1069 981 1540 1559 1459 1559 > 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]) [ 880,1559) [1559,2078] 30 30 > colnames(x) [1] "aanvoer" "aanvoerwaarde" "prijzen" "interventie" [5] "visserijen" > colnames(x)[par1] [1] "aanvoer" > x[,par1] [1] [1559,2078] [1559,2078] [1559,2078] [1559,2078] [ 880,1559) [ 880,1559) [7] [ 880,1559) [1559,2078] [1559,2078] [1559,2078] [1559,2078] [1559,2078] [13] [1559,2078] [1559,2078] [ 880,1559) [ 880,1559) [ 880,1559) [ 880,1559) [19] [ 880,1559) [ 880,1559) [1559,2078] [1559,2078] [1559,2078] [1559,2078] [25] [1559,2078] [1559,2078] [1559,2078] [ 880,1559) [ 880,1559) [ 880,1559) [31] [ 880,1559) [1559,2078] [1559,2078] [1559,2078] [1559,2078] [ 880,1559) [37] [ 880,1559) [1559,2078] [1559,2078] [1559,2078] [ 880,1559) [ 880,1559) [43] [ 880,1559) [ 880,1559) [1559,2078] [1559,2078] [ 880,1559) [ 880,1559) [49] [ 880,1559) [1559,2078] [ 880,1559) [ 880,1559) [ 880,1559) [ 880,1559) [55] [ 880,1559) [ 880,1559) [ 880,1559) [1559,2078] [ 880,1559) [1559,2078] Levels: [ 880,1559) [1559,2078] > 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/1qa2g1292497673.tab") + } + } m.ct.i.pred m.ct.i.actu 1 2 1 238 25 2 34 231 [1] 0.904943 [1] 0.8716981 [1] 0.8882576 m.ct.x.pred m.ct.x.actu 1 2 1 32 5 2 3 32 [1] 0.8648649 [1] 0.9142857 [1] 0.8888889 > m Conditional inference tree with 4 terminal nodes Response: as.factor(aanvoer) Inputs: aanvoerwaarde, prijzen, interventie, visserijen Number of observations: 60 1) aanvoerwaarde <= 5.6; criterion = 1, statistic = 21.698 2)* weights = 27 1) aanvoerwaarde > 5.6 3) prijzen <= 4.4; criterion = 0.998, statistic = 12.073 4) visserijen <= 1345; criterion = 0.999, statistic = 13.797 5)* weights = 7 4) visserijen > 1345 6)* weights = 19 3) prijzen > 4.4 7)* weights = 7 > postscript(file="/var/www/rcomp/tmp/2qa2g1292497673.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/3qa2g1292497673.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) + } > if (par2 != 'none') { + print(cbind(as.factor(x[,par1]),predict(m))) + myt <- table(as.factor(x[,par1]),predict(m)) + print(myt) + } [,1] [,2] [1,] 2 2 [2,] 2 2 [3,] 2 1 [4,] 2 2 [5,] 1 1 [6,] 1 1 [7,] 1 1 [8,] 2 2 [9,] 2 2 [10,] 2 2 [11,] 2 2 [12,] 2 2 [13,] 2 2 [14,] 2 1 [15,] 1 1 [16,] 1 1 [17,] 1 1 [18,] 1 1 [19,] 1 1 [20,] 1 1 [21,] 2 2 [22,] 2 2 [23,] 2 2 [24,] 2 2 [25,] 2 2 [26,] 2 2 [27,] 2 1 [28,] 1 1 [29,] 1 1 [30,] 1 1 [31,] 1 1 [32,] 2 2 [33,] 2 2 [34,] 2 2 [35,] 2 2 [36,] 1 1 [37,] 1 1 [38,] 2 2 [39,] 2 2 [40,] 2 2 [41,] 1 1 [42,] 1 1 [43,] 1 1 [44,] 1 1 [45,] 2 2 [46,] 2 2 [47,] 1 1 [48,] 1 1 [49,] 1 2 [50,] 2 1 [51,] 1 1 [52,] 1 1 [53,] 1 1 [54,] 1 1 [55,] 1 1 [56,] 1 1 [57,] 1 1 [58,] 2 1 [59,] 1 1 [60,] 2 2 [ 880,1559) [1559,2078] [ 880,1559) 29 1 [1559,2078] 5 25 > postscript(file="/var/www/rcomp/tmp/40jj11292497673.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/5ebzs1292497673.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/6pkzd1292497673.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/rcomp/tmp/7s3fj1292497673.tab") + } > try(system("convert tmp/2qa2g1292497673.ps tmp/2qa2g1292497673.png",intern=TRUE)) character(0) > try(system("convert tmp/3qa2g1292497673.ps tmp/3qa2g1292497673.png",intern=TRUE)) character(0) > try(system("convert tmp/40jj11292497673.ps tmp/40jj11292497673.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.450 0.670 3.143