Home » date » 2010 » Dec » 13 »

WS10 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: Mon, 13 Dec 2010 14:00:29 +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/13/t1292248752ivwnacdlz97mnii.htm/, Retrieved Mon, 13 Dec 2010 14:59:16 +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/13/t1292248752ivwnacdlz97mnii.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 24563400 -0,2643 24.45 2772.73 0,0373 115.7 5,98 9.12 14163200 -0,2643 23.62 2151.83 0,0353 109.2 5,49 11.03 18184800 -0,2643 21.90 1840.26 0,0292 116.9 5,31 12.74 20810300 -0,1918 27.12 2116.24 0,0327 109.9 4,8 9.98 12843000 -0,1918 27.70 2110.49 0,0362 116.1 4,21 11.62 13866700 -0,1918 29.23 2160.54 0,0325 118.9 3,97 9.40 15119200 -0,2246 26.50 2027.13 0,0272 116.3 3,77 9.27 8301600 -0,2246 22.84 1805.43 0,0272 114.0 3,65 7.76 14039600 -0,2246 20.49 1498.80 0,0265 97.0 3,07 8.78 12139700 0,3654 23.28 1690.20 0,0213 85.3 2,49 10.65 9649000 0,3654 25.71 1930.58 0,019 84.9 2,09 10.95 8513600 0,3654 26.52 1950.40 0,0155 94.6 1,82 12.36 15278600 0,0447 25.51 1934.03 0,0114 97.8 1,73 10.85 15590900 0,0447 23.36 1731.49 0,0114 95.0 1,74 11.84 9691100 0,0447 24.15 1845.35 0,0148 110.7 1,73 12.14 10882700 -0,0312 20.92 1688.23 0,0164 108.5 1,75 11.65 10294800 -0,0312 20.38 1615.73 0,0118 110.3 1,75 8.86 16031900 -0,0312 21.90 1463.21 0,0107 106.3 1,75 7.63 13683600 -0,0048 1 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 time13 seconds
R Server'George Udny Yule' @ 72.249.76.132


Goodness of Fit
Correlation0.935
R-squared0.8743
RMSE26.8206


Actuals, Predictions, and Residuals
#ActualsForecastsResiduals
110.8160.485-49.675
29.1211.3089285714286-2.18892857142857
311.0311.3089285714286-0.278928571428569
412.7411.30892857142861.43107142857143
59.9811.3089285714286-1.32892857142857
611.6211.30892857142860.311071428571431
79.411.3089285714286-1.90892857142857
89.2711.3089285714286-2.03892857142857
97.767.716666666666670.0433333333333321
108.7811.3089285714286-2.52892857142857
1110.6511.3089285714286-0.658928571428568
1210.9511.3089285714286-0.358928571428569
1312.3611.30892857142861.05107142857143
1410.8511.3089285714286-0.458928571428569
1511.8411.30892857142860.531071428571432
1612.1411.30892857142860.831071428571432
1711.6511.30892857142860.341071428571432
188.867.716666666666671.14333333333333
197.637.71666666666667-0.0866666666666678
207.387.71666666666667-0.336666666666668
217.257.71666666666667-0.466666666666668
228.037.716666666666670.313333333333332
237.757.716666666666670.0333333333333323
247.167.71666666666667-0.556666666666668
257.187.71666666666667-0.536666666666668
267.517.71666666666667-0.206666666666668
277.0798.131-91.061
287.117.71666666666667-0.606666666666667
298.987.716666666666671.26333333333333
309.5311.3089285714286-1.77892857142857
3110.5411.3089285714286-0.768928571428569
3211.3111.30892857142860.00107142857143216
3310.3611.3089285714286-0.948928571428569
3411.4411.30892857142860.131071428571431
3510.4511.3089285714286-0.858928571428569
3610.6911.3089285714286-0.618928571428569
3711.2811.3089285714286-0.0289285714285690
3811.9611.30892857142860.651071428571433
3913.5211.30892857142862.21107142857143
4012.8911.30892857142861.58107142857143
4114.0311.30892857142862.72107142857143
4216.2711.30892857142864.96107142857143
4316.1734.065-17.895
4417.2534.065-16.815
4519.3834.065-14.685
4626.260.485-34.285
4733.5360.485-26.955
4832.260.485-28.285
4938.4560.485-22.035
5044.8660.485-15.625
5141.6760.485-18.815
5236.0660.485-24.425
5339.7634.0655.69499999999999
5436.8134.0652.745
5542.6534.0658.585
5646.8934.06512.825
5753.6134.06519.545
5857.5960.485-2.89499999999999
5967.8260.4857.335
6071.8960.48511.405
6175.5160.48515.025
6268.4960.4858.005
6362.7260.4852.23500000000001
6470.3960.4859.905
6559.7760.485-0.714999999999989
6657.2760.485-3.21499999999999
6767.9660.4857.475
6867.8560.4857.365
6976.9860.48516.495
7081.0860.48520.595
7191.66134.148571428571-42.4885714285714
7284.84134.148571428571-49.3085714285714
7385.73134.148571428571-48.4185714285714
7484.6160.48524.125
7592.9160.48532.425
7699.8134.148571428571-34.3485714285714
77121.19134.148571428571-12.9585714285714
78122.04134.148571428571-12.1085714285714
79131.76134.148571428571-2.38857142857142
80138.48134.1485714285714.33142857142857
81153.47134.14857142857119.3214285714286
82189.95134.14857142857155.8014285714286
83182.22134.14857142857148.0714285714286
84198.08134.14857142857163.9314285714286
85135.36134.1485714285711.21142857142860
86125.0260.48564.535
87143.5134.1485714285719.35142857142858
88173.95203.507142857143-29.5571428571428
89188.75203.507142857143-14.7571428571428
90167.44203.507142857143-36.0671428571428
91158.95203.507142857143-44.5571428571428
92169.53203.507142857143-33.9771428571428
93113.66203.507142857143-89.8471428571428
94107.5998.1319.45899999999999
9592.6798.131-5.46100000000001
9685.3598.131-12.7810000000000
9790.1398.131-8.00100000000002
9889.3198.131-8.82100000000001
99105.1298.1316.98899999999999
100125.8398.13127.699
101135.8198.13137.679
102142.4398.13144.299
103163.39203.507142857143-40.1171428571429
104168.21203.507142857143-35.2971428571428
105185.35203.507142857143-18.1571428571428
106188.5203.507142857143-15.0071428571428
107199.91203.507142857143-3.59714285714284
108210.73203.5071428571437.22285714285715
109192.06203.507142857143-11.4471428571428
110204.62203.5071428571431.11285714285717
111235203.50714285714331.4928571428572
112261.09203.50714285714357.5828571428571
113256.88203.50714285714353.3728571428572
114251.53203.50714285714348.0228571428572
115257.25203.50714285714353.7428571428572
116243.1203.50714285714339.5928571428572
117283.75203.50714285714380.2428571428572
 
Charts produced by software:
http://www.freestatistics.org/blog/date/2010/Dec/13/t1292248752ivwnacdlz97mnii/2dn3n1292248814.png (open in new window)
http://www.freestatistics.org/blog/date/2010/Dec/13/t1292248752ivwnacdlz97mnii/2dn3n1292248814.ps (open in new window)


http://www.freestatistics.org/blog/date/2010/Dec/13/t1292248752ivwnacdlz97mnii/35e2p1292248814.png (open in new window)
http://www.freestatistics.org/blog/date/2010/Dec/13/t1292248752ivwnacdlz97mnii/35e2p1292248814.ps (open in new window)


http://www.freestatistics.org/blog/date/2010/Dec/13/t1292248752ivwnacdlz97mnii/4gn1s1292248814.png (open in new window)
http://www.freestatistics.org/blog/date/2010/Dec/13/t1292248752ivwnacdlz97mnii/4gn1s1292248814.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