R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-pc-linux-gnu (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > x <- array(list(1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1,0,1,1,1,0,1,1,1,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,1,1,1,1,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,1,1,1,1,0,1,1,1,0,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,0,1,0,0,NA,0,0,NA,1,1,NA,NA,1,NA,NA),dim=c(3,37),dimnames=list(c('T','E','S'),1:37)) > y <- array(NA,dim=c(3,37),dimnames=list(c('T','E','S'),1:37)) > 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 = '3' > par1 = '2' > main = 'Association Plot' > library(vcd) Loading required package: MASS Loading required package: grid Loading required package: colorspace > 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,])))) [,1] [,2] [,3] [1,] 1 1 1 [2,] 1 1 1 [3,] 1 1 1 [4,] 0 1 1 [5,] 1 1 1 [6,] 1 1 0 [7,] 1 1 0 [8,] 1 0 1 [9,] 1 1 0 [10,] 1 1 1 [11,] 0 1 0 [12,] 1 1 0 [13,] 1 0 0 [14,] 1 1 0 [15,] 0 1 0 [16,] 1 1 0 [17,] 1 0 0 [18,] 1 1 1 [19,] 1 1 0 [20,] 0 1 0 [21,] 1 1 1 [22,] 1 0 1 [23,] 0 0 1 [24,] 0 1 1 [25,] 1 1 1 [26,] 0 1 1 [27,] 1 0 1 [28,] 0 0 1 [29,] 0 1 0 [30,] 1 1 0 [31,] 0 0 1 [32,] 1 1 0 [33,] 0 1 0 [34,] 0 NA 0 [35,] 0 NA 1 [36,] 1 NA NA [37,] 1 NA NA > (table1 <- table(z[,cat1],z[,cat2])) 0 1 0 2 6 1 14 11 > (V1<-dimnames(y)[[1]][cat1]) [1] "E" > (V2<-dimnames(y)[[1]][cat2]) [1] "S" > postscript(file="/var/fisher/rcomp/tmp/1iotz1355418317.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() null device 1 > > #Note: the /var/fisher/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/fisher/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/fisher/rcomp/tmp/2hnqg1355418317.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test with simulated p-value (based on 2000 replicates) data: table1 X-squared = 2.3318, df = NA, p-value = 0.2144 > if (par3 == 'McNemar Chi-Squared') { + (cst <- mcnemar.test(table1)) + } > if (par3 != 'McNemar Chi-Squared') { + 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/fisher/rcomp/tmp/3w9oj1355418317.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) > a<-table.element(a, 'Chi Square Statistic', 1, TRUE) > a<-table.element(a, round(cst$statistic, digits=2), 1,FALSE) > a<-table.row.end(a) > if(!simulate.p.value){ + 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/fisher/rcomp/tmp/4inll1355418317.tab") > > try(system("convert tmp/1iotz1355418317.ps tmp/1iotz1355418317.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.465 0.315 1.769