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(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 = 'none' > 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 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] "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 1950 1970 2010 2060 2120 2170 2180 2190 2210 2240 2260 2330 1 1 1 1 1 1 1 1 2 1 1 1 1 2350 2370 2440 2520 2610 2700 2710 2820 2830 2840 2910 2950 2960 1 2 2 1 1 2 1 1 1 1 1 1 1 2980 3000 3010 3030 3040 3120 3140 3170 3190 3230 3240 3250 3260 1 1 1 1 1 1 1 1 2 1 1 1 1 3290 3300 3420 3450 3480 3550 3570 3580 3600 3650 3770 3840 4180 1 1 1 1 1 2 1 1 1 1 1 1 1 4450 4490 4740 5550 5580 5890 6200 6360 6710 7480 10450 1 1 1 1 1 1 1 1 1 1 1 > colnames(x) [1] "Garnalen" "Kabeljauw" "Tong" "Zeeduivel" "Olie" > 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 == '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/1efk51293212908.tab") + } + } > m Conditional inference tree with 3 terminal nodes Response: Garnalen Inputs: Kabeljauw, Tong, Zeeduivel, Olie Number of observations: 69 1) Olie <= 84.82; criterion = 1, statistic = 26.691 2) Kabeljauw <= 2720; criterion = 0.972, statistic = 7.243 3)* weights = 40 2) Kabeljauw > 2720 4)* weights = 18 1) Olie > 84.82 5)* weights = 11 > postscript(file="/var/www/html/rcomp/tmp/2efk51293212908.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/377jq1293212908.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 3010 2780.250 229.750000 2 2910 2780.250 129.750000 3 3840 2780.250 1059.750000 4 3580 3243.333 336.666667 5 3140 2780.250 359.750000 6 3550 2780.250 769.750000 7 3250 2780.250 469.750000 8 2820 2780.250 39.750000 9 2260 2780.250 -520.250000 10 2060 2780.250 -720.250000 11 2120 2780.250 -660.250000 12 2210 2780.250 -570.250000 13 2190 2780.250 -590.250000 14 2180 2780.250 -600.250000 15 2350 2780.250 -430.250000 16 2440 3243.333 -803.333333 17 2370 2780.250 -410.250000 18 2440 2780.250 -340.250000 19 2610 2780.250 -170.250000 20 3040 3243.333 -203.333333 21 3190 3243.333 -53.333333 22 3120 3243.333 -123.333333 23 3170 2780.250 389.750000 24 3600 3243.333 356.666667 25 3420 3243.333 176.666667 26 3650 2780.250 869.750000 27 4180 2780.250 1399.750000 28 2960 3243.333 -283.333333 29 2710 2780.250 -70.250000 30 2950 2780.250 169.750000 31 3030 3243.333 -213.333333 32 3770 3243.333 526.666667 33 4740 3243.333 1496.666667 34 4450 3243.333 1206.666667 35 5550 5882.727 -332.727273 36 5580 5882.727 -302.727273 37 5890 5882.727 7.272727 38 7480 5882.727 1597.272727 39 10450 5882.727 4567.272727 40 6360 5882.727 477.272727 41 6710 5882.727 827.272727 42 6200 5882.727 317.272727 43 4490 5882.727 -1392.727273 44 3480 5882.727 -2402.727273 45 2520 5882.727 -3362.727273 46 1920 3243.333 -1323.333333 47 2010 2780.250 -770.250000 48 1950 2780.250 -830.250000 49 2240 2780.250 -540.250000 50 2370 2780.250 -410.250000 51 2840 2780.250 59.750000 52 2700 2780.250 -80.250000 53 2980 2780.250 199.750000 54 3290 2780.250 509.750000 55 3300 3243.333 56.666667 56 3000 3243.333 -243.333333 57 2330 3243.333 -913.333333 58 2190 2780.250 -590.250000 59 1970 2780.250 -810.250000 60 2170 2780.250 -610.250000 61 2830 2780.250 49.750000 62 3190 2780.250 409.750000 63 3550 2780.250 769.750000 64 3240 2780.250 459.750000 65 3450 2780.250 669.750000 66 3570 2780.250 789.750000 67 3230 3243.333 -13.333333 68 3260 3243.333 16.666667 69 2700 2780.250 -80.250000 > 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/4zyjb1293212908.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/5kghh1293212908.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/6ohfn1293212908.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/7hqxq1293212908.tab") + } > > try(system("convert tmp/2efk51293212908.ps tmp/2efk51293212908.png",intern=TRUE)) character(0) > try(system("convert tmp/377jq1293212908.ps tmp/377jq1293212908.png",intern=TRUE)) character(0) > try(system("convert tmp/4zyjb1293212908.ps tmp/4zyjb1293212908.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.206 0.591 6.813