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(0,-1,0,-1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,-1,0,0,1,1,1,1,1,0,0,NA,0,0,0,-1,0,0,1,1,0,1,0,0,0,-1,0,NA,-1,NA,0,0,-1,0,0,NA,0,NA,0,0,0,0,-1,-1,0,-1,0,1,0,NA,0,1,0,NA,0,-1,1,1,1,1,0,0,0,0,0,0,0,-1,0,0,0,1,1,1,1,0,0,-1,0,0,0,0,1,1,0,0,1,1,0,NA,1,0,1,1,1,1,1,NA,0,0,0,NA,1,1,0,0,0,0,-1,0,0,1,1,0,1,1,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,-1,0,0,1,0,0,-1,0,0,0,0,1,0,1,0,1,-1,0,0,NA,0,1,-1,NA,0,0,0,1,0,NA,0,-1,0,0,0,NA,1,1,0,0,0,0,0,0,0,0,0,NA,0,0,0,-1,0,1,0,0,0,1,1,0),dim=c(2,105),dimnames=list(c('post1-pre','post3-pre'),1:105)) > y <- array(NA,dim=c(2,105),dimnames=list(c('post1-pre','post3-pre'),1:105)) > 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) 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,] 0 -1 [2,] 0 -1 [3,] 1 1 [4,] 0 0 [5,] 0 0 [6,] 0 0 [7,] 0 0 [8,] 1 1 [9,] 1 1 [10,] 0 -1 [11,] 0 0 [12,] 1 1 [13,] 1 1 [14,] 1 0 [15,] 0 NA [16,] 0 0 [17,] 0 -1 [18,] 0 0 [19,] 1 1 [20,] 0 1 [21,] 0 0 [22,] 0 -1 [23,] 0 NA [24,] -1 NA [25,] 0 0 [26,] -1 0 [27,] 0 NA [28,] 0 NA [29,] 0 0 [30,] 0 0 [31,] -1 -1 [32,] 0 -1 [33,] 0 1 [34,] 0 NA [35,] 0 1 [36,] 0 NA [37,] 0 -1 [38,] 1 1 [39,] 1 1 [40,] 0 0 [41,] 0 0 [42,] 0 0 [43,] 0 -1 [44,] 0 0 [45,] 0 1 [46,] 1 1 [47,] 1 0 [48,] 0 -1 [49,] 0 0 [50,] 0 0 [51,] 1 1 [52,] 0 0 [53,] 1 1 [54,] 0 NA [55,] 1 0 [56,] 1 1 [57,] 1 1 [58,] 1 NA [59,] 0 0 [60,] 0 NA [61,] 1 1 [62,] 0 0 [63,] 0 0 [64,] -1 0 [65,] 0 1 [66,] 1 0 [67,] 1 1 [68,] 0 0 [69,] 0 0 [70,] 0 0 [71,] 1 0 [72,] 1 0 [73,] 1 0 [74,] 1 0 [75,] 0 0 [76,] -1 0 [77,] 0 1 [78,] 0 0 [79,] -1 0 [80,] 0 0 [81,] 0 1 [82,] 0 1 [83,] 0 1 [84,] -1 0 [85,] 0 NA [86,] 0 1 [87,] -1 NA [88,] 0 0 [89,] 0 1 [90,] 0 NA [91,] 0 -1 [92,] 0 0 [93,] 0 NA [94,] 1 1 [95,] 0 0 [96,] 0 0 [97,] 0 0 [98,] 0 0 [99,] 0 NA [100,] 0 0 [101,] 0 -1 [102,] 0 1 [103,] 0 0 [104,] 0 1 [105,] 1 0 > (table1 <- table(z[,cat1],z[,cat2])) -1 0 1 -1 1 5 0 0 11 35 13 1 0 9 16 > (V1<-dimnames(y)[[1]][cat1]) [1] "post1-pre" > (V2<-dimnames(y)[[1]][cat2]) [1] "post3-pre" > postscript(file="/var/fisher/rcomp/tmp/1wutr1354793628.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/2kud71354793628.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 = 19.0399, df = NA, p-value = 0.001499 > 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/fisher/rcomp/tmp/30xo11354793628.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/fisher/rcomp/tmp/4r55j1354793628.tab") > > try(system("convert tmp/1wutr1354793628.ps tmp/1wutr1354793628.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.422 0.278 1.680