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(5 + ,6 + ,5 + ,7 + ,11 + ,2 + ,2 + ,6 + ,2 + ,3 + ,11 + ,1 + ,6 + ,6 + ,6 + ,5 + ,15 + ,1 + ,6 + ,4 + ,4 + ,5 + ,9 + ,2 + ,6 + ,2 + ,6 + ,3 + ,11 + ,1 + ,5 + ,7 + ,3 + ,4 + ,17 + ,1 + ,5 + ,6 + ,5 + ,4 + ,16 + ,1 + ,6 + ,5 + ,3 + ,5 + ,9 + ,1 + ,6 + ,6 + ,5 + ,5 + ,14 + ,1 + ,5 + ,7 + ,4 + ,5 + ,12 + ,1 + ,5 + ,7 + ,1 + ,6 + ,6 + ,2 + ,5 + ,4 + ,6 + ,5 + ,4 + ,1 + ,6 + ,1 + ,6 + ,2 + ,13 + ,1 + ,5 + ,6 + ,6 + ,5 + ,12 + ,1 + ,5 + ,4 + ,4 + ,4 + ,10 + ,1 + ,6 + ,5 + ,6 + ,6 + ,14 + ,2 + ,6 + ,5 + ,5 + ,5 + ,12 + ,1 + ,4 + ,6 + ,3 + ,6 + ,9 + ,1 + ,5 + ,4 + ,5 + ,5 + ,16 + ,2 + ,5 + ,6 + ,4 + ,2 + ,13 + ,2 + ,5 + ,3 + ,5 + ,3 + ,12 + ,1 + ,6 + ,3 + ,6 + ,5 + ,11 + ,1 + ,5 + ,5 + ,3 + ,6 + ,12 + ,2 + ,7 + ,5 + ,4 + ,5 + ,12 + ,2 + ,6 + ,5 + ,5 + ,4 + ,11 + ,1 + ,6 + ,5 + ,4 + ,5 + ,16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,6 + ,3 + ,6 + ,13 + ,1 + ,5 + ,6 + ,4 + ,5 + ,10 + ,1 + ,3 + ,2 + ,2 + ,4 + ,9 + ,2 + ,6 + ,5 + ,4 + ,5 + ,8 + ,2 + ,5 + ,6 + ,4 + ,5 + ,15 + ,2 + ,5 + ,5 + ,3 + ,5 + ,15 + ,1 + ,5 + ,3 + ,2 + ,5 + ,12 + ,1 + ,2 + ,7 + ,5 + ,6 + ,8 + ,2 + ,5 + ,5 + ,5 + ,2 + ,15 + ,1 + ,5 + ,4 + ,4 + ,4 + ,9 + ,1 + ,6 + ,5 + ,6 + ,7 + ,14 + ,2 + ,6 + ,3 + ,5 + ,3 + ,16 + ,1 + ,5 + ,2 + ,1 + ,2 + ,14 + ,1 + ,5 + ,5 + ,5 + ,5 + ,14 + ,2 + ,5 + ,5 + ,5 + ,3 + ,14 + ,1 + ,6 + ,2 + ,5 + ,5 + ,14 + ,1 + ,6 + ,3 + ,5 + ,6 + ,14 + ,2 + ,6 + ,2 + ,5 + ,3 + ,13 + ,2 + ,6 + ,6 + ,4 + ,5 + ,12 + ,1 + ,6 + ,6 + ,7 + ,5 + ,13 + ,2 + ,7 + ,2 + ,5 + ,3 + ,19 + ,1 + ,5 + ,2 + ,4 + ,5 + ,9 + ,2) + ,dim=c(6 + ,150) + ,dimnames=list(c('handgebruik' + ,'stilheid' + ,'extravert' + ,'blozen' + ,'populariteit' + ,'geslacht') + ,1:150)) > y <- array(NA,dim=c(6,150),dimnames=list(c('handgebruik','stilheid','extravert','blozen','populariteit','geslacht'),1:150)) > for (i in 1:dim(x)[1]) + { + for (j in 1:dim(x)[2]) + { + y[i,j] <- as.numeric(x[i,j]) + } + } > par2 = 'No' > par1 = '5' > #'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(rpart) > library(partykit) Loading required package: grid Loading required package: mvtnorm > par1 <- as.numeric(par1) > autoprune <- function ( tree, method='Minimum CV'){ + xerr <- tree$cptable[,'xerror'] + cpmin.id <- which.min(xerr) + if (method == 'Minimum CV Error plus 1 SD'){ + xstd <- tree$cptable[,'xstd'] + errt <- xerr[cpmin.id] + xstd[cpmin.id] + cpSE1.min <- which.min( errt < xerr ) + mycp <- (tree$cptable[,'CP'])[cpSE1.min] + } + if (method == 'Minimum CV') { + mycp <- (tree$cptable[,'CP'])[cpmin.id] + } + return (mycp) + } > conf.multi.mat <- function(true, new) + { + if ( all( is.na(match( levels(true),levels(new) ) )) ) + stop ( 'conflict of vector levels') + multi.t <- list() + for (mylev in levels(true) ) { + true.tmp <- true + new.tmp <- new + left.lev <- levels (true.tmp)[- match(mylev,levels(true) ) ] + levels(true.tmp) <- list ( mylev = mylev, all = left.lev ) + levels(new.tmp) <- list ( mylev = mylev, all = left.lev ) + curr.t <- conf.mat ( true.tmp , new.tmp ) + multi.t[[mylev]] <- curr.t + multi.t[[mylev]]$precision <- + round( curr.t$conf[1,1] / sum( curr.t$conf[1,] ), 2 ) + } + return (multi.t) + } > x <- t(y) > k <- length(x[1,]) > n <- length(x[,1]) > x1 <- cbind(x[,par1], x[,1:k!=par1]) > mycolnames <- c(colnames(x)[par1], colnames(x)[1:k!=par1]) > colnames(x1) <- mycolnames #colnames(x)[par1] > m <- rpart(as.data.frame(x1)) > par2 [1] "No" > if (par2 != 'No') { + mincp <- autoprune(m,method=par2) + print(mincp) + m <- prune(m,cp=mincp) + } > m$cptable CP nsplit rel error xerror xstd 1 0.06027186 0 1.0000000 1.012652 0.1107963 2 0.05046594 1 0.9397281 1.116667 0.1202835 3 0.04667911 2 0.8892622 1.080503 0.1242376 4 0.03070030 3 0.8425831 1.049344 0.1184911 5 0.02086905 4 0.8118828 1.012724 0.1129385 6 0.01918232 5 0.7910137 1.029705 0.1150191 7 0.01701167 6 0.7718314 1.052715 0.1157744 8 0.01228371 7 0.7548198 1.067737 0.1183137 9 0.01199485 9 0.7302523 1.076388 0.1193758 10 0.01072716 10 0.7182575 1.076388 0.1193758 11 0.01000000 11 0.7075303 1.071183 0.1155720 > postscript(file="/var/www/rcomp/tmp/1i9271292962824.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(as.party(m),tp_args=list(id=FALSE)) > dev.off() null device 1 > postscript(file="/var/www/rcomp/tmp/2tija1292962824.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plotcp(m) > dev.off() null device 1 > cbind(y=m$y,pred=predict(m),res=residuals(m)) y pred res 1 11 12.761905 -1.76190476 2 11 13.888889 -2.88888889 3 15 11.789474 3.21052632 4 9 12.761905 -3.76190476 5 11 10.142857 0.85714286 6 17 12.571429 4.42857143 7 16 13.250000 2.75000000 8 9 10.888889 -1.88888889 9 14 13.250000 0.75000000 10 12 12.571429 -0.57142857 11 6 8.285714 -2.28571429 12 4 11.789474 -7.78947368 13 13 10.142857 2.85714286 14 12 11.789474 0.21052632 15 10 12.571429 -2.57142857 16 14 12.761905 1.23809524 17 12 13.250000 -1.25000000 18 9 12.571429 -3.57142857 19 16 12.761905 3.23809524 20 13 12.761905 0.23809524 21 12 14.642857 -2.64285714 22 11 11.789474 -0.78947368 23 12 10.777778 1.22222222 24 12 12.761905 -0.76190476 25 11 13.250000 -2.25000000 26 16 12.761905 3.23809524 27 9 13.250000 -4.25000000 28 8 11.818182 -3.81818182 29 11 11.789474 -0.78947368 30 9 8.285714 0.71428571 31 16 11.818182 4.18181818 32 14 11.789474 2.21052632 33 10 12.761905 -2.76190476 34 14 13.250000 0.75000000 35 13 8.285714 4.71428571 36 12 10.142857 1.85714286 37 16 12.761905 3.23809524 38 16 10.888889 5.11111111 39 15 14.642857 0.35714286 40 5 8.285714 -3.28571429 41 12 10.777778 1.22222222 42 11 13.888889 -2.88888889 43 15 13.250000 1.75000000 44 15 11.818182 3.18181818 45 10 9.928571 0.07142857 46 12 10.888889 1.11111111 47 5 10.142857 -5.14285714 48 16 13.888889 2.11111111 49 16 13.250000 2.75000000 50 12 12.761905 -0.76190476 51 6 8.285714 -2.28571429 52 7 9.928571 -2.92857143 53 14 11.818182 2.18181818 54 8 11.818182 -3.81818182 55 12 12.571429 -0.57142857 56 10 11.818182 -1.81818182 57 11 12.761905 -1.76190476 58 17 12.571429 4.42857143 59 13 11.789474 1.21052632 60 15 13.250000 1.75000000 61 10 11.789474 -1.78947368 62 9 12.761905 -3.76190476 63 16 14.642857 1.35714286 64 11 11.818182 -0.81818182 65 8 9.928571 -1.92857143 66 14 12.761905 1.23809524 67 11 10.777778 0.22222222 68 12 10.888889 1.11111111 69 14 9.928571 4.07142857 70 15 14.642857 0.35714286 71 14 9.928571 4.07142857 72 11 9.928571 1.07142857 73 11 9.928571 1.07142857 74 15 13.888889 1.11111111 75 7 11.818182 -4.81818182 76 12 12.761905 -0.76190476 77 10 11.789474 -1.78947368 78 13 10.777778 2.22222222 79 15 12.761905 2.23809524 80 13 12.571429 0.42857143 81 15 13.888889 1.11111111 82 8 9.928571 -1.92857143 83 14 13.250000 0.75000000 84 11 8.285714 2.71428571 85 12 10.777778 1.22222222 86 16 13.250000 2.75000000 87 8 9.928571 -1.92857143 88 12 13.250000 -1.25000000 89 16 11.789474 4.21052632 90 11 10.777778 0.22222222 91 13 12.571429 0.42857143 92 6 10.888889 -4.88888889 93 4 10.777778 -6.77777778 94 11 10.888889 0.11111111 95 7 9.928571 -2.92857143 96 12 10.777778 1.22222222 97 12 10.142857 1.85714286 98 16 14.642857 1.35714286 99 15 13.250000 1.75000000 100 13 14.642857 -1.64285714 101 12 13.250000 -1.25000000 102 9 13.250000 -4.25000000 103 16 14.642857 1.35714286 104 11 10.888889 0.11111111 105 14 11.818182 2.18181818 106 10 10.777778 -0.77777778 107 10 11.789474 -1.78947368 108 11 11.789474 -0.78947368 109 16 13.888889 2.11111111 110 8 11.789474 -3.78947368 111 16 14.642857 1.35714286 112 12 11.789474 0.21052632 113 11 11.789474 -0.78947368 114 16 11.789474 4.21052632 115 9 10.888889 -1.88888889 116 13 9.928571 3.07142857 117 14 11.789474 2.21052632 118 10 10.142857 -0.14285714 119 12 13.888889 -1.88888889 120 11 14.642857 -3.64285714 121 10 9.928571 0.07142857 122 12 13.250000 -1.25000000 123 13 12.571429 0.42857143 124 14 12.761905 1.23809524 125 12 11.789474 0.21052632 126 14 11.789474 2.21052632 127 13 12.571429 0.42857143 128 8 10.142857 -2.14285714 129 13 12.571429 0.42857143 130 10 12.571429 -2.57142857 131 9 9.928571 -0.92857143 132 8 12.761905 -4.76190476 133 15 12.761905 2.23809524 134 15 12.571429 2.42857143 135 12 14.642857 -2.64285714 136 8 8.285714 -0.28571429 137 15 13.888889 1.11111111 138 9 12.571429 -3.57142857 139 14 12.761905 1.23809524 140 16 14.642857 1.35714286 141 14 14.642857 -0.64285714 142 14 12.761905 1.23809524 143 14 13.888889 0.11111111 144 14 14.642857 -0.64285714 145 14 11.818182 2.18181818 146 13 11.818182 1.18181818 147 12 10.888889 1.11111111 148 13 12.761905 0.23809524 149 19 14.642857 4.35714286 150 9 9.928571 -0.92857143 > myr <- residuals(m) > myp <- predict(m) > postscript(file="/var/www/rcomp/tmp/3tija1292962824.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > op <- par(mfrow=c(2,2)) > plot(myr,ylab='residuals') > plot(density(myr),main='Residual Kernel Density') > plot(myp,myr,xlab='predicted',ylab='residuals',main='Predicted vs Residuals') > plot(density(myp),main='Prediction Kernel Density') > par(op) > dev.off() null device 1 > > #Note: the /var/www/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/rcomp/createtable") > > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Model Performance',6,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'#',header=TRUE) > a<-table.element(a,'Complexity',header=TRUE) > a<-table.element(a,'split',header=TRUE) > a<-table.element(a,'relative error',header=TRUE) > a<-table.element(a,'CV error',header=TRUE) > a<-table.element(a,'CV S.D.',header=TRUE) > a<-table.row.end(a) > for (i in 1:length(m$cptable[,1])) { + a<-table.row.start(a) + a<-table.element(a,i,header=TRUE) + a<-table.element(a,round(m$cptable[i,'CP'],3)) + a<-table.element(a,m$cptable[i,'nsplit']) + a<-table.element(a,round(m$cptable[i,'rel error'],3)) + a<-table.element(a,round(m$cptable[i,'xerror'],3)) + a<-table.element(a,round(m$cptable[i,'xstd'],3)) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/www/rcomp/tmp/47azi1292962824.tab") > > try(system("convert tmp/1i9271292962824.ps tmp/1i9271292962824.png",intern=TRUE)) character(0) > try(system("convert tmp/2tija1292962824.ps tmp/2tija1292962824.png",intern=TRUE)) character(0) > try(system("convert tmp/3tija1292962824.ps tmp/3tija1292962824.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.930 0.530 2.517