R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-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(317 + ,310232.86 + ,41.761 + ,0.939 + ,0.923 + ,0.869 + ,267 + ,1330141.29 + ,6.2 + ,0.623 + ,0.843 + ,0.618 + ,204 + ,139390.2 + ,13.611 + ,0.784 + ,0.77 + ,0.713 + ,198 + ,62348.45 + ,32.147 + ,0.815 + ,0.949 + ,0.832 + ,107 + ,81644.45 + ,32.255 + ,0.928 + ,0.953 + ,0.838 + ,89 + ,64768.39 + ,29.578 + ,0.87 + ,0.971 + ,0.819 + ,88 + ,48636.07 + ,25.493 + ,0.934 + ,0.956 + ,0.808 + ,80 + ,126804.43 + ,29.692 + ,0.883 + ,1.000 + ,0.827 + ,79 + ,21515.75 + ,34.259 + ,0.981 + ,0.976 + ,0.837 + ,69 + ,60748.96 + ,26.578 + ,0.856 + ,0.976 + ,0.799 + ,53 + ,9992.34 + ,16.896 + ,0.866 + ,0.858 + ,0.732 + ,50 + ,16783.09 + ,36.358 + ,0.931 + ,0.958 + ,0.845 + ,49 + ,45415.6 + ,5.737 + ,0.858 + ,0.765 + ,0.591 + ,42 + ,15460.48 + ,10.452 + ,0.834 + ,0.742 + ,0.668 + ,39 + ,4252.28 + ,24.706 + ,1.000 + ,0.957 + ,0.783 + ,39 + ,46505.96 + ,27.066 + ,0.874 + ,0.969 + ,0.799 + ,34 + ,201103.33 + ,9.414 + ,0.663 + ,0.844 + ,0.662 + ,33 + ,76923.3 + ,10.496 + ,0.64 + ,0.836 + ,0.662 + ,32 + ,2847.23 + ,6.931 + ,0.768 + ,0.838 + ,0.598 + ,29 + ,10201.71 + ,22.098 + ,0.924 + ,0.91 + ,0.769 + ,27 + ,33759.74 + ,34.567 + ,0.927 + ,0.962 + ,0.84 + ,25 + ,9612.63 + ,11.841 + ,0.776 + ,0.794 + ,0.702 + ,23 + ,40046.57 + ,1.428 + ,0.582 + ,0.586 + ,0.387 + ,22 + ,21959.28 + ,10.794 + ,0.831 + ,0.851 + ,0.674 + ,21 + ,5515.57 + ,32.252 + ,0.924 + ,0.928 + ,0.836 + ,20 + ,8303.51 + ,8.752 + ,0.671 + ,0.8 + ,0.639 + ,20 + ,88013.49 + ,848 + ,0.237 + ,0.619 + ,0.326 + ,20 + ,38463.69 + ,16.705 + ,0.822 + ,0.885 + ,0.739 + ,20 + ,49109.11 + ,9.333 + ,0.705 + ,0.517 + ,0.652 + ,19 + ,4486.88 + ,16.338 + ,0.778 + ,0.893 + ,0.724 + ,16 + ,9074.06 + ,32.314 + ,0.904 + ,0.969 + ,0.842 + ,15 + ,44205.29 + ,8.136 + ,0.667 + ,0.847 + ,0.633 + ,15 + ,77804.12 + ,11.209 + ,0.583 + ,0.851 + ,0.689 + ,14 + ,4600.82 + ,4.335 + ,0.839 + ,0.848 + ,0.554 + ,14 + ,3545.32 + ,15.011 + ,0.883 + ,0.824 + ,0.729 + ,14 + ,112468.85 + ,12.429 + ,0.726 + ,0.898 + ,0.7 + ,14 + ,7623.44 + ,36.954 + ,0.872 + ,0.983 + ,0.858 + ,13 + ,4676.31 + ,47.676 + ,0.985 + ,0.964 + ,0.883 + ,10 + ,4622.92 + ,36.278 + ,0.963 + ,0.955 + ,0.814 + ,9 + ,41343.2 + ,13.202 + ,0.806 + ,0.882 + ,0.713 + ,9 + ,7344.85 + ,9.967 + ,0.79 + ,0.86 + ,0.663 + ,9 + ,2003.14 + ,24.806 + ,0.933 + ,0.936 + ,0.79 + ,8 + ,1173108.02 + ,2.993 + ,0.45 + ,0.717 + ,0.508 + ,8 + ,1228.69 + ,23.221 + ,0.712 + ,0.791 + ,0.782 + ,8 + ,10525.04 + ,7.512 + ,0.645 + ,0.86 + ,0.614 + ,8 + ,27865.74 + ,2.611 + ,0.711 + ,0.762 + ,0.486 + ,7 + ,9823.82 + ,7.658 + ,0.616 + ,0.842 + ,0.629 + ,7 + ,3086.92 + ,3.198 + ,0.722 + ,0.765 + ,0.505 + ,6 + ,2217.97 + ,12.847 + ,0.873 + ,0.841 + ,0.711 + ,5 + ,34586.18 + ,7.421 + ,0.652 + ,0.838 + ,0.621 + ,5 + ,107.82 + ,7.593 + ,0.779 + ,0.883 + ,0.608 + ,5 + ,5470.31 + ,19.202 + ,0.875 + ,0.875 + ,0.759 + ,5 + ,66336.26 + ,7.26 + ,0.597 + ,0.854 + ,0.622 + ,5 + ,33398.68 + ,1.105 + ,0.475 + ,0.538 + ,0.347 + ,5 + ,27223.23 + ,11.19 + ,0.692 + ,0.858 + ,0.669 + ,4 + ,2966.8 + ,4.794 + ,0.76 + ,0.856 + ,0.566 + ,4 + ,10423.49 + ,32.395 + ,0.882 + ,0.947 + ,0.832 + ,4 + ,80471.87 + ,5.151 + ,0.56 + ,0.84 + ,0.568 + ,4 + ,5255.07 + ,30.784 + ,0.877 + ,0.946 + ,0.828 + ,3 + ,7148.78 + ,11.456 + ,0.802 + ,0.842 + ,0.678 + ,3 + ,1291.17 + ,16.132 + ,0.916 + ,0.865 + ,0.734 + ,3 + ,242968.34 + ,3.813 + ,0.584 + ,0.779 + ,0.518 + ,3 + ,28274.73 + ,12.724 + ,0.73 + ,0.855 + ,0.704 + ,2 + ,2029.31 + ,12.154 + ,0.693 + ,0.523 + ,0.698 + ,2 + ,1102.68 + ,25.759 + ,0.798 + ,0.94 + ,0.79 + ,2 + ,1545.26 + ,13.094 + ,0.66 + ,0.674 + ,0.689 + ,2 + ,10749.94 + ,26.482 + ,0.861 + ,0.945 + ,0.783 + ,2 + ,13550.44 + ,4.286 + ,0.438 + ,0.807 + ,0.534 + ,2 + ,666.73 + ,10.022 + ,0.802 + ,0.861 + ,0.665 + ,2 + ,10735.76 + ,21.37 + ,0.739 + ,0.938 + ,0.763 + ,2 + ,840.93 + ,82.978 + ,0.623 + ,0.921 + ,1.000 + ,2 + ,4317.48 + ,2.592 + ,0.716 + ,0.778 + ,0.49 + ,2 + ,4701.07 + ,45.978 + ,0.751 + ,0.964 + ,0.897 + ,1 + ,29121.29 + ,1.20 + ,0.367 + ,0.452 + ,0.38 + ,1 + ,7089.7 + ,39.255 + ,0.837 + ,0.99 + ,0.874 + ,1 + ,31627.43 + ,4.081 + ,0.447 + ,0.823 + ,0.535 + ,1 + ,25731.78 + ,21.321 + ,0.689 + ,0.85 + ,0.781 + ,1 + ,7487.49 + ,1.791 + ,0.704 + ,0.75 + ,0.425 + ,0 + ,2986.95 + ,7.449 + ,0.721 + ,0.898 + ,0.624 + ,0 + ,13068.16 + ,5.278 + ,0.422 + ,0.49 + ,0.557 + ,0 + ,86.75 + ,17.052 + ,0.744 + ,0.83 + ,0.723 + ,0 + ,8214.16 + ,34.673 + ,0.858 + ,0.96 + ,0.842 + ,0 + ,156118.46 + ,1.286 + ,0.415 + ,0.772 + ,0.391 + ,0 + ,314.52 + ,6.019 + ,0.663 + ,0.884 + ,0.582 + ,0 + ,9056.01 + ,1.369 + ,0.365 + ,0.569 + ,0.374 + ,0 + ,699.85 + ,4.643 + ,0.336 + ,0.744 + ,0.568 + ,0 + ,9947.42 + ,4.013 + ,0.749 + ,0.735 + ,0.53 + ,0 + ,4621.6 + ,7.266 + ,0.723 + ,0.878 + ,0.621 + ,0 + ,16241.81 + ,1.078 + ,0.187 + ,0.559 + ,0.349 + ,0 + ,9863.12 + ,356 + ,0.353 + ,0.48 + ,0.186 + ,0 + ,14453.68 + ,1.739 + ,0.502 + ,0.68 + ,0.418 + ,0 + ,19294.15 + ,2.002 + ,0.52 + ,0.499 + ,0.431 + ,0 + ,508.66 + ,3.309 + ,0.425 + ,0.854 + ,0.505 + ,0 + ,4844.93 + ,688 + ,0.321 + ,0.448 + ,0.28 + ,0 + ,10543.46 + ,1.181 + ,0.219 + ,0.466 + ,0.344 + ,0 + ,16746.49 + ,13.057 + ,0.797 + ,0.932 + ,0.701 + ,0 + ,773.41 + ,1.074 + ,0.368 + ,0.648 + ,0.341 + ,0 + ,4125.92 + ,3.848 + ,0.523 + ,0.59 + ,0.49 + ,0 + ,4516.22 + ,10.085 + ,0.659 + ,0.936 + ,0.667 + ,0 + ,21058.8 + ,1.545 + ,0.304 + ,0.558 + ,0.377 + ,0 + ,740.53 + ,2.106 + ,0.294 + ,0.598 + ,0.451 + ,0 + ,72.81 + ,8.066 + ,0.67 + ,0.907 + ,0.626 + ,0 + ,69851.29 + ,290 + ,0.356 + ,0.448 + ,0.147 + ,0 + ,14790.61 + ,7.508 + ,0.686 + ,0.877 + ,0.62 + ,0 + ,6052.06 + ,6.02 + ,0.637 + ,0.823 + ,0.585 + ,0 + ,650.7 + ,28.857 + ,0.427 + ,0.49 + ,0.741 + ,0 + ,5792.98 + ,527 + ,0.271 + ,0.656 + ,0.24 + ,0 + ,875.98 + ,4.11 + ,0.786 + ,0.777 + ,0.533 + ,0 + ,1755.46 + ,1.285 + ,0.334 + ,0.607 + ,0.365 + ,0 + ,24339.84 + ,1.41 + ,0.574 + ,0.698 + ,0.396 + ,0 + ,10324.02 + ,951 + ,0.246 + ,0.538 + ,0.309 + ,0 + ,1565.13 + ,973 + ,0.302 + ,0.444 + ,0.329 + ,0 + ,748.49 + ,2.942 + ,0.65 + ,0.787 + ,0.496 + ,0 + ,9648.92 + ,1.045 + ,0.406 + ,0.664 + ,0.346 + ,0 + ,7989.41 + ,3.488 + ,0.574 + ,0.838 + ,0.507 + ,0 + ,308.91 + ,33.98 + ,0.912 + ,0.975 + ,0.814 + ,0 + ,29671.6 + ,3.222 + ,0.491 + ,0.774 + ,0.495 + ,0 + ,7353.98 + ,25.474 + ,0.907 + ,0.972 + ,0.796 + ,0 + ,6407.09 + ,5.082 + ,0.71 + ,0.842 + ,0.569 + ,0 + ,99.48 + ,2.209 + ,0.647 + ,0.759 + ,0.494 + ,0 + ,5508.63 + ,2.073 + ,0.716 + ,0.753 + ,0.432 + ,0 + ,6368.16 + ,2.048 + ,0.432 + ,0.749 + ,0.445 + ,0 + ,4125.25 + ,11.868 + ,0.695 + ,0.83 + ,0.698 + ,0 + ,1919.55 + ,1.333 + ,0.507 + ,0.445 + ,0.403 + ,0 + ,3685.08 + ,360 + ,0.439 + ,0.58 + ,0.14 + ,0 + ,6461.45 + ,14.985 + ,0.731 + ,0.864 + ,0.693 + ,0 + ,497.54 + ,68.853 + ,0.771 + ,0.946 + ,0.892 + ,0 + ,21281.84 + ,912 + ,0.497 + ,0.737 + ,0.302 + ,0 + ,15447.5 + ,721 + ,0.41 + ,0.54 + ,0.289 + ,0 + ,395.65 + ,4.972 + ,0.568 + ,0.897 + ,0.568 + ,0 + ,13796.35 + ,1.077 + ,0.27 + ,0.496 + ,0.346 + ,0 + ,406.77 + ,21.987 + ,0.797 + ,0.941 + ,0.769 + ,0 + ,3205.06 + ,1.751 + ,0.366 + ,0.609 + ,0.419 + ,0 + ,1294.1 + ,11.658 + ,0.659 + ,0.842 + ,0.696 + ,0 + ,107.15 + ,2.804 + ,0.689 + ,0.773 + ,0.484 + ,0 + ,22417.45 + ,804 + ,0.222 + ,0.477 + ,0.314 + ,0 + ,2128.47 + ,5.821 + ,0.617 + ,0.67 + ,0.591 + ,0 + ,28951.85 + ,1.049 + ,0.356 + ,0.77 + ,0.351 + ,0 + ,5604.45 + ,2.398 + ,0.525 + ,0.852 + ,0.457 + ,0 + ,15878.27 + ,626 + ,0.177 + ,0.547 + ,0.266 + ,0 + ,152217.34 + ,2.001 + ,0.442 + ,0.503 + ,0.434 + ,0 + ,184404.79 + ,2.369 + ,0.386 + ,0.717 + ,0.464 + ,0 + ,3410.68 + ,11.857 + ,0.743 + ,0.885 + ,0.69 + ,0 + ,6064.52 + ,2.072 + ,0.335 + ,0.675 + ,0.447 + ,0 + ,6375.83 + ,4.107 + ,0.643 + ,0.828 + ,0.552 + ,0 + ,28947.97 + ,7.836 + ,0.704 + ,0.852 + ,0.634 + ,0 + ,99900.18 + ,3.216 + ,0.684 + ,0.769 + ,0.508 + ,0 + ,11055.98 + ,1.032 + ,0.407 + ,0.559 + ,0.348 + ,0 + ,175.81 + ,1.653 + ,0.452 + ,0.705 + ,0.413 + ,0 + ,160.92 + ,8.722 + ,0.693 + ,0.862 + ,0.632 + ,0 + ,192 + ,4 + ,0.75 + ,0.827 + ,0.526 + ,0 + ,12323.25 + ,1.65 + ,0.385 + ,0.62 + ,0.406 + ,0 + ,88.34 + ,17.786 + ,0.747 + ,0.845 + ,0.733 + ,0 + ,5245.69 + ,734 + ,0.304 + ,0.438 + ,0.286 + ,0 + ,559.2 + ,2.312 + ,0.427 + ,0.755 + ,0.413 + ,0 + ,21083.83 + ,4.333 + ,0.68 + ,0.867 + ,0.559 + ,0 + ,49.9 + ,13.191 + ,0.693 + ,0.838 + ,0.684 + ,0 + ,104.22 + ,8.312 + ,0.712 + ,0.825 + ,0.628 + ,0 + ,43939.6 + ,2.007 + ,0.247 + ,0.654 + ,0.421 + ,0 + ,1354.05 + ,4.539 + ,0.578 + ,0.453 + ,0.545 + ,0 + ,22198.11 + ,4.295 + ,0.534 + ,0.881 + ,0.537 + ,0 + ,41892.89 + ,1.237 + ,0.454 + ,0.603 + ,0.37 + ,0 + ,1154.62 + ,731 + ,0.371 + ,0.67 + ,0.487 + ,0 + ,6587.24 + ,772 + ,0.473 + ,0.585 + ,0.297 + ,0 + ,105.63 + ,4.055 + ,0.79 + ,0.825 + ,0.535 + ,0 + ,4940.92 + ,6.576 + ,0.739 + ,0.71 + ,0.615 + ,0 + ,4975.59 + ,52.435 + ,0.741 + ,0.892 + ,0.916 + ,0 + ,3301.08 + ,11.977 + ,0.763 + ,0.899 + ,0.7 + ,0 + ,221.55 + ,4.03 + ,0.554 + ,0.805 + ,0.527 + ,0 + ,89571.13 + ,2.682 + ,0.503 + ,0.87 + ,0.478 + ,0 + ,23495.36 + ,2.243 + ,0.31 + ,0.718 + ,0.444 + ,0 + ,13460.31 + ,1.299 + ,0.48 + ,0.458 + ,0.362) + ,dim=c(6 + ,172) + ,dimnames=list(c('TotalPoints' + ,'POP' + ,'GDP/cap' + ,'Education' + ,'LifeExpectancy' + ,'GNI/cap') + ,1:172)) > y <- array(NA,dim=c(6,172),dimnames=list(c('TotalPoints','POP','GDP/cap','Education','LifeExpectancy','GNI/cap'),1:172)) > 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' > par4 <- 'no' > par3 <- '3' > par2 <- 'none' > par1 <- '1' > #'GNU S' R Code compiled by R2WASP v. 1.2.291 () > #Author: root > #To cite this work: Wessa P., 2012, Recursive Partitioning (Regression Trees) (v1.0.3) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_regression_trees.wasp/ > #Source of accompanying publication: > # > 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, 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) Hmisc library by Frank E Harrell Jr Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview') to see overall documentation. NOTE:Hmisc no longer redefines [.factor to drop unused levels when subsetting. To get the old behavior of Hmisc type dropUnusedLevels(). 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] "TotalPoints" > x[,par1] [1] 317 267 204 198 107 89 88 80 79 69 53 50 49 42 39 39 34 33 [19] 32 29 27 25 23 22 21 20 20 20 20 19 16 15 15 14 14 14 [37] 14 13 10 9 9 9 8 8 8 8 7 7 6 5 5 5 5 5 [55] 5 4 4 4 4 3 3 3 3 2 2 2 2 2 2 2 2 2 [73] 2 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 [91] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [109] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [127] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [145] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [163] 0 0 0 0 0 0 0 0 0 0 > 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]) 0 1 2 3 4 5 6 7 8 9 10 13 14 15 16 19 20 21 22 23 94 5 10 4 4 6 1 2 4 3 1 1 4 2 1 1 4 1 1 1 25 27 29 32 33 34 39 42 49 50 53 69 79 80 88 89 107 198 204 267 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 317 1 > colnames(x) [1] "TotalPoints" "POP" "GDP.cap" "Education" [5] "LifeExpectancy" "GNI.cap" > colnames(x)[par1] [1] "TotalPoints" > x[,par1] [1] 317 267 204 198 107 89 88 80 79 69 53 50 49 42 39 39 34 33 [19] 32 29 27 25 23 22 21 20 20 20 20 19 16 15 15 14 14 14 [37] 14 13 10 9 9 9 8 8 8 8 7 7 6 5 5 5 5 5 [55] 5 4 4 4 4 3 3 3 3 2 2 2 2 2 2 2 2 2 [73] 2 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 [91] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [109] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [127] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [145] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [163] 0 0 0 0 0 0 0 0 0 0 > if (par2 == 'none') { + m <- ctree(as.formula(paste(colnames(x)[par1],' ~ .',sep='')),data = x) + } > > #Note: the /var/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/1wkfp1355682546.tab") + } + } > m Conditional inference tree with 8 terminal nodes Response: TotalPoints Inputs: POP, GDP.cap, Education, LifeExpectancy, GNI.cap Number of observations: 172 1) POP <= 44205.29; criterion = 1, statistic = 40.262 2) Education <= 0.916; criterion = 1, statistic = 30.955 3) Education <= 0.763; criterion = 1, statistic = 18.472 4) POP <= 29671.6; criterion = 0.997, statistic = 11.989 5) Education <= 0.578; criterion = 0.955, statistic = 6.77 6)* weights = 50 5) Education > 0.578 7)* weights = 47 4) POP > 29671.6 8)* weights = 7 3) Education > 0.763 9) LifeExpectancy <= 0.858; criterion = 0.952, statistic = 6.676 10)* weights = 11 9) LifeExpectancy > 0.858 11)* weights = 21 2) Education > 0.916 12)* weights = 9 1) POP > 44205.29 13) GNI.cap <= 0.7; criterion = 0.975, statistic = 7.877 14)* weights = 18 13) GNI.cap > 0.7 15)* weights = 9 > postscript(file="/var/wessaorg/rcomp/tmp/2cygm1355682546.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/wessaorg/rcomp/tmp/3hb961355682546.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 317 132.333333 184.6666667 2 267 26.222222 240.7777778 3 204 132.333333 71.6666667 4 198 132.333333 65.6666667 5 107 132.333333 -25.3333333 6 89 132.333333 -43.3333333 7 88 132.333333 -44.3333333 8 80 132.333333 -52.3333333 9 79 30.777778 48.2222222 10 69 132.333333 -63.3333333 11 53 19.181818 33.8181818 12 50 30.777778 19.2222222 13 49 26.222222 22.7777778 14 42 19.181818 22.8181818 15 39 30.777778 8.2222222 16 39 132.333333 -93.3333333 17 34 26.222222 7.7777778 18 33 26.222222 6.7777778 19 32 19.181818 12.8181818 20 29 30.777778 -1.7777778 21 27 30.777778 -3.7777778 22 25 19.181818 5.8181818 23 23 7.000000 16.0000000 24 22 19.181818 2.8181818 25 21 30.777778 -9.7777778 26 20 1.787234 18.2127660 27 20 26.222222 -6.2222222 28 20 5.476190 14.5238095 29 20 26.222222 -6.2222222 30 19 5.476190 13.5238095 31 16 5.476190 10.5238095 32 15 7.000000 8.0000000 33 15 26.222222 -11.2222222 34 14 19.181818 -5.1818182 35 14 19.181818 -5.1818182 36 14 26.222222 -12.2222222 37 14 5.476190 8.5238095 38 13 30.777778 -17.7777778 39 10 30.777778 -20.7777778 40 9 5.476190 3.5238095 41 9 5.476190 3.5238095 42 9 30.777778 -21.7777778 43 8 26.222222 -18.2222222 44 8 1.787234 6.2127660 45 8 1.787234 6.2127660 46 8 1.787234 6.2127660 47 7 1.787234 5.2127660 48 7 1.787234 5.2127660 49 6 19.181818 -13.1818182 50 5 7.000000 -2.0000000 51 5 5.476190 -0.4761905 52 5 5.476190 -0.4761905 53 5 26.222222 -21.2222222 54 5 7.000000 -2.0000000 55 5 1.787234 3.2127660 56 4 1.787234 2.2127660 57 4 5.476190 -1.4761905 58 4 26.222222 -22.2222222 59 4 5.476190 -1.4761905 60 3 19.181818 -16.1818182 61 3 5.476190 -2.4761905 62 3 26.222222 -23.2222222 63 3 1.787234 1.2127660 64 2 1.787234 0.2127660 65 2 5.476190 -3.4761905 66 2 1.787234 0.2127660 67 2 5.476190 -3.4761905 68 2 0.060000 1.9400000 69 2 5.476190 -3.4761905 70 2 1.787234 0.2127660 71 2 1.787234 0.2127660 72 2 1.787234 0.2127660 73 2 1.787234 0.2127660 74 1 0.060000 0.9400000 75 1 5.476190 -4.4761905 76 1 7.000000 -6.0000000 77 1 1.787234 -0.7872340 78 1 1.787234 -0.7872340 79 0 1.787234 -1.7872340 80 0 0.060000 -0.0600000 81 0 1.787234 -1.7872340 82 0 5.476190 -5.4761905 83 0 26.222222 -26.2222222 84 0 1.787234 -1.7872340 85 0 0.060000 -0.0600000 86 0 0.060000 -0.0600000 87 0 1.787234 -1.7872340 88 0 1.787234 -1.7872340 89 0 0.060000 -0.0600000 90 0 0.060000 -0.0600000 91 0 0.060000 -0.0600000 92 0 0.060000 -0.0600000 93 0 0.060000 -0.0600000 94 0 0.060000 -0.0600000 95 0 0.060000 -0.0600000 96 0 5.476190 -5.4761905 97 0 0.060000 -0.0600000 98 0 0.060000 -0.0600000 99 0 1.787234 -1.7872340 100 0 0.060000 -0.0600000 101 0 0.060000 -0.0600000 102 0 1.787234 -1.7872340 103 0 26.222222 -26.2222222 104 0 1.787234 -1.7872340 105 0 1.787234 -1.7872340 106 0 0.060000 -0.0600000 107 0 0.060000 -0.0600000 108 0 19.181818 -19.1818182 109 0 0.060000 -0.0600000 110 0 0.060000 -0.0600000 111 0 0.060000 -0.0600000 112 0 0.060000 -0.0600000 113 0 1.787234 -1.7872340 114 0 0.060000 -0.0600000 115 0 0.060000 -0.0600000 116 0 5.476190 -5.4761905 117 0 0.060000 -0.0600000 118 0 5.476190 -5.4761905 119 0 1.787234 -1.7872340 120 0 1.787234 -1.7872340 121 0 1.787234 -1.7872340 122 0 0.060000 -0.0600000 123 0 1.787234 -1.7872340 124 0 0.060000 -0.0600000 125 0 0.060000 -0.0600000 126 0 1.787234 -1.7872340 127 0 5.476190 -5.4761905 128 0 0.060000 -0.0600000 129 0 0.060000 -0.0600000 130 0 0.060000 -0.0600000 131 0 0.060000 -0.0600000 132 0 5.476190 -5.4761905 133 0 0.060000 -0.0600000 134 0 1.787234 -1.7872340 135 0 1.787234 -1.7872340 136 0 0.060000 -0.0600000 137 0 1.787234 -1.7872340 138 0 0.060000 -0.0600000 139 0 0.060000 -0.0600000 140 0 0.060000 -0.0600000 141 0 26.222222 -26.2222222 142 0 26.222222 -26.2222222 143 0 1.787234 -1.7872340 144 0 0.060000 -0.0600000 145 0 1.787234 -1.7872340 146 0 1.787234 -1.7872340 147 0 26.222222 -26.2222222 148 0 0.060000 -0.0600000 149 0 0.060000 -0.0600000 150 0 1.787234 -1.7872340 151 0 1.787234 -1.7872340 152 0 0.060000 -0.0600000 153 0 1.787234 -1.7872340 154 0 0.060000 -0.0600000 155 0 0.060000 -0.0600000 156 0 1.787234 -1.7872340 157 0 1.787234 -1.7872340 158 0 1.787234 -1.7872340 159 0 7.000000 -7.0000000 160 0 0.060000 -0.0600000 161 0 0.060000 -0.0600000 162 0 7.000000 -7.0000000 163 0 0.060000 -0.0600000 164 0 0.060000 -0.0600000 165 0 19.181818 -19.1818182 166 0 1.787234 -1.7872340 167 0 1.787234 -1.7872340 168 0 1.787234 -1.7872340 169 0 0.060000 -0.0600000 170 0 26.222222 -26.2222222 171 0 0.060000 -0.0600000 172 0 0.060000 -0.0600000 > if (par2 != 'none') { + print(cbind(as.factor(x[,par1]),predict(m))) + myt <- table(as.factor(x[,par1]),predict(m)) + print(myt) + } > postscript(file="/var/wessaorg/rcomp/tmp/41won1355682546.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/wessaorg/rcomp/tmp/5xrz61355682547.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/wessaorg/rcomp/tmp/6bpnd1355682547.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/wessaorg/rcomp/tmp/7ytci1355682547.tab") + } > > try(system("convert tmp/2cygm1355682546.ps tmp/2cygm1355682546.png",intern=TRUE)) character(0) > try(system("convert tmp/3hb961355682546.ps tmp/3hb961355682546.png",intern=TRUE)) character(0) > try(system("convert tmp/41won1355682546.ps tmp/41won1355682546.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 5.372 0.417 5.787