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('E',1,'F',0,'F',1,'H',1,'H',1,'H',1,'E',1,'F',1,'E',1,'F',0,'H',0,'E',0,'F',1,'H',0,'E',0,'H',0,'E',1,'F',1,'H',0,'F',0,'H',0,'H',1,'H',0,'E',0,'F',0,'E',0,'E',0,'F',1,'F',0,'H',0,'E',1,'E',1,'H',1,'E',1,'F',1,'E',1,'F',0,'H',0,'E',0,'F',0,'F',0,'F',0,'F',0,'H',1,'E',0,'E',0,'H',0,'E',1,'F',1,'F',0,'H',0,'E',1,'F',1,'E',1,'H',1,'H',1,'H',1,'E',1,'H',0,'E',0,'H',1,'F',1,'H',1,'F',0,'E',1,'E',1,'F',0,'H',1,'F',0,'E',1,'E',1,'H',0,'H',1,'F',1,'H',1,'E',0,'F',1,'E',0,'E',0,'E',0,'F',1,'E',1,'F',1,'H',1,'H',1,'H',1,'F',0,'H',1,'H',1,'F',1,'F',1,'H',0,'F',1,'H',1,'E',0,'F',1,'E',0,'H',1,'F',1,'F',1,'H',1,'E',1,'F',0,'H',1,'E',1,'F',0,'H',0,'H',1,'F',1,'F',1,'H',1,'E',0,'H',1,'E',1,'E',0,'F',1,'F',1),dim=c(2,117),dimnames=list(c('treat','gender'),1:117)) > y <- array(NA,dim=c(2,117),dimnames=list(c('treat','gender'),1:117)) > for (i in 1:dim(x)[1]) + { + for (j in 1:dim(x)[2]) + { + y[i,j] <- as.numeric(x[i,j]) + } + } There were 50 or more warnings (use warnings() to see the first 50) > par3 = 'Exact Pearson Chi-Squared by Simulation' > par2 = '2' > par1 = '1' > 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] [1,] "E" "1" [2,] "F" "0" [3,] "F" "1" [4,] "H" "1" [5,] "H" "1" [6,] "H" "1" [7,] "E" "1" [8,] "F" "1" [9,] "E" "1" [10,] "F" "0" [11,] "H" "0" [12,] "E" "0" [13,] "F" "1" [14,] "H" "0" [15,] "E" "0" [16,] "H" "0" [17,] "E" "1" [18,] "F" "1" [19,] "H" "0" [20,] "F" "0" [21,] "H" "0" [22,] "H" "1" [23,] "H" "0" [24,] "E" "0" [25,] "F" "0" [26,] "E" "0" [27,] "E" "0" [28,] "F" "1" [29,] "F" "0" [30,] "H" "0" [31,] "E" "1" [32,] "E" "1" [33,] "H" "1" [34,] "E" "1" [35,] "F" "1" [36,] "E" "1" [37,] "F" "0" [38,] "H" "0" [39,] "E" "0" [40,] "F" "0" [41,] "F" "0" [42,] "F" "0" [43,] "F" "0" [44,] "H" "1" [45,] "E" "0" [46,] "E" "0" [47,] "H" "0" [48,] "E" "1" [49,] "F" "1" [50,] "F" "0" [51,] "H" "0" [52,] "E" "1" [53,] "F" "1" [54,] "E" "1" [55,] "H" "1" [56,] "H" "1" [57,] "H" "1" [58,] "E" "1" [59,] "H" "0" [60,] "E" "0" [61,] "H" "1" [62,] "F" "1" [63,] "H" "1" [64,] "F" "0" [65,] "E" "1" [66,] "E" "1" [67,] "F" "0" [68,] "H" "1" [69,] "F" "0" [70,] "E" "1" [71,] "E" "1" [72,] "H" "0" [73,] "H" "1" [74,] "F" "1" [75,] "H" "1" [76,] "E" "0" [77,] "F" "1" [78,] "E" "0" [79,] "E" "0" [80,] "E" "0" [81,] "F" "1" [82,] "E" "1" [83,] "F" "1" [84,] "H" "1" [85,] "H" "1" [86,] "H" "1" [87,] "F" "0" [88,] "H" "1" [89,] "H" "1" [90,] "F" "1" [91,] "F" "1" [92,] "H" "0" [93,] "F" "1" [94,] "H" "1" [95,] "E" "0" [96,] "F" "1" [97,] "E" "0" [98,] "H" "1" [99,] "F" "1" [100,] "F" "1" [101,] "H" "1" [102,] "E" "1" [103,] "F" "0" [104,] "H" "1" [105,] "E" "1" [106,] "F" "0" [107,] "H" "0" [108,] "H" "1" [109,] "F" "1" [110,] "F" "1" [111,] "H" "1" [112,] "E" "0" [113,] "H" "1" [114,] "E" "1" [115,] "E" "0" [116,] "F" "1" [117,] "F" "1" > (table1 <- table(z[,cat1],z[,cat2])) 0 1 E 17 20 F 17 23 H 14 26 > (V1<-dimnames(y)[[1]][cat1]) [1] "treat" > (V2<-dimnames(y)[[1]][cat2]) [1] "gender" > postscript(file="/var/fisher/rcomp/tmp/1uj2s1356024493.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/2um341356024493.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 = 1.0064, df = NA, p-value = 0.6277 > 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/33vpe1356024493.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/4f06m1356024493.tab") > > try(system("convert tmp/1uj2s1356024493.ps tmp/1uj2s1356024493.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.426 0.299 1.746