Home » date » 2010 » Dec » 21 »

paper - 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, 21 Dec 2010 21:38:27 +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/21/t12929673801gw07krom1iz9iy.htm/, Retrieved Tue, 21 Dec 2010 22:36:24 +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/21/t12929673801gw07krom1iz9iy.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 «
631923 -12 -10.8 654294 -13 -12.2 671833 -16 -14.1 586840 -10 -15.2 600969 -4 -15.8 625568 -9 -15.8 558110 -8 -14.9 630577 -9 -12.6 628654 -3 -9.9 603184 -13 -7.8 656255 -3 -6 600730 -1 -5 670326 -2 -4.5 678423 0 -3.9 641502 0 -2.9 625311 -3 -1.5 628177 0 -0.5 589767 5 0 582471 3 0.5 636248 4 0.9 599885 3 0.8 621694 1 0.1 637406 -1 -1 596994 0 -2 696308 -2 -3 674201 -1 -3.7 648861 2 -4.7 649605 0 -6.4 672392 -6 -7.5 598396 -7 -7.8 613177 -6 -7.7 638104 -4 -6.6 615632 -9 -4.2 634465 -2 -2 638686 -3 -0.7 604243 2 0.1 706669 3 0.9 677185 1 2.1 644328 0 3.5 644825 1 4.9 605707 1 5.7 600136 3 6.2 612166 5 6.5 599659 5 6.5 634210 4 6.3 618234 11 6.2 613576 8 6.4 627200 -1 6.3 668973 4 5.8 651479 4 5.1 619661 4 5.1 644260 6 5.8 579936 6 6.7 601752 6 7.1 595376 6 6.7 588902 4 5.5 634341 1 4.2 594305 6 3 606200 0 2.2 610926 2 2 633685 -2 1.8 639696 0 1.8 659451 1 1.5 593248 -3 0.4 606677 -3 -0.9 599434 -5 -1.7 569578 -7 -2.6 629873 -7 -4.4 613438 -5 - 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 time6 seconds
R Server'Gwilym Jenkins' @ 72.249.127.135


Goodness of Fit
Correlation0.557
R-squared0.3102
RMSE34250.6269


Actuals, Predictions, and Residuals
#ActualsForecastsResiduals
1631923627585.3424657534337.65753424657
2654294627585.34246575326708.6575342466
3671833627585.34246575344247.6575342466
4586840627585.342465753-40745.3424657534
5600969627585.342465753-26616.3424657534
6625568627585.342465753-2017.34246575343
7558110627585.342465753-69475.3424657534
8630577627585.3424657532991.65753424657
9628654627585.3424657531068.65753424657
10603184627585.342465753-24401.3424657534
11656255627585.34246575328669.6575342466
12600730627585.342465753-26855.3424657534
13670326627585.34246575342740.6575342466
14678423627585.34246575350837.6575342466
15641502627585.34246575313916.6575342466
16625311627585.342465753-2274.34246575343
17628177627585.342465753591.657534246566
18589767627585.342465753-37818.3424657534
19582471627585.342465753-45114.3424657534
20636248627585.3424657538662.65753424657
21599885627585.342465753-27700.3424657534
22621694627585.342465753-5891.34246575343
23637406627585.3424657539820.65753424657
24596994627585.342465753-30591.3424657534
25696308627585.34246575368722.6575342466
26674201627585.34246575346615.6575342466
27648861627585.34246575321275.6575342466
28649605627585.34246575322019.6575342466
29672392627585.34246575344806.6575342466
30598396627585.342465753-29189.3424657534
31613177627585.342465753-14408.3424657534
32638104627585.34246575310518.6575342466
33615632627585.342465753-11953.3424657534
34634465627585.3424657536879.65753424657
35638686627585.34246575311100.6575342466
36604243627585.342465753-23342.3424657534
37706669627585.34246575379083.6575342466
38677185627585.34246575349599.6575342466
39644328627585.34246575316742.6575342466
40644825627585.34246575317239.6575342466
41605707627585.342465753-21878.3424657534
42600136627585.342465753-27449.3424657534
43612166627585.342465753-15419.3424657534
44599659627585.342465753-27926.3424657534
45634210627585.3424657536624.65753424657
46618234627585.342465753-9351.34246575343
47613576627585.342465753-14009.3424657534
48627200627585.342465753-385.342465753434
49668973627585.34246575341387.6575342466
50651479627585.34246575323893.6575342466
51619661627585.342465753-7924.34246575343
52644260627585.34246575316674.6575342466
53579936627585.342465753-47649.3424657534
54601752627585.342465753-25833.3424657534
55595376627585.342465753-32209.3424657534
56588902627585.342465753-38683.3424657534
57634341627585.3424657536755.65753424657
58594305627585.342465753-33280.3424657534
59606200627585.342465753-21385.3424657534
60610926627585.342465753-16659.3424657534
61633685627585.3424657536099.65753424657
62639696627585.34246575312110.6575342466
63659451627585.34246575331865.6575342466
64593248627585.342465753-34337.3424657534
65606677627585.342465753-20908.3424657534
66599434627585.342465753-28151.3424657534
67569578627585.342465753-58007.3424657534
68629873627585.3424657532287.65753424657
69613438627585.342465753-14147.3424657534
70604172627585.342465753-23413.3424657534
71658328695676.636363636-37348.6363636364
72612633695676.636363636-83043.6363636364
73707372695676.63636363611695.3636363636
74739770695676.63636363644093.3636363636
75777535695676.63636363681858.3636363636
76685030695676.636363636-10646.6363636364
77730234695676.63636363634557.3636363636
78714154695676.63636363618477.3636363636
79630872695676.636363636-64804.6363636364
80719492695676.63636363623815.3636363636
81677023695676.636363636-18653.6363636364
82679272627585.34246575351686.6575342466
83718317627585.34246575390731.6575342466
84645672627585.34246575318086.6575342466
 
Charts produced by software:
http://www.freestatistics.org/blog/date/2010/Dec/21/t12929673801gw07krom1iz9iy/27iad1292967501.png (open in new window)
http://www.freestatistics.org/blog/date/2010/Dec/21/t12929673801gw07krom1iz9iy/27iad1292967501.ps (open in new window)


http://www.freestatistics.org/blog/date/2010/Dec/21/t12929673801gw07krom1iz9iy/37iad1292967501.png (open in new window)
http://www.freestatistics.org/blog/date/2010/Dec/21/t12929673801gw07krom1iz9iy/37iad1292967501.ps (open in new window)


http://www.freestatistics.org/blog/date/2010/Dec/21/t12929673801gw07krom1iz9iy/4irrg1292967501.png (open in new window)
http://www.freestatistics.org/blog/date/2010/Dec/21/t12929673801gw07krom1iz9iy/4irrg1292967501.ps (open in new window)


 
Parameters (Session):
par1 = 1 ; par2 = none ; par3 = 3 ; par4 = no ;
 
Parameters (R input):
par1 = 1 ; par2 = none ; par3 = 3 ; 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