Home » date » 2010 » Dec » 21 »

*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 15:30:20 +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/t1292945279hl7gwg07b28jwcz.htm/, Retrieved Tue, 21 Dec 2010 16:27:59 +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/t1292945279hl7gwg07b28jwcz.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 «
4,031636 0,5215052 9,166456 1,303763 3,702076 0,4248284 7,970589 1,416094 3,056176 0,4250311 7,104091 1,052458 3,280707 0,4771938 6,621064 1,312283 2,984728 0,8280212 7,529215 1,309429 3,693712 0,6156186 8,170938 1,492409 3,226317 0,366627 8,15745 1,026556 2,190349 0,4308883 7,378962 1,005406 2,599515 0,2810287 7,921496 1,334886 3,080288 0,4646245 8,15674 1,393873 2,929672 0,2693951 8,856365 1,128092 2,922548 0,5779049 8,817177 1,122787 3,234943 0,5661151 8,734347 1,213104 2,983081 0,5077584 9,345927 1,253528 3,284389 0,7507175 8,99297 1,094796 3,806511 0,6808395 10,78512 0,9129438 3,784579 0,7661091 8,886867 1,19513 2,645654 0,4561473 8,818847 0,9274994 3,092081 0,4977496 8,823744 0,9653326 3,204859 0,4193273 9,165298 1,198078 3,107225 0,6095514 8,652657 0,966362 3,466909 0,457337 8,173054 0,9736851 2,984404 0,5705478 7,563416 0,9948013 3,218072 0,3478996 7,595809 0,8262616 2,82731 0,3874993 8,381467 0,6888877 3,182049 0,5824285 7,216432 0,7813066 2,236319 0,2391033 6,540178 0,60479 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 time5 seconds
R Server'Sir Ronald Aylmer Fisher' @ 193.190.124.24


Goodness of Fit
Correlation0.7435
R-squared0.5528
RMSE0.4527


Actuals, Predictions, and Residuals
#ActualsForecastsResiduals
14.0316363.160133981132080.871502018867924
23.7020762.660549761904761.04152623809524
33.0561762.660549761904760.395626238095238
43.2807073.160133981132080.120573018867924
52.9847283.16013398113208-0.175405981132076
63.6937123.160133981132080.533578018867924
73.2263172.660549761904760.565767238095238
82.1903492.66054976190476-0.470200761904762
92.5995151.815103018750.78441198125
103.0802883.16013398113208-0.0798459811320757
112.9296721.815103018751.11456898125
122.9225483.16013398113208-0.237585981132076
133.2349433.160133981132080.0748090188679242
142.9830813.16013398113208-0.177052981132076
153.2843893.160133981132080.124255018867924
163.8065113.160133981132080.646377018867924
173.7845793.160133981132080.624445018867924
182.6456542.66054976190476-0.0148957619047621
193.0920813.16013398113208-0.0680529811320758
203.2048592.660549761904760.544309238095238
213.1072253.16013398113208-0.0529089811320755
223.4669093.160133981132080.306775018867924
232.9844043.16013398113208-0.175729981132076
243.2180722.660549761904760.557522238095238
252.827312.660549761904760.166760238095238
263.1820493.160133981132080.0219150188679245
272.2363191.815103018750.42121598125
282.0332181.815103018750.21811498125
291.6448041.81510301875-0.170299018750000
301.6279712.66054976190476-1.03257876190476
311.6775592.66054976190476-0.982990761904762
322.3308282.66054976190476-0.329721761904762
332.4936152.66054976190476-0.166934761904762
342.2571722.66054976190476-0.403377761904762
352.6555171.815103018750.84041398125
362.2986551.815103018750.48355198125
372.6004022.66054976190476-0.0601477619047621
383.045233.16013398113208-0.114903981132076
392.7905832.660549761904760.130033238095238
403.2270522.660549761904760.566502238095238
412.9674792.660549761904760.306929238095238
422.9388172.660549761904760.278267238095238
433.2779613.160133981132080.117827018867924
443.4239853.160133981132080.263851018867924
453.0726463.16013398113208-0.0874879811320755
462.7542533.16013398113208-0.405880981132076
472.9104313.16013398113208-0.249702981132076
483.1743693.160133981132080.0142350188679243
493.0683873.16013398113208-0.0917469811320757
503.0895433.16013398113208-0.0705909811320757
512.9066543.16013398113208-0.253479981132076
522.9311613.16013398113208-0.228972981132076
533.025663.16013398113208-0.134473981132076
542.9395513.16013398113208-0.220582981132076
552.6910192.660549761904760.0304692380952378
563.198123.160133981132080.0379860188679242
573.076393.16013398113208-0.0837439811320757
582.8638733.16013398113208-0.296260981132076
593.0138023.16013398113208-0.146331981132076
603.0533643.16013398113208-0.106769981132075
612.8647533.16013398113208-0.295380981132076
623.0570623.16013398113208-0.103071981132075
632.9593653.16013398113208-0.200768981132076
643.2522583.160133981132080.0921240188679242
653.6029883.160133981132080.442854018867924
663.4977043.160133981132080.337570018867924
673.2968673.160133981132080.136733018867925
683.6024173.160133981132080.442283018867924
693.30013.160133981132080.139966018867924
703.401933.160133981132080.241796018867924
713.5025913.160133981132080.342457018867924
723.4023483.160133981132080.242214018867924
733.4985513.160133981132080.338417018867924
743.1998233.160133981132080.0396890188679242
752.7000643.16013398113208-0.460069981132076
762.8010343.16013398113208-0.359099981132076
772.8986283.16013398113208-0.261505981132076
782.8008543.16013398113208-0.359279981132075
792.3999422.66054976190476-0.260607761904762
802.4027241.815103018750.58762098125
812.2023311.815103018750.38722798125
822.1025943.16013398113208-1.05753998113208
831.7982932.66054976190476-0.862256761904762
841.2024841.81510301875-0.61261901875
851.4002011.81510301875-0.41490201875
861.2008321.81510301875-0.61427101875
871.2980831.81510301875-0.51702001875
881.0997421.81510301875-0.71536101875
891.0013771.81510301875-0.81372601875
900.83617431.81510301875-0.97892871875
 
Charts produced by software:
http://www.freestatistics.org/blog/date/2010/Dec/21/t1292945279hl7gwg07b28jwcz/21acz1292945412.png (open in new window)
http://www.freestatistics.org/blog/date/2010/Dec/21/t1292945279hl7gwg07b28jwcz/21acz1292945412.ps (open in new window)


http://www.freestatistics.org/blog/date/2010/Dec/21/t1292945279hl7gwg07b28jwcz/31acz1292945412.png (open in new window)
http://www.freestatistics.org/blog/date/2010/Dec/21/t1292945279hl7gwg07b28jwcz/31acz1292945412.ps (open in new window)


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


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