Home » date » 2010 » Dec » 14 »

Apple Inc - Recursive Partitioning

*The author of this computation has been verified*
R Software Module: /rwasp_regression_trees1.wasp (opens new window with default values)
Title produced by software: Recursive Partitioning (Regression Trees)
Date of computation: Tue, 14 Dec 2010 15:16:31 +0000
 
Cite this page as follows:
Statistical Computations at FreeStatistics.org, Office for Research Development and Education, URL http://www.freestatistics.org/blog/date/2010/Dec/14/t1292340508wje2o5qexifj85q.htm/, Retrieved Tue, 14 Dec 2010 16:28:29 +0100
 
BibTeX entries for LaTeX users:
@Manual{KEY,
    author = {{YOUR NAME}},
    publisher = {Office for Research Development and Education},
    title = {Statistical Computations at FreeStatistics.org, URL http://www.freestatistics.org/blog/date/2010/Dec/14/t1292340508wje2o5qexifj85q.htm/},
    year = {2010},
}
@Manual{R,
    title = {R: A Language and Environment for Statistical Computing},
    author = {{R Development Core Team}},
    organization = {R Foundation for Statistical Computing},
    address = {Vienna, Austria},
    year = {2010},
    note = {{ISBN} 3-900051-07-0},
    url = {http://www.R-project.org},
}
 
Original text written by user:
 
IsPrivate?
No (this computation is public)
 
User-defined keywords:
 
Dataseries X:
» Textbox « » Textfile « » CSV «
10.81 -0.2643 0 0 24563400 24.45 115.7 9.12 -0.2643 0 0 14163200 23.62 109.2 11.03 -0.2643 0 0 18184800 21.90 116.9 12.74 -0.1918 0 0 20810300 27.12 109.9 9.98 -0.1918 0 0 12843000 27.70 116.1 11.62 -0.1918 0 0 13866700 29.23 118.9 9.40 -0.2246 0 0 15119200 26.50 116.3 9.27 -0.2246 0 0 8301600 22.84 114.0 7.76 -0.2246 0 0 14039600 20.49 97.0 8.78 0.3654 0 0 12139700 23.28 85.3 10.65 0.3654 0 0 9649000 25.71 84.9 10.95 0.3654 0 0 8513600 26.52 94.6 12.36 0.0447 0 0 15278600 25.51 97.8 10.85 0.0447 0 0 15590900 23.36 95.0 11.84 0.0447 0 0 9691100 24.15 110.7 12.14 -0.0312 0 0 10882700 20.92 108.5 11.65 -0.0312 0 0 10294800 20.38 110.3 8.86 -0.0312 0 0 16031900 21.90 106.3 7.63 -0.0048 0 0 13683600 19.21 97.4 7.38 -0.0048 0 0 8677200 19.65 94.5 7.25 -0.0048 0 0 9874100 17.51 93.7 8.03 0.0705 0 0 10725500 21.41 79.6 7.75 0.0705 0 0 8348400 23.09 84.9 7.16 0.0705 0 0 8046200 20.70 80.7 7.18 -0.0134 0 0 10862300 19.00 78.8 7.51 -0.0134 0 0 8100300 19.04 64.8 7.07 etc...
 
Output produced by software:

Enter (or paste) a matrix (table) containing all data (time) series. Every column represents a different variable and must be delimited by a space or Tab. Every row represents a period in time (or category) and must be delimited by hard returns. The easiest way to enter data is to copy and paste a block of spreadsheet cells. Please, do not use commas or spaces to seperate groups of digits!


Summary of computational transaction
Raw Inputview raw input (R code)
Raw Outputview raw output of R engine
Computing time4 seconds
R Server'RServer@AstonUniversity' @ vre.aston.ac.uk


Goodness of Fit
Correlation0.9578
R-squared0.9174
RMSE21.741


Actuals, Predictions, and Residuals
#ActualsForecastsResiduals
110.8156.7588-45.9488
29.1210.1563157894737-1.03631578947368
311.0310.15631578947370.873684210526315
412.7410.15631578947372.58368421052632
59.9810.1563157894737-0.176315789473684
611.6210.15631578947371.46368421052632
79.410.1563157894737-0.756315789473684
89.2710.1563157894737-0.886315789473684
97.7610.1563157894737-2.39631578947368
108.7823.2811111111111-14.5011111111111
1110.6523.2811111111111-12.6311111111111
1210.9523.2811111111111-12.3311111111111
1312.3610.15631578947372.20368421052632
1410.8510.15631578947370.693684210526316
1511.8410.15631578947371.68368421052632
1612.1410.15631578947371.98368421052632
1711.6510.15631578947371.49368421052632
188.8610.1563157894737-1.29631578947368
197.6310.1563157894737-2.52631578947368
207.3810.1563157894737-2.77631578947368
217.2510.1563157894737-2.90631578947368
228.0310.1563157894737-2.12631578947368
237.7510.1563157894737-2.40631578947368
247.1610.1563157894737-2.99631578947368
257.1810.1563157894737-2.97631578947368
267.5110.1563157894737-2.64631578947368
277.0710.1563157894737-3.08631578947368
287.1110.1563157894737-3.04631578947368
298.9810.1563157894737-1.17631578947368
309.5310.1563157894737-0.626315789473685
3110.5410.15631578947370.383684210526315
3211.3110.15631578947371.15368421052632
3310.3610.15631578947370.203684210526315
3411.4410.15631578947371.28368421052632
3510.4510.15631578947370.293684210526315
3610.6910.15631578947370.533684210526316
3711.2810.15631578947371.12368421052632
3811.9610.15631578947371.80368421052632
3913.5210.15631578947373.36368421052632
4012.8910.15631578947372.73368421052632
4114.0310.15631578947373.87368421052632
4216.2710.15631578947376.11368421052632
4316.1723.2811111111111-7.11111111111111
4417.2523.2811111111111-6.03111111111111
4519.3823.2811111111111-3.90111111111111
4626.256.7588-30.5588
4733.5356.7588-23.2288
4832.256.7588-24.5588
4938.4556.7588-18.3088
5044.8656.7588-11.8988
5141.6756.7588-15.0888
5236.0656.7588-20.6988
5339.7656.7588-16.9988
5436.8123.281111111111113.5288888888889
5542.6523.281111111111119.3688888888889
5646.8923.281111111111123.6088888888889
5753.6156.7588-3.1488
5857.5956.75880.831200000000003
5967.8256.758811.0612
6071.8956.758815.1312
6175.5156.758818.7512
6268.4956.758811.7312
6362.7256.75885.9612
6470.3956.758813.6312
6559.7756.75883.0112
6657.2756.75880.511200000000002
6767.9656.758811.2012
6867.8556.758811.0912
6976.9856.758820.2212
7081.0856.758824.3212
7191.6656.758834.9012
7284.8456.758828.0812
7385.73116.526111111111-30.7961111111111
7484.61116.526111111111-31.9161111111111
7592.91116.526111111111-23.6161111111111
7699.8116.526111111111-16.7261111111111
77121.19116.5261111111114.66388888888889
78122.04116.5261111111115.5138888888889
79131.76150.437272727273-18.6772727272727
80138.48150.437272727273-11.9572727272727
81153.47150.4372727272733.03272727272727
82189.95150.43727272727339.5127272727273
83182.22150.43727272727331.7827272727273
84198.08218.733125-20.653125
85135.36150.437272727273-15.0772727272727
86125.02150.437272727273-25.4172727272727
87143.5150.437272727273-6.93727272727273
88173.95150.43727272727323.5127272727273
89188.75218.733125-29.983125
90167.44150.43727272727317.0027272727273
91158.95218.733125-59.783125
92169.53218.733125-49.203125
93113.66150.437272727273-36.7772727272727
94107.59116.526111111111-8.9361111111111
9592.67116.526111111111-23.8561111111111
9685.35116.526111111111-31.1761111111111
9790.13116.526111111111-26.3961111111111
9889.31116.526111111111-27.2161111111111
99105.12116.526111111111-11.4061111111111
100125.83116.5261111111119.30388888888889
101135.81116.52611111111119.2838888888889
102142.43116.52611111111125.9038888888889
103163.39116.52611111111146.8638888888889
104168.21116.52611111111151.6838888888889
105185.35116.52611111111168.8238888888889
106188.5218.733125-30.233125
107199.91218.733125-18.823125
108210.73218.733125-8.00312500000001
109192.06218.733125-26.673125
110204.62218.733125-14.113125
111235218.73312516.266875
112261.09218.73312542.356875
113256.88218.73312538.146875
114251.53218.73312532.796875
115257.25218.73312538.516875
116243.1218.73312524.366875
117283.75218.73312565.016875
 
Charts produced by software:
http://www.freestatistics.org/blog/date/2010/Dec/14/t1292340508wje2o5qexifj85q/2um431292339784.png (open in new window)
http://www.freestatistics.org/blog/date/2010/Dec/14/t1292340508wje2o5qexifj85q/2um431292339784.ps (open in new window)


http://www.freestatistics.org/blog/date/2010/Dec/14/t1292340508wje2o5qexifj85q/3um431292339784.png (open in new window)
http://www.freestatistics.org/blog/date/2010/Dec/14/t1292340508wje2o5qexifj85q/3um431292339784.ps (open in new window)


http://www.freestatistics.org/blog/date/2010/Dec/14/t1292340508wje2o5qexifj85q/45v3o1292339784.png (open in new window)
http://www.freestatistics.org/blog/date/2010/Dec/14/t1292340508wje2o5qexifj85q/45v3o1292339784.ps (open in new window)


 
Parameters (Session):
par1 = 1 ; par2 = none ; par4 = no ;
 
Parameters (R input):
par1 = 1 ; par2 = none ; par4 = no ;
 
R code (references can be found in the software module):
library(party)
library(Hmisc)
par1 <- as.numeric(par1)
par3 <- as.numeric(par3)
x <- data.frame(t(y))
is.data.frame(x)
x <- x[!is.na(x[,par1]),]
k <- length(x[1,])
n <- length(x[,1])
colnames(x)[par1]
x[,par1]
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])
colnames(x)
colnames(x)[par1]
x[,par1]
if (par2 == 'none') {
m <- ctree(as.formula(paste(colnames(x)[par1],' ~ .',sep='')),data = x)
}
load(file='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='mytable3.tab')
}
}
m
bitmap(file='test1.png')
plot(m)
dev.off()
bitmap(file='test1a.png')
plot(x[,par1] ~ as.factor(where(m)),main='Response by Terminal Node',xlab='Terminal Node',ylab='Response')
dev.off()
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)
}
bitmap(file='test2.png')
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()
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='mytable1.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='mytable.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='mytable2.tab')
}
 





Copyright

Creative Commons License

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.

Software written by Ed van Stee & Patrick Wessa


Disclaimer

Information provided on this web site is provided "AS IS" without warranty of any kind, either express or implied, including, without limitation, warranties of merchantability, fitness for a particular purpose, and noninfringement. We use reasonable efforts to include accurate and timely information and periodically update the information, and software without notice. However, we make no warranties or representations as to the accuracy or completeness of such information (or software), and we assume no liability or responsibility for errors or omissions in the content of this web site, or any software bugs in online applications. Your use of this web site is AT YOUR OWN RISK. Under no circumstances and under no legal theory shall we be liable to you or any other person for any direct, indirect, special, incidental, exemplary, or consequential damages arising from your access to, or use of, this web site.


Privacy Policy

We may request personal information to be submitted to our servers in order to be able to:

  • personalize online software applications according to your needs
  • enforce strict security rules with respect to the data that you upload (e.g. statistical data)
  • manage user sessions of online applications
  • alert you about important changes or upgrades in resources or applications

We NEVER allow other companies to directly offer registered users information about their products and services. Banner references and hyperlinks of third parties NEVER contain any personal data of the visitor.

We do NOT sell, nor transmit by any means, personal information, nor statistical data series uploaded by you to third parties.

We carefully protect your data from loss, misuse, alteration, and destruction. However, at any time, and under any circumstance you are solely responsible for managing your passwords, and keeping them secret.

We store a unique ANONYMOUS USER ID in the form of a small 'Cookie' on your computer. This allows us to track your progress when using this website which is necessary to create state-dependent features. The cookie is used for NO OTHER PURPOSE. At any time you may opt to disallow cookies from this website - this will not affect other features of this website.

We examine cookies that are used by third-parties (banner and online ads) very closely: abuse from third-parties automatically results in termination of the advertising contract without refund. We have very good reason to believe that the cookies that are produced by third parties (banner ads) do NOT cause any privacy or security risk.

FreeStatistics.org is safe. There is no need to download any software to use the applications and services contained in this website. Hence, your system's security is not compromised by their use, and your personal data - other than data you submit in the account application form, and the user-agent information that is transmitted by your browser - is never transmitted to our servers.

As a general rule, we do not log on-line behavior of individuals (other than normal logging of webserver 'hits'). However, in cases of abuse, hacking, unauthorized access, Denial of Service attacks, illegal copying, hotlinking, non-compliance with international webstandards (such as robots.txt), or any other harmful behavior, our system engineers are empowered to log, track, identify, publish, and ban misbehaving individuals - even if this leads to ban entire blocks of IP addresses, or disclosing user's identity.


FreeStatistics.org is powered by