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. 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(10.65 + ,NA + ,11.3447238275332 + ,34.00466 + ,0 + ,34 + ,10.65 + ,34.0202876898303 + ,34.00466 + ,152 + ,81.75 + ,12.985 + ,80.394008519981 + ,34.00466 + ,103 + ,106.5 + ,19.8615 + ,104.461728571947 + ,34.00466 + ,98 + ,0.525 + ,28.52535 + ,1.51024885747802 + ,34.00466 + ,24 + ,24.025 + ,25.725315 + ,24.3449175147126 + ,34.00466 + ,24 + ,5.25 + ,25.5552835 + ,6.10102813170674 + ,34.00466 + ,4 + ,9 + ,23.52475515 + ,9.74297366894733 + ,34.00466 + ,0 + ,12.8 + ,22.072279635 + ,13.4323962225627 + ,34.00466 + ,2 + ,25.05 + ,21.1450516715 + ,25.3271480416495 + ,34.00466 + ,2 + ,0.3 + ,21.53554650435 + ,1.29132499835047 + ,34.00466 + ,82 + ,75.75 + ,19.411991853915 + ,74.5430992988187 + ,34.00466 + ,70 + ,54.75 + ,25.0457926685235 + ,54.1692693680278 + ,34.00466 + ,76 + ,1.526 + ,28.0162134016712 + ,2.48213334115502 + ,34.00466 + ,51 + ,1.02 + ,25.3671920615040 + ,1.99046641401920 + ,34.00466 + ,NA + ,3.752 + ,22.9324728553536 + ,4.64256354643977 + ,34.00466 + ,0 + ,17.25 + ,21.0144255698183 + ,17.7434661387314 + ,34.00466 + ,9 + ,9.2 + ,20.6379830128364 + ,9.92884171115339 + ,34.00466 + ,12 + ,50.25 + ,19.4941847115528 + ,49.7607775635948 + ,34.00466 + ,2 + ,2.25 + ,22.5697662403975 + ,3.18356297838536 + ,34.00466 + ,51 + ,3.95 + ,20.5377896163578 + ,4.83254096458096 + ,34.00466 + ,55 + ,60 + ,18.879010654722 + ,59.2038839531516 + ,34.00466 + ,53 + ,55.8 + ,22.9911095892498 + ,55.1395593527327 + ,34.00466 + ,17 + ,6.75 + ,26.2719986303248 + ,7.55013353908689 + ,34.00466 + ,38 + ,61.95 + ,24.3197987672923 + ,61.1045586779287 + ,34.00466 + ,29 + ,7.025 + ,28.0828188905631 + ,7.817053763127 + ,34.00466 + ,32 + ,85.75 + ,25.9770370015068 + ,84.1965045872622 + ,34.00466 + ,78 + ,18.525 + ,31.9543333013561 + ,18.9797298623388 + ,34.00466 + ,26 + ,6 + ,30.6113999712205 + ,6.8227878984193 + ,34.00466 + ,117 + ,25.35 + ,28.1502599740985 + ,25.5966143213555 + ,34.00466 + ,29 + ,46.775 + ,27.8702339766886 + ,46.3822925793737 + ,34.00466 + ,5 + ,51.025 + ,29.7607105790198 + ,50.5102268038572 + ,34.00466 + ,45 + ,30 + ,31.8871395211178 + ,30.1128301008900 + ,34.00466 + ,13 + ,3 + ,31.698425569006 + ,3.91120762158714 + ,34.00466 + ,56 + ,30 + ,28.8285830121054 + ,30.1059458610932 + ,34.00466 + ,55 + ,44 + ,28.9457247108949 + ,43.6876743593134 + ,34.00466 + ,13 + ,80.75 + ,30.4511522398054 + ,79.3472312750332 + ,34.00466 + ,65 + ,27.5 + ,35.4810370158248 + ,27.6902669964837 + ,34.00466 + ,78 + ,39.725 + ,34.6829333142424 + ,39.5536267539573 + ,34.00466 + ,49 + ,29.25 + ,35.1871399828181 + ,29.3886144748858 + ,34.00466 + ,90 + ,32.725 + ,34.5934259845363 + ,32.7602726524212 + ,34.00466 + ,52 + ,56.25 + ,34.4065833860827 + ,55.591319459741 + ,34.00466 + ,28 + ,28.65 + ,36.5909250474744 + ,28.8093454557490 + ,34.00466 + ,82 + ,51.75 + ,35.796832542727 + ,51.2297172974473 + ,34.00466 + ,31 + ,32.26 + ,37.3921492884543 + ,32.3159796143125 + ,34.00466 + ,4 + ,72 + ,36.8789343596088 + ,70.8921850090827 + ,34.00466 + ,31 + ,65.4 + ,40.391040923648 + ,64.5012300391254 + ,34.00466 + ,84 + ,33.75 + ,42.8919368312832 + ,33.7767127288168 + ,34.00466 + ,56 + ,77.85 + ,41.9777431481549 + ,76.6044993211423 + ,34.00466 + ,54 + ,10.875 + ,45.5649688333394 + ,11.5642347595514 + ,34.00466 + ,84) + ,dim=c(5 + ,50) + ,dimnames=list(c('Actuals' + ,'Croston' + ,'ETS' + ,'Arima' + ,'Kaneka') + ,1:50)) > y <- array(NA,dim=c(5,50),dimnames=list(c('Actuals','Croston','ETS','Arima','Kaneka'),1:50)) > 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 = '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(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.7429401 0 1.0000000 1.0297414 0.17446995 2 0.1128618 1 0.2570599 0.2954922 0.05220124 3 0.0100000 2 0.1441981 0.1760371 0.05472036 > postscript(file="/var/www/html/freestat/rcomp/tmp/1zpcn1274871078.ps",horizontal=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/html/freestat/rcomp/tmp/2zpcn1274871078.ps",horizontal=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 10.650 6.17350 4.47650000 2 34.000 29.34357 4.65642857 3 81.750 65.46111 16.28888889 4 106.500 65.46111 41.03888889 5 0.525 6.17350 -5.64850000 6 24.025 29.34357 -5.31857143 7 5.250 6.17350 -0.92350000 8 9.000 6.17350 2.82650000 9 12.800 6.17350 6.62650000 10 25.050 29.34357 -4.29357143 11 0.300 6.17350 -5.87350000 12 75.750 65.46111 10.28888889 13 54.750 65.46111 -10.71111111 14 1.526 6.17350 -4.64750000 15 1.020 6.17350 -5.15350000 16 3.752 6.17350 -2.42150000 17 17.250 6.17350 11.07650000 18 9.200 6.17350 3.02650000 19 50.250 65.46111 -15.21111111 20 2.250 6.17350 -3.92350000 21 3.950 6.17350 -2.22350000 22 60.000 65.46111 -5.46111111 23 55.800 65.46111 -9.66111111 24 6.750 6.17350 0.57650000 25 61.950 65.46111 -3.51111111 26 7.025 6.17350 0.85150000 27 85.750 65.46111 20.28888889 28 18.525 29.34357 -10.81857143 29 6.000 6.17350 -0.17350000 30 25.350 29.34357 -3.99357143 31 46.775 65.46111 -18.68611111 32 51.025 65.46111 -14.43611111 33 30.000 29.34357 0.65642857 34 3.000 6.17350 -3.17350000 35 30.000 29.34357 0.65642857 36 44.000 65.46111 -21.46111111 37 80.750 65.46111 15.28888889 38 27.500 29.34357 -1.84357143 39 39.725 29.34357 10.38142857 40 29.250 29.34357 -0.09357143 41 32.725 29.34357 3.38142857 42 56.250 65.46111 -9.21111111 43 28.650 29.34357 -0.69357143 44 51.750 65.46111 -13.71111111 45 32.260 29.34357 2.91642857 46 72.000 65.46111 6.53888889 47 65.400 65.46111 -0.06111111 48 33.750 29.34357 4.40642857 49 77.850 65.46111 12.38888889 50 10.875 6.17350 4.70150000 > myr <- residuals(m) > myp <- predict(m) > postscript(file="/var/www/html/freestat/rcomp/tmp/3zpcn1274871078.ps",horizontal=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/html/freestat/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/freestat/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/html/freestat/rcomp/tmp/4qd281274871078.tab") > > try(system("convert tmp/1zpcn1274871078.ps tmp/1zpcn1274871078.png",intern=TRUE)) character(0) > try(system("convert tmp/2zpcn1274871078.ps tmp/2zpcn1274871078.png",intern=TRUE)) character(0) > try(system("convert tmp/3zpcn1274871078.ps tmp/3zpcn1274871078.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.504 0.707 1.677