R version 2.8.0 (2008-10-20) Copyright (C) 2008 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. Natural language support but running in an English locale 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(186448 + ,17822 + ,1942 + ,16739 + ,4872 + ,1020 + ,190530 + ,22422 + ,2547 + ,17851 + ,4905 + ,1200 + ,194207 + ,18817 + ,2033 + ,17034 + ,4971 + ,1279 + ,190855 + ,22043 + ,2049 + ,18055 + ,4971 + ,1308 + ,200779 + ,19191 + ,2007 + ,18216 + ,4930 + ,1173 + ,204428 + ,23171 + ,2660 + ,18960 + ,5001 + ,1291 + ,207617 + ,19463 + ,2063 + ,17903 + ,5059 + ,1466 + ,212071 + ,22522 + ,2113 + ,18842 + ,5085 + ,1507 + ,214239 + ,20265 + ,2145 + ,18907 + ,5111 + ,1478 + ,215883 + ,24249 + ,2866 + ,19862 + ,5190 + ,1629 + ,223484 + ,20299 + ,2163 + ,18836 + ,5076 + ,1712 + ,221529 + ,25455 + ,2157 + ,19846 + ,5134 + ,1727 + ,225247 + ,21089 + ,2201 + ,19511 + ,4804 + ,1519 + ,226699 + ,26237 + ,2838 + ,20318 + ,4579 + ,1617 + ,231406 + ,21362 + ,2142 + ,19843 + ,4526 + ,1637 + ,232324 + ,26489 + ,2253 + ,20975 + ,4550 + ,1633 + ,237192 + ,21828 + ,2258 + ,20485 + ,4566 + ,1469 + ,236727 + ,27496 + ,2979 + ,21407 + ,4588 + ,1657 + ,240698 + ,21991 + ,2288 + ,20404 + ,4564 + ,1599 + ,240688 + ,27611 + ,2431 + ,21454 + ,4723 + ,1420 + ,245283 + ,22512 + ,2393 + ,21558 + ,4553 + ,1495 + ,243556 + ,28581 + ,3244 + ,22442 + ,4556 + ,1623 + ,247826 + ,23000 + ,2476 + ,21201 + ,4542 + ,1346 + ,245798 + ,28385 + ,2490 + ,21804 + ,4234 + ,1613 + ,250479 + ,23387 + ,2547 + ,22537 + ,4341 + ,1563 + ,249216 + ,30192 + ,3461 + ,22736 + ,4269 + ,2071 + ,251896 + ,24346 + ,2549 + ,21525 + ,4217 + ,1584 + ,247616 + ,30393 + ,2496 + ,22427 + ,4207 + ,1843 + ,249994 + ,24753 + ,2532 + ,23437 + ,4267 + ,1598 + ,246552 + ,31723 + ,3553 + ,23366 + ,4249 + ,1687 + ,248771 + ,24838 + ,2555 + ,22281 + ,4217 + ,1473 + ,247551 + ,32272 + ,2565 + ,22994 + ,4172 + ,2080 + ,249745 + ,25219 + ,2548 + ,24007 + ,4161 + ,1703 + ,245742 + ,33191 + ,3932 + ,24145 + ,4103 + ,1832 + ,249019 + ,26218 + ,2525 + ,23065 + ,4027 + ,1781 + ,245841 + ,33537 + ,2633 + ,24374 + ,4042 + ,2481 + ,248771 + ,27975 + ,2657 + ,24805 + ,4120 + ,1977 + ,244723 + ,34356 + ,3829 + ,25159 + ,4188 + ,1974 + ,246878 + ,27082 + ,2769 + ,23751 + ,4185 + ,1777 + ,246014 + ,34333 + ,2816 + ,25487 + ,4216 + ,2303 + ,248496 + ,28141 + ,3052 + ,25608 + ,4250 + ,1480 + ,244351 + ,36125 + ,4146 + ,26396 + ,4259 + ,1907 + ,248016 + ,28451 + ,3185 + ,25207 + ,4206 + ,1610 + ,246509 + ,35801 + ,3147 + ,27000 + ,4132 + ,1546 + ,249426 + ,28979 + ,3161 + ,27369 + ,3944 + ,1718 + ,247840 + ,37285 + ,4311 + ,28401 + ,3872 + ,1841 + ,251035 + ,30310 + ,3155 + ,27126 + ,3797 + ,1650 + ,250161 + ,36721 + ,3284 + ,28474 + ,3840 + ,1671 + ,254278 + ,29534 + ,3350 + ,28926 + ,3895 + ,1974 + ,250801 + ,38626 + ,4268 + ,29894 + ,3633 + ,2153 + ,253985 + ,29654 + ,3220 + ,28822 + ,3622 + ,1898 + ,249174 + ,42638 + ,8289 + ,29849 + ,3562 + ,2725 + ,251287 + ,31372 + ,3419 + ,30624 + ,3555 + ,2047 + ,247947 + ,39603 + ,3902 + ,31038 + ,3489 + ,1698 + ,249992 + ,31647 + ,3223 + ,29468 + ,3500 + ,1768 + ,243805 + ,39946 + ,3447 + ,31294 + ,3373 + ,1921 + ,255812 + ,31518 + ,3389 + ,32110 + ,3285 + ,9782 + ,250417 + ,42743 + ,4637 + ,32827 + ,3292 + ,2231 + ,253033 + ,33462 + ,3509 + ,31327 + ,3241 + ,2062 + ,248705 + ,41744 + ,4107 + ,32749 + ,3266 + ,2132 + ,253950 + ,33142 + ,3632 + ,33598 + ,3168 + ,2465 + ,251484 + ,41753 + ,4490 + ,33878 + ,3181 + ,2198 + ,251093 + ,35487 + ,3649 + ,32292 + ,3246 + ,2330 + ,245996 + ,44720 + ,3983 + ,34021 + ,3159 + ,1214 + ,252721 + ,33472 + ,3678 + ,34955 + ,3209 + ,2517 + ,248019 + ,45134 + ,4570 + ,35322 + ,3220 + ,2255 + ,250464 + ,36255 + ,3778 + ,33816 + ,3305 + ,2379 + ,245571 + ,46228 + ,4153 + ,35766 + ,3251 + ,2349 + ,252690 + ,35483 + ,4027 + ,36770 + ,3281 + ,2219 + ,250183 + ,47663 + ,5050 + ,37762 + ,3304 + ,2470 + ,253639 + ,38064 + ,4155 + ,36298 + ,3270 + ,2540 + ,254436 + ,47177 + ,4475 + ,39219 + ,3377 + ,2667 + ,265280 + ,35062 + ,4117 + ,39664 + ,3235 + ,3507 + ,268705 + ,45062 + ,5193 + ,40178 + ,3125 + ,2972 + ,270643 + ,36943 + ,4199 + ,38402 + ,3091 + ,2678 + ,271480 + ,46194 + ,4391 + ,40957 + ,3102 + ,2979) + ,dim=c(6 + ,76) + ,dimnames=list(c('Nettoschuld' + ,'ParafiscaleOntvangsten' + ,'Niet-parafiscaleOntvangsten' + ,'LopendeUitgaven' + ,'Rentelasten' + ,'KapitaalUitgaven') + ,1:76)) > y <- array(NA,dim=c(6,76),dimnames=list(c('Nettoschuld','ParafiscaleOntvangsten','Niet-parafiscaleOntvangsten','LopendeUitgaven','Rentelasten','KapitaalUitgaven'),1:76)) > 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 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] "Nettoschuld" > x[,par1] [1] 186448 190530 194207 190855 200779 204428 207617 212071 214239 215883 [11] 223484 221529 225247 226699 231406 232324 237192 236727 240698 240688 [21] 245283 243556 247826 245798 250479 249216 251896 247616 249994 246552 [31] 248771 247551 249745 245742 249019 245841 248771 244723 246878 246014 [41] 248496 244351 248016 246509 249426 247840 251035 250161 254278 250801 [51] 253985 249174 251287 247947 249992 243805 255812 250417 253033 248705 [61] 253950 251484 251093 245996 252721 248019 250464 245571 252690 250183 [71] 253639 254436 265280 268705 270643 271480 > 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]) [186448,247947) [247947,271480] 38 38 > colnames(x) [1] "Nettoschuld" "ParafiscaleOntvangsten" [3] "Niet.parafiscaleOntvangsten" "LopendeUitgaven" [5] "Rentelasten" "KapitaalUitgaven" > colnames(x)[par1] [1] "Nettoschuld" > x[,par1] [1] [186448,247947) [186448,247947) [186448,247947) [186448,247947) [5] [186448,247947) [186448,247947) [186448,247947) [186448,247947) [9] [186448,247947) [186448,247947) [186448,247947) [186448,247947) [13] [186448,247947) [186448,247947) [186448,247947) [186448,247947) [17] [186448,247947) [186448,247947) [186448,247947) [186448,247947) [21] [186448,247947) [186448,247947) [186448,247947) [186448,247947) [25] [247947,271480] [247947,271480] [247947,271480] [186448,247947) [29] [247947,271480] [186448,247947) [247947,271480] [186448,247947) [33] [247947,271480] [186448,247947) [247947,271480] [186448,247947) [37] [247947,271480] [186448,247947) [186448,247947) [186448,247947) [41] [247947,271480] [186448,247947) [247947,271480] [186448,247947) [45] [247947,271480] [186448,247947) [247947,271480] [247947,271480] [49] [247947,271480] [247947,271480] [247947,271480] [247947,271480] [53] [247947,271480] [247947,271480] [247947,271480] [186448,247947) [57] [247947,271480] [247947,271480] [247947,271480] [247947,271480] [61] [247947,271480] [247947,271480] [247947,271480] [186448,247947) [65] [247947,271480] [247947,271480] [247947,271480] [186448,247947) [69] [247947,271480] [247947,271480] [247947,271480] [247947,271480] [73] [247947,271480] [247947,271480] [247947,271480] [247947,271480] Levels: [186448,247947) [247947,271480] > if (par2 == 'none') { + m <- ctree(as.formula(paste(colnames(x)[par1],' ~ .',sep='')),data = x) + } > > #Note: the /var/www/html/freestat/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/freestat/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/freestat/rcomp/tmp/1tj0r1293786264.tab") + } + } m.ct.i.pred m.ct.i.actu 1 2 1 260 72 2 30 317 [1] 0.7831325 [1] 0.9135447 [1] 0.8497791 m.ct.x.pred m.ct.x.actu 1 2 1 34 14 2 8 25 [1] 0.7083333 [1] 0.7575758 [1] 0.728395 > m Conditional inference tree with 4 terminal nodes Response: as.factor(Nettoschuld) Inputs: ParafiscaleOntvangsten, Niet.parafiscaleOntvangsten, LopendeUitgaven, Rentelasten, KapitaalUitgaven Number of observations: 76 1) Rentelasten <= 4027; criterion = 1, statistic = 35.428 2)* weights = 33 1) Rentelasten > 4027 3) Rentelasten <= 4341; criterion = 0.979, statistic = 8.199 4) ParafiscaleOntvangsten <= 30192; criterion = 0.996, statistic = 11.229 5)* weights = 11 4) ParafiscaleOntvangsten > 30192 6)* weights = 9 3) Rentelasten > 4341 7)* weights = 23 > postscript(file="/var/www/html/freestat/rcomp/tmp/2z1rb1293786264.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/freestat/rcomp/tmp/3222p1293786264.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,] 1 1 [2,] 1 1 [3,] 1 1 [4,] 1 1 [5,] 1 1 [6,] 1 1 [7,] 1 1 [8,] 1 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,] 1 1 [21,] 1 1 [22,] 1 1 [23,] 1 1 [24,] 1 2 [25,] 2 2 [26,] 2 2 [27,] 2 2 [28,] 1 1 [29,] 2 2 [30,] 1 1 [31,] 2 2 [32,] 1 1 [33,] 2 2 [34,] 1 1 [35,] 2 2 [36,] 1 1 [37,] 2 2 [38,] 1 1 [39,] 1 2 [40,] 1 1 [41,] 2 2 [42,] 1 1 [43,] 2 2 [44,] 1 1 [45,] 2 2 [46,] 1 2 [47,] 2 2 [48,] 2 2 [49,] 2 2 [50,] 2 2 [51,] 2 2 [52,] 2 2 [53,] 2 2 [54,] 2 2 [55,] 2 2 [56,] 1 2 [57,] 2 2 [58,] 2 2 [59,] 2 2 [60,] 2 2 [61,] 2 2 [62,] 2 2 [63,] 2 2 [64,] 1 2 [65,] 2 2 [66,] 2 2 [67,] 2 2 [68,] 1 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 [186448,247947) [247947,271480] [186448,247947) 32 6 [247947,271480] 0 38 > postscript(file="/var/www/html/freestat/rcomp/tmp/46m5q1293786264.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/freestat/rcomp/tmp/5uq6n1293786264.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/freestat/rcomp/tmp/63bgv1293786264.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/freestat/rcomp/tmp/74aj91293786264.tab") + } > > try(system("convert tmp/2z1rb1293786264.ps tmp/2z1rb1293786264.png",intern=TRUE)) character(0) > try(system("convert tmp/3222p1293786264.ps tmp/3222p1293786264.png",intern=TRUE)) character(0) > try(system("convert tmp/46m5q1293786264.ps tmp/46m5q1293786264.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 4.510 0.696 5.414