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(3010 + ,2590 + ,11290 + ,4700 + ,44.51 + ,2910 + ,2080 + ,11620 + ,4960 + ,45.48 + ,3840 + ,2640 + ,10790 + ,4880 + ,53.1 + ,3580 + ,3000 + ,8380 + ,4090 + ,51.88 + ,3140 + ,2350 + ,9370 + ,3450 + ,48.65 + ,3550 + ,2220 + ,10090 + ,3020 + ,54.35 + ,3250 + ,2540 + ,11130 + ,3070 + ,57.52 + ,2820 + ,2700 + ,10530 + ,3720 + ,63.98 + ,2260 + ,2580 + ,10490 + ,3750 + ,62.91 + ,2060 + ,2420 + ,10570 + ,3910 + ,58.54 + ,2120 + ,2090 + ,11170 + ,4120 + ,55.24 + ,2210 + ,2000 + ,11610 + ,4780 + ,56.86 + ,2190 + ,1860 + ,10920 + ,3070 + ,62.99 + ,2180 + ,1980 + ,11570 + ,4100 + ,60.21 + ,2350 + ,2690 + ,12960 + ,3900 + ,62.06 + ,2440 + ,3040 + ,11190 + ,3020 + ,70.26 + ,2370 + ,2450 + ,11920 + ,3220 + ,69.78 + ,2440 + ,2650 + ,14930 + ,4030 + ,68.56 + ,2610 + ,2710 + ,14520 + ,4210 + ,73.67 + ,3040 + ,3230 + ,12970 + ,4510 + ,73.23 + ,3190 + ,3160 + ,13870 + ,4320 + ,61.96 + ,3120 + ,3040 + ,13250 + ,3890 + ,57.81 + ,3170 + ,2630 + ,12760 + ,7280 + ,58.76 + ,3600 + ,2730 + ,14050 + ,9640 + ,62.47 + ,3420 + ,2830 + ,14660 + ,5680 + ,53.68 + ,3650 + ,2320 + ,15010 + ,6320 + ,57.56 + ,4180 + ,2410 + ,15020 + ,5820 + ,62.05 + ,2960 + ,3080 + ,13090 + ,4890 + ,67.49 + ,2710 + ,2260 + ,13190 + ,3320 + ,67.21 + ,2950 + ,2300 + ,11390 + ,2930 + ,71.05 + ,3030 + ,3600 + ,10110 + ,3530 + ,76.93 + ,3770 + ,3380 + ,8240 + ,3690 + ,70.76 + ,4740 + ,3670 + ,7920 + ,3750 + ,77.17 + ,4450 + ,3040 + ,7700 + ,3330 + ,82.34 + ,5550 + ,2840 + ,7920 + ,4790 + ,92.41 + ,5580 + ,2810 + ,8130 + ,5990 + ,90.93 + ,5890 + ,2980 + ,10510 + ,5290 + ,92.18 + ,7480 + ,2440 + ,10230 + ,5310 + ,94.99 + ,10450 + ,2620 + ,10940 + ,4790 + ,103.64 + ,6360 + ,2270 + ,9230 + ,3630 + ,109.07 + ,6710 + ,2540 + ,10320 + ,2820 + ,122.8 + ,6200 + ,3060 + ,9590 + ,2770 + ,132.32 + ,4490 + ,3730 + ,9980 + ,2820 + ,132.72 + ,3480 + ,3450 + ,9630 + ,3750 + ,113.24 + ,2520 + ,3220 + ,9520 + ,3100 + ,97.23 + ,1920 + ,2980 + ,9150 + ,4350 + ,71.58 + ,2010 + ,2470 + ,9490 + ,4050 + ,52.45 + ,1950 + ,2240 + ,10090 + ,6000 + ,39.95 + ,2240 + ,1970 + ,9570 + ,10630 + ,43.44 + ,2370 + ,1860 + ,8870 + ,3750 + ,43.32 + ,2840 + ,2200 + ,8270 + ,3840 + ,46.54 + ,2700 + ,2000 + ,7530 + ,4200 + ,50.18 + ,2980 + ,1590 + ,10240 + ,2610 + ,57.3 + ,3290 + ,2280 + ,10590 + ,2610 + ,68.61 + ,3300 + ,2830 + ,9440 + ,2530 + ,64.44 + ,3000 + ,3060 + ,10620 + ,3090 + ,72.51 + ,2330 + ,3320 + ,11470 + ,4310 + ,67.65 + ,2190 + ,2680 + ,10680 + ,4190 + ,72.77 + ,1970 + ,2470 + ,11130 + ,3790 + ,76.66 + ,2170 + ,2500 + ,12390 + ,3910 + ,74.46 + ,2830 + ,2170 + ,10920 + ,4890 + ,76.17 + ,3190 + ,2070 + ,10320 + ,4970 + ,73.75 + ,3550 + ,2380 + ,10810 + ,5550 + ,78.83 + ,3240 + ,2480 + ,10280 + ,4730 + ,84.82 + ,3450 + ,2350 + ,11790 + ,4580 + ,75.95 + ,3570 + ,2610 + ,13290 + ,2500 + ,74.76 + ,3230 + ,3410 + ,11740 + ,2630 + ,75.58 + ,3260 + ,3380 + ,11320 + ,4300 + ,77.04 + ,2700 + ,2720 + ,11930 + ,3750 + ,77.84) + ,dim=c(5 + ,69) + ,dimnames=list(c('Garnalen' + ,'Kabeljauw' + ,'Tong' + ,'Zeeduivel' + ,'Olie') + ,1:69)) > y <- array(NA,dim=c(5,69),dimnames=list(c('Garnalen','Kabeljauw','Tong','Zeeduivel','Olie'),1:69)) > 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 = '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] "Garnalen" > x[,par1] [1] 3010 2910 3840 3580 3140 3550 3250 2820 2260 2060 2120 2210 [13] 2190 2180 2350 2440 2370 2440 2610 3040 3190 3120 3170 3600 [25] 3420 3650 4180 2960 2710 2950 3030 3770 4740 4450 5550 5580 [37] 5890 7480 10450 6360 6710 6200 4490 3480 2520 1920 2010 1950 [49] 2240 2370 2840 2700 2980 3290 3300 3000 2330 2190 1970 2170 [61] 2830 3190 3550 3240 3450 3570 3230 3260 2700 > 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]) [1920, 2710) [2710, 3420) [3420,10450] 23 23 23 > colnames(x) [1] "Garnalen" "Kabeljauw" "Tong" "Zeeduivel" "Olie" > colnames(x)[par1] [1] "Garnalen" > x[,par1] [1] [2710, 3420) [2710, 3420) [3420,10450] [3420,10450] [2710, 3420) [6] [3420,10450] [2710, 3420) [2710, 3420) [1920, 2710) [1920, 2710) [11] [1920, 2710) [1920, 2710) [1920, 2710) [1920, 2710) [1920, 2710) [16] [1920, 2710) [1920, 2710) [1920, 2710) [1920, 2710) [2710, 3420) [21] [2710, 3420) [2710, 3420) [2710, 3420) [3420,10450] [3420,10450] [26] [3420,10450] [3420,10450] [2710, 3420) [2710, 3420) [2710, 3420) [31] [2710, 3420) [3420,10450] [3420,10450] [3420,10450] [3420,10450] [36] [3420,10450] [3420,10450] [3420,10450] [3420,10450] [3420,10450] [41] [3420,10450] [3420,10450] [3420,10450] [3420,10450] [1920, 2710) [46] [1920, 2710) [1920, 2710) [1920, 2710) [1920, 2710) [1920, 2710) [51] [2710, 3420) [1920, 2710) [2710, 3420) [2710, 3420) [2710, 3420) [56] [2710, 3420) [1920, 2710) [1920, 2710) [1920, 2710) [1920, 2710) [61] [2710, 3420) [2710, 3420) [3420,10450] [2710, 3420) [3420,10450] [66] [3420,10450] [2710, 3420) [2710, 3420) [1920, 2710) Levels: [1920, 2710) [2710, 3420) [3420,10450] > 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/1dqyk1293213010.tab") + } + } > m Conditional inference tree with 2 terminal nodes Response: as.factor(Garnalen) Inputs: Kabeljauw, Tong, Zeeduivel, Olie Number of observations: 69 1) Olie <= 77.84; criterion = 0.998, statistic = 15.437 2)* weights = 55 1) Olie > 77.84 3)* weights = 14 > postscript(file="/var/www/rcomp/tmp/2ohfn1293213010.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/3ohfn1293213010.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 1 [2,] 2 1 [3,] 3 1 [4,] 3 1 [5,] 2 1 [6,] 3 1 [7,] 2 1 [8,] 2 1 [9,] 1 1 [10,] 1 1 [11,] 1 1 [12,] 1 1 [13,] 1 1 [14,] 1 1 [15,] 1 1 [16,] 1 1 [17,] 1 1 [18,] 1 1 [19,] 1 1 [20,] 2 1 [21,] 2 1 [22,] 2 1 [23,] 2 1 [24,] 3 1 [25,] 3 1 [26,] 3 1 [27,] 3 1 [28,] 2 1 [29,] 2 1 [30,] 2 1 [31,] 2 1 [32,] 3 1 [33,] 3 1 [34,] 3 3 [35,] 3 3 [36,] 3 3 [37,] 3 3 [38,] 3 3 [39,] 3 3 [40,] 3 3 [41,] 3 3 [42,] 3 3 [43,] 3 3 [44,] 3 3 [45,] 1 3 [46,] 1 1 [47,] 1 1 [48,] 1 1 [49,] 1 1 [50,] 1 1 [51,] 2 1 [52,] 1 1 [53,] 2 1 [54,] 2 1 [55,] 2 1 [56,] 2 1 [57,] 1 1 [58,] 1 1 [59,] 1 1 [60,] 1 1 [61,] 2 1 [62,] 2 1 [63,] 3 3 [64,] 2 3 [65,] 3 1 [66,] 3 1 [67,] 2 1 [68,] 2 1 [69,] 1 1 [1920, 2710) [2710, 3420) [3420,10450] [1920, 2710) 22 0 1 [2710, 3420) 22 0 1 [3420,10450] 11 0 12 > postscript(file="/var/www/rcomp/tmp/49iea1293213010.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/5krdv1293213010.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/6n9cj1293213010.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/7rasp1293213010.tab") + } > > try(system("convert tmp/2ohfn1293213010.ps tmp/2ohfn1293213010.png",intern=TRUE)) character(0) > try(system("convert tmp/3ohfn1293213010.ps tmp/3ohfn1293213010.png",intern=TRUE)) character(0) > try(system("convert tmp/49iea1293213010.ps tmp/49iea1293213010.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.970 0.290 2.239