x <- array(list(41
,12
,39
,11
,30
,14
,31
,12
,34
,21
,35
,12
,39
,22
,34
,11
,36
,10
,37
,13
,38
,10
,36
,8
,38
,15
,39
,14
,33
,10
,32
,14
,36
,14
,38
,11
,39
,10
,32
,13
,32
,7
,31
,14
,39
,12
,37
,14
,39
,11
,41
,9
,36
,11
,33
,15
,33
,14
,34
,13
,31
,9
,27
,15
,37
,10
,34
,11
,34
,13
,32
,8
,29
,20
,36
,12
,29
,10
,35
,10
,37
,9
,34
,14
,38
,8
,35
,14
,38
,11
,37
,13
,38
,9
,33
,11
,36
,15
,38
,11
,32
,10
,32
,14
,32
,18
,34
,14
,32
,11
,37
,12
,39
,13
,29
,9
,37
,10
,35
,15
,30
,20
,38
,12
,34
,12
,31
,14
,34
,13
,35
,11
,36
,17
,30
,12
,39
,13
,35
,14
,38
,13
,31
,15
,34
,13
,38
,10
,34
,11
,39
,19
,37
,13
,34
,17
,28
,13
,37
,9
,33
,11
,37
,10
,35
,9
,37
,12
,32
,12
,33
,13
,38
,13
,33
,12
,29
,15
,33
,22
,31
,13
,36
,15
,35
,13
,32
,15
,29
,10
,39
,11
,37
,16
,35
,11
,37
,11
,32
,10
,38
,10
,37
,16
,36
,12
,32
,11
,33
,16
,40
,19
,38
,11
,41
,16
,36
,15
,43
,24
,30
,14
,31
,15
,32
,11
,32
,15
,37
,12
,37
,10
,33
,14
,34
,13
,33
,9
,38
,15
,33
,15
,31
,14
,38
,11
,37
,8
,33
,11
,31
,11
,39
,8
,44
,10
,33
,11
,35
,13
,32
,11
,28
,20
,40
,10
,27
,15
,37
,12
,32
,14
,28
,23
,34
,14
,30
,16
,35
,11
,31
,12
,32
,10
,30
,14
,30
,12
,31
,12
,40
,11
,32
,12
,36
,13
,32
,11
,35
,19
,38
,12
,42
,17
,34
,9
,35
,12
,35
,19
,33
,18
,36
,15
,32
,14
,33
,11
,34
,9
,32
,18
,34
,16)
,dim=c(2
,162)
,dimnames=list(c('Depression'
,'Connected')
,1:162))
 y <- array(NA,dim=c(2,162),dimnames=list(c('Depression','Connected'),1:162))
 for (i in 1:dim(x)[1])
 {
 	for (j in 1:dim(x)[2])
 	{
 		y[i,j] <- as.numeric(x[i,j])
 	}
 }
par3 = 'Exact Pearson Chi-Squared by Simulation'
par2 = '2'
par1 = '1'
main = 'Association Plot'
par3 <- 'Exact Pearson Chi-Squared by Simulation'
par2 <- '2'
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(vcd)
cat1 <- as.numeric(par1) #
cat2<- as.numeric(par2) #
simulate.p.value=FALSE
if (par3 == 'Exact Pearson Chi-Squared by Simulation') simulate.p.value=TRUE
x <- t(x)
(z <- array(unlist(x),dim=c(length(x[,1]),length(x[1,]))))
(table1 <- table(z[,cat1],z[,cat2]))
(V1<-dimnames(y)[[1]][cat1])
(V2<-dimnames(y)[[1]][cat2])
postscript(file="/var/wessaorg/rcomp/tmp/19fq11350915902.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) 
assoc(ftable(z[,cat1],z[,cat2],row.vars=1,dnn=c(V1,V2)),shade=T)
dev.off()

#Note: the /var/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab
load(file="/var/wessaorg/rcomp/createtable")

a<-table.start()
a<-table.row.start(a)
a<-table.element(a,'Tabulation of Results',ncol(table1)+1,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,paste(V1,' x ', V2),ncol(table1)+1,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a, ' ', 1,TRUE)
for(nc in 1:ncol(table1)){
a<-table.element(a, colnames(table1)[nc], 1, TRUE)
}
a<-table.row.end(a)
for(nr in 1:nrow(table1) ){
a<-table.element(a, rownames(table1)[nr], 1, TRUE)
for(nc in 1:ncol(table1) ){
a<-table.element(a, table1[nr, nc], 1, FALSE)
}
a<-table.row.end(a)
}
a<-table.end(a)
table.save(a,file="/var/wessaorg/rcomp/tmp/265kf1350915902.tab") 
(cst<-chisq.test(table1, simulate.p.value=simulate.p.value) )
if (par3 == 'McNemar Chi-Squared') {
(cst <- mcnemar.test(table1))
}
if (par3=='Fisher Exact Test') {
(cst <- fisher.test(table1))
}
if ((par3 != 'McNemar Chi-Squared') & (par3 != 'Fisher Exact Test')) {
a<-table.start()
a<-table.row.start(a)
a<-table.element(a,'Tabulation of Expected Results',ncol(table1)+1,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a,paste(V1,' x ', V2),ncol(table1)+1,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a, ' ', 1,TRUE)
for(nc in 1:ncol(table1)){
a<-table.element(a, colnames(table1)[nc], 1, TRUE)
}
a<-table.row.end(a)
for(nr in 1:nrow(table1) ){
a<-table.element(a, rownames(table1)[nr], 1, TRUE)
for(nc in 1:ncol(table1) ){
a<-table.element(a, round(cst$expected[nr, nc], digits=2), 1, FALSE)
}
a<-table.row.end(a)
}
a<-table.end(a)
table.save(a,file="/var/wessaorg/rcomp/tmp/3ms6z1350915903.tab") 
}
a<-table.start()
a<-table.row.start(a)
a<-table.element(a,'Statistical Results',2,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
a<-table.element(a, cst$method, 2,TRUE)
a<-table.row.end(a)
a<-table.row.start(a)
if (par3=='Pearson Chi-Squared') a<-table.element(a, 'Pearson Chi Square Statistic', 1, TRUE)
if (par3=='Exact Pearson Chi-Squared by Simulation') a<-table.element(a, 'Exact Pearson Chi Square Statistic', 1, TRUE)
if (par3=='McNemar Chi-Squared') a<-table.element(a, 'McNemar Chi Square Statistic', 1, TRUE)
if (par3=='Fisher Exact Test') a<-table.element(a, 'Odds Ratio', 1, TRUE)
if (par3=='Fisher Exact Test') {
if ((ncol(table1) == 2) & (nrow(table1) == 2)) {
a<-table.element(a, round(cst$estimate, digits=2), 1,FALSE)
} else {
a<-table.element(a, '--', 1,FALSE)
}
} else {
a<-table.element(a, round(cst$statistic, digits=2), 1,FALSE)
}
a<-table.row.end(a)
if(!simulate.p.value){
if(par3!='Fisher Exact Test') {
a<-table.row.start(a)
a<-table.element(a, 'Degrees of Freedom', 1, TRUE)
a<-table.element(a, cst$parameter, 1,FALSE)
a<-table.row.end(a)
}
}
a<-table.row.start(a)
a<-table.element(a, 'P value', 1, TRUE)
a<-table.element(a, round(cst$p.value, digits=2), 1,FALSE)
a<-table.row.end(a)
a<-table.end(a)
table.save(a,file="/var/wessaorg/rcomp/tmp/4plz31350915903.tab") 

try(system("convert tmp/19fq11350915902.ps tmp/19fq11350915902.png",intern=TRUE))

