x <- array(list(252101
,62
,34
,104
,124252
,134577
,59
,30
,111
,98956
,198520
,62
,38
,93
,98073
,189326
,94
,34
,119
,106816
,137449
,43
,25
,57
,41449
,65295
,27
,31
,80
,76173
,439387
,103
,29
,107
,177551
,33186
,19
,18
,22
,22807
,178368
,51
,30
,103
,126938
,186657
,38
,29
,72
,61680
,261949
,96
,38
,123
,72117
,191051
,95
,49
,164
,79738
,138866
,57
,33
,100
,57793
,296878
,66
,46
,143
,91677
,192648
,72
,38
,79
,64631
,333462
,162
,52
,183
,106385
,243571
,58
,32
,123
,161961
,263451
,130
,35
,81
,112669
,155679
,48
,25
,74
,114029
,227053
,70
,42
,158
,124550
,240028
,63
,40
,133
,105416
,388549
,90
,35
,128
,72875
,156540
,34
,25
,84
,81964
,148421
,43
,46
,184
,104880
,177732
,97
,36
,127
,76302
,191441
,105
,35
,128
,96740
,249893
,122
,38
,118
,93071
,236812
,76
,35
,125
,78912
,142329
,45
,28
,89
,35224
,259667
,53
,37
,122
,90694
,231625
,65
,40
,151
,125369
,176062
,67
,42
,122
,80849
,286683
,79
,44
,162
,104434
,87485
,33
,33
,121
,65702
,322865
,83
,35
,132
,108179
,247082
,51
,37
,110
,63583
,346011
,106
,39
,135
,95066
,191653
,74
,32
,80
,62486
,114673
,31
,17
,46
,31081
,284224
,161
,34
,127
,94584
,284195
,72
,33
,103
,87408
,155363
,59
,35
,95
,68966
,177306
,67
,32
,100
,88766
,144571
,49
,35
,102
,57139
,140319
,73
,45
,45
,90586
,405267
,135
,38
,122
,109249
,78800
,42
,26
,66
,33032
,201970
,69
,45
,159
,96056
,302674
,99
,44
,153
,146648
,164733
,50
,40
,131
,80613
,194221
,68
,33
,113
,87026
,24188
,24
,4
,7
,5950
,342263
,279
,41
,147
,131106
,65029
,17
,18
,61
,32551
,101097
,64
,14
,41
,31701
,246088
,46
,33
,108
,91072
,273108
,75
,49
,184
,159803
,282220
,160
,32
,115
,143950
,273495
,119
,37
,132
,112368
,214872
,74
,32
,113
,82124
,335121
,124
,41
,141
,144068
,267171
,107
,25
,65
,162627
,187938
,88
,40
,87
,55062
,229512
,78
,35
,121
,95329
,209798
,61
,33
,112
,105612
,201345
,60
,28
,81
,62853
,163833
,114
,31
,116
,125976
,204250
,129
,40
,132
,79146
,197813
,67
,32
,104
,108461
,132955
,60
,25
,80
,99971
,216092
,59
,42
,145
,77826
,73566
,32
,23
,67
,22618
,213198
,67
,42
,159
,84892
,181713
,49
,38
,90
,92059
,148698
,49
,34
,120
,77993
,300103
,70
,38
,126
,104155
,251437
,78
,32
,118
,109840
,197295
,101
,37
,112
,238712
,158163
,55
,34
,123
,67486
,155529
,57
,33
,98
,68007
,132672
,41
,25
,78
,48194
,377205
,100
,40
,119
,134796
,145905
,66
,26
,99
,38692
,223701
,87
,40
,81
,93587
,80953
,25
,8
,27
,56622
,130805
,47
,27
,77
,15986
,135082
,48
,32
,118
,113402
,300805
,156
,33
,122
,97967
,271806
,95
,50
,103
,74844
,150949
,96
,37
,129
,136051
,225805
,79
,33
,69
,50548
,197389
,68
,34
,121
,112215
,156583
,56
,28
,81
,59591
,222599
,66
,32
,119
,59938
,261601
,70
,32
,116
,137639
,178489
,35
,32
,123
,143372
,200657
,43
,31
,111
,138599
,259084
,68
,35
,100
,174110
,313075
,130
,58
,221
,135062
,346933
,100
,27
,95
,175681
,246440
,104
,45
,153
,130307
,252444
,58
,37
,118
,139141
,159965
,159
,32
,50
,44244
,43287
,14
,19
,64
,43750
,172239
,68
,22
,34
,48029
,183738
,120
,35
,76
,95216
,227681
,43
,36
,112
,92288
,260464
,81
,36
,115
,94588
,106288
,54
,23
,69
,197426
,109632
,77
,36
,108
,151244
,268905
,58
,36
,130
,139206
,266805
,78
,42
,110
,106271
,23623
,11
,1
,0
,1168
,152474
,65
,32
,83
,71764
,61857
,25
,11
,30
,25162
,144889
,43
,40
,106
,45635
,346600
,99
,34
,91
,101817
,21054
,16
,0
,0
,855
,224051
,45
,27
,69
,100174
,31414
,19
,8
,9
,14116
,261043
,105
,35
,123
,85008
,197819
,57
,41
,143
,124254
,154984
,73
,40
,125
,105793
,112933
,45
,28
,81
,117129
,38214
,34
,8
,21
,8773
,158671
,33
,35
,124
,94747
,302148
,70
,47
,168
,107549
,177918
,55
,46
,149
,97392
,350552
,70
,42
,147
,126893
,275578
,91
,48
,145
,118850
,368746
,106
,49
,172
,234853
,172464
,31
,35
,126
,74783
,94381
,35
,32
,89
,66089
,243875
,279
,36
,137
,95684
,382487
,153
,42
,149
,139537
,114525
,40
,35
,121
,144253
,335681
,119
,37
,133
,153824
,147989
,72
,34
,93
,63995
,216638
,45
,36
,119
,84891
,192862
,72
,36
,102
,61263
,184818
,107
,32
,45
,106221
,336707
,105
,33
,104
,113587
,215836
,76
,35
,111
,113864
,173260
,63
,21
,78
,37238
,271773
,89
,40
,120
,119906
,130908
,52
,49
,176
,135096
,204009
,75
,33
,109
,151611
,245514
,92
,39
,132
,144645
,1
,0
,0
,0
,0
,14688
,10
,0
,0
,6023
,98
,1
,0
,0
,0
,455
,2
,0
,0
,0
,0
,0
,0
,0
,0
,0
,0
,0
,0
,0
,195765
,75
,33
,78
,77457
,326038
,121
,42
,104
,62464
,0
,0
,0
,0
,0
,203
,4
,0
,0
,0
,7199
,5
,0
,0
,1644
,46660
,20
,5
,13
,6179
,17547
,5
,1
,4
,3926
,107465
,38
,38
,65
,42087
,969
,2
,0
,0
,0
,173102
,58
,28
,55
,87656)
,dim=c(5
,164)
,dimnames=list(c('TimeinRFC'
,'#logins'
,'#FBmess'
,'#revCom'
,'#char')
,1:164))
 y <- array(NA,dim=c(5,164),dimnames=list(c('TimeinRFC','#logins','#FBmess','#revCom','#char'),1:164))
 for (i in 1:dim(x)[1])
 {
 	for (j in 1:dim(x)[2])
 	{
 		y[i,j] <- as.numeric(x[i,j])
 	}
 }
par4 = 'no'
par3 = '3'
par2 = 'none'
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(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)
}

#Note: the /var/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab
load(file="/var/wessaorg/rcomp/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="/var/wessaorg/rcomp/tmp/1u3i51323627339.tab") 
}
}
m
postscript(file="/var/wessaorg/rcomp/tmp/2go3o1323627339.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) 
plot(m)
dev.off()
postscript(file="/var/wessaorg/rcomp/tmp/35bpd1323627339.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) 
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)
}
postscript(file="/var/wessaorg/rcomp/tmp/403wh1323627339.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) 
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="/var/wessaorg/rcomp/tmp/5llzv1323627339.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="/var/wessaorg/rcomp/tmp/6alqj1323627339.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="/var/wessaorg/rcomp/tmp/7qkkj1323627339.tab") 
}

try(system("convert tmp/2go3o1323627339.ps tmp/2go3o1323627339.png",intern=TRUE))
try(system("convert tmp/35bpd1323627339.ps tmp/35bpd1323627339.png",intern=TRUE))
try(system("convert tmp/403wh1323627339.ps tmp/403wh1323627339.png",intern=TRUE))

