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(3030.29 + ,25.64 + ,2803.47 + ,27.97 + ,2767.63 + ,27.62 + ,2882.6 + ,23.31 + ,2863.36 + ,29.07 + ,2897.06 + ,29.58 + ,3012.61 + ,28.63 + ,3142.95 + ,29.92 + ,3032.93 + ,32.68 + ,3045.78 + ,31.54 + ,3110.52 + ,32.43 + ,3013.24 + ,26.54 + ,2987.1 + ,25.85 + ,2995.55 + ,27.6 + ,2833.18 + ,25.71 + ,2848.96 + ,25.38 + ,2794.83 + ,28.57 + ,2845.26 + ,27.64 + ,2915.03 + ,25.36 + ,2892.63 + ,25.9 + ,2604.42 + ,26.29 + ,2641.65 + ,21.74 + ,2659.81 + ,19.2 + ,2638.53 + ,19.32 + ,2720.25 + ,19.82 + ,2745.88 + ,20.36 + ,2735.7 + ,24.31 + ,2811.7 + ,25.97 + ,2799.43 + ,25.61 + ,2555.28 + ,24.67 + ,2304.98 + ,25.59 + ,2214.95 + ,26.09 + ,2065.81 + ,28.37 + ,1940.49 + ,27.34 + ,2042 + ,24.46 + ,1995.37 + ,27.46 + ,1946.81 + ,30.23 + ,1765.9 + ,32.33 + ,1635.25 + ,29.87 + ,1833.42 + ,24.87 + ,1910.43 + ,25.48 + ,1959.67 + ,27.28 + ,1969.6 + ,28.24 + ,2061.41 + ,29.58 + ,2093.48 + ,26.95 + ,2120.88 + ,29.08 + ,2174.56 + ,28.76 + ,2196.72 + ,29.59 + ,2350.44 + ,30.7 + ,2440.25 + ,30.52 + ,2408.64 + ,32.67 + ,2472.81 + ,33.19 + ,2407.6 + ,37.13 + ,2454.62 + ,35.54 + ,2448.05 + ,37.75 + ,2497.84 + ,41.84 + ,2645.64 + ,42.94 + ,2756.76 + ,49.14 + ,2849.27 + ,44.61 + ,2921.44 + ,40.22 + ,2981.85 + ,44.23 + ,3080.58 + ,45.85 + ,3106.22 + ,53.38 + ,3119.31 + ,53.26 + ,3061.26 + ,51.8 + ,3097.31 + ,55.3 + ,3161.69 + ,57.81 + ,3257.16 + ,63.96 + ,3277.01 + ,63.77 + ,3295.32 + ,59.15 + ,3363.99 + ,56.12 + ,3494.17 + ,57.42 + ,3667.03 + ,63.52 + ,3813.06 + ,61.71 + ,3917.96 + ,63.01 + ,3895.51 + ,68.18 + ,3801.06 + ,72.03 + ,3570.12 + ,69.75 + ,3701.61 + ,74.41 + ,3862.27 + ,74.33 + ,3970.1 + ,64.24 + ,4138.52 + ,60.03 + ,4199.75 + ,59.44 + ,4290.89 + ,62.5 + ,4443.91 + ,55.04 + ,4502.64 + ,58.34 + ,4356.98 + ,61.92 + ,4591.27 + ,67.65 + ,4696.96 + ,67.68 + ,4621.4 + ,70.3 + ,4562.84 + ,75.26 + ,4202.52 + ,71.44 + ,4296.49 + ,76.36 + ,4435.23 + ,81.71 + ,4105.18 + ,92.6 + ,4116.68 + ,90.6 + ,3844.49 + ,92.23 + ,3720.98 + ,94.09 + ,3674.4 + ,102.79 + ,3857.62 + ,109.65 + ,3801.06 + ,124.05 + ,3504.37 + ,132.69 + ,3032.6 + ,135.81 + ,3047.03 + ,116.07 + ,2962.34 + ,101.42 + ,2197.82 + ,75.73 + ,2014.45 + ,55.48 + ,1862.83 + ,43.8 + ,1905.41 + ,45.29) + ,dim=c(2 + ,109) + ,dimnames=list(c('Aandelenkoers' + ,'Olieprijs') + ,1:109)) > y <- array(NA,dim=c(2,109),dimnames=list(c('Aandelenkoers','Olieprijs'),1:109)) > 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] "Aandelenkoers" > x[,par1] [1] 3030.29 2803.47 2767.63 2882.60 2863.36 2897.06 3012.61 3142.95 3032.93 [10] 3045.78 3110.52 3013.24 2987.10 2995.55 2833.18 2848.96 2794.83 2845.26 [19] 2915.03 2892.63 2604.42 2641.65 2659.81 2638.53 2720.25 2745.88 2735.70 [28] 2811.70 2799.43 2555.28 2304.98 2214.95 2065.81 1940.49 2042.00 1995.37 [37] 1946.81 1765.90 1635.25 1833.42 1910.43 1959.67 1969.60 2061.41 2093.48 [46] 2120.88 2174.56 2196.72 2350.44 2440.25 2408.64 2472.81 2407.60 2454.62 [55] 2448.05 2497.84 2645.64 2756.76 2849.27 2921.44 2981.85 3080.58 3106.22 [64] 3119.31 3061.26 3097.31 3161.69 3257.16 3277.01 3295.32 3363.99 3494.17 [73] 3667.03 3813.06 3917.96 3895.51 3801.06 3570.12 3701.61 3862.27 3970.10 [82] 4138.52 4199.75 4290.89 4443.91 4502.64 4356.98 4591.27 4696.96 4621.40 [91] 4562.84 4202.52 4296.49 4435.23 4105.18 4116.68 3844.49 3720.98 3674.40 [100] 3857.62 3801.06 3504.37 3032.60 3047.03 2962.34 2197.82 2014.45 1862.83 [109] 1905.41 > 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]) [1635,2962) [2962,4697] 55 54 > colnames(x) [1] "Aandelenkoers" "Olieprijs" > colnames(x)[par1] [1] "Aandelenkoers" > x[,par1] [1] [2962,4697] [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [7] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [13] [2962,4697] [2962,4697] [1635,2962) [1635,2962) [1635,2962) [1635,2962) [19] [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [25] [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [31] [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [37] [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [43] [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [49] [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [55] [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [1635,2962) [61] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [67] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [73] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [79] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [85] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [91] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [97] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [2962,4697] [103] [2962,4697] [2962,4697] [2962,4697] [1635,2962) [1635,2962) [1635,2962) [109] [1635,2962) Levels: [1635,2962) [2962,4697] > 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/1p7qv1291917029.tab") + } + } m.ct.i.pred m.ct.i.actu 1 2 1 472 18 2 101 398 [1] 0.9632653 [1] 0.7975952 [1] 0.8796764 m.ct.x.pred m.ct.x.actu 1 2 1 58 2 2 9 32 [1] 0.9666667 [1] 0.7804878 [1] 0.8910891 > m Conditional inference tree with 2 terminal nodes Response: as.factor(Aandelenkoers) Input: Olieprijs Number of observations: 109 1) Olieprijs <= 49.14; criterion = 1, statistic = 48.201 2)* weights = 64 1) Olieprijs > 49.14 3)* weights = 45 > postscript(file="/var/www/rcomp/tmp/2p7qv1291917029.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/3p7qv1291917029.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,] 1 1 [3,] 1 1 [4,] 1 1 [5,] 1 1 [6,] 1 1 [7,] 2 1 [8,] 2 1 [9,] 2 1 [10,] 2 1 [11,] 2 1 [12,] 2 1 [13,] 2 1 [14,] 2 1 [15,] 1 1 [16,] 1 1 [17,] 1 1 [18,] 1 1 [19,] 1 1 [20,] 1 1 [21,] 1 1 [22,] 1 1 [23,] 1 1 [24,] 1 1 [25,] 1 1 [26,] 1 1 [27,] 1 1 [28,] 1 1 [29,] 1 1 [30,] 1 1 [31,] 1 1 [32,] 1 1 [33,] 1 1 [34,] 1 1 [35,] 1 1 [36,] 1 1 [37,] 1 1 [38,] 1 1 [39,] 1 1 [40,] 1 1 [41,] 1 1 [42,] 1 1 [43,] 1 1 [44,] 1 1 [45,] 1 1 [46,] 1 1 [47,] 1 1 [48,] 1 1 [49,] 1 1 [50,] 1 1 [51,] 1 1 [52,] 1 1 [53,] 1 1 [54,] 1 1 [55,] 1 1 [56,] 1 1 [57,] 1 1 [58,] 1 1 [59,] 1 1 [60,] 1 1 [61,] 2 1 [62,] 2 1 [63,] 2 2 [64,] 2 2 [65,] 2 2 [66,] 2 2 [67,] 2 2 [68,] 2 2 [69,] 2 2 [70,] 2 2 [71,] 2 2 [72,] 2 2 [73,] 2 2 [74,] 2 2 [75,] 2 2 [76,] 2 2 [77,] 2 2 [78,] 2 2 [79,] 2 2 [80,] 2 2 [81,] 2 2 [82,] 2 2 [83,] 2 2 [84,] 2 2 [85,] 2 2 [86,] 2 2 [87,] 2 2 [88,] 2 2 [89,] 2 2 [90,] 2 2 [91,] 2 2 [92,] 2 2 [93,] 2 2 [94,] 2 2 [95,] 2 2 [96,] 2 2 [97,] 2 2 [98,] 2 2 [99,] 2 2 [100,] 2 2 [101,] 2 2 [102,] 2 2 [103,] 2 2 [104,] 2 2 [105,] 2 2 [106,] 1 2 [107,] 1 2 [108,] 1 1 [109,] 1 1 [1635,2962) [2962,4697] [1635,2962) 53 2 [2962,4697] 11 43 > postscript(file="/var/www/rcomp/tmp/4hgpx1291917029.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/5d8561291917029.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/6hqlu1291917029.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/7903x1291917029.tab") + } > > try(system("convert tmp/2p7qv1291917029.ps tmp/2p7qv1291917029.png",intern=TRUE)) character(0) > try(system("convert tmp/3p7qv1291917029.ps tmp/3p7qv1291917029.png",intern=TRUE)) character(0) > try(system("convert tmp/4hgpx1291917029.ps tmp/4hgpx1291917029.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.260 0.600 2.832