R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows" 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(12,41,11,39,14,30,12,31,21,34,12,35,22,39,11,34,10,36,13,37,10,38,8,36,15,38,14,39,10,33,14,32,14,36,11,38,10,39,13,32,7,32,14,31,12,39,14,37,11,39,9,41,11,36,15,33,14,33,13,34,9,31,15,27,10,37,11,34,13,34,8,32,20,29,12,36,10,29,10,35),dim=c(2,40),dimnames=list(c('A','B'),1:40)) > y <- array(NA,dim=c(2,40),dimnames=list(c('A','B'),1:40)) > for (i in 1:dim(x)[1]) + { + for (j in 1:dim(x)[2]) + { + y[i,j] <- as.numeric(x[i,j]) + } + } > par3 = 'Pearson Chi-Squared' > par2 = '2' > par1 = '1' > main = 'Association Plot' > par3 <- 'Pearson Chi-Squared' > 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,] 12 41 [2,] 11 39 [3,] 14 30 [4,] 12 31 [5,] 21 34 [6,] 12 35 [7,] 22 39 [8,] 11 34 [9,] 10 36 [10,] 13 37 [11,] 10 38 [12,] 8 36 [13,] 15 38 [14,] 14 39 [15,] 10 33 [16,] 14 32 [17,] 14 36 [18,] 11 38 [19,] 10 39 [20,] 13 32 [21,] 7 32 [22,] 14 31 [23,] 12 39 [24,] 14 37 [25,] 11 39 [26,] 9 41 [27,] 11 36 [28,] 15 33 [29,] 14 33 [30,] 13 34 [31,] 9 31 [32,] 15 27 [33,] 10 37 [34,] 11 34 [35,] 13 34 [36,] 8 32 [37,] 20 29 [38,] 12 36 [39,] 10 29 [40,] 10 35 > (table1 <- table(z[,cat1],z[,cat2])) 27 29 30 31 32 33 34 35 36 37 38 39 41 7 0 0 0 0 1 0 0 0 0 0 0 0 0 8 0 0 0 0 1 0 0 0 1 0 0 0 0 9 0 0 0 1 0 0 0 0 0 0 0 0 1 10 0 1 0 0 0 1 0 1 1 1 1 1 0 11 0 0 0 0 0 0 2 0 1 0 1 2 0 12 0 0 0 1 0 0 0 1 1 0 0 1 1 13 0 0 0 0 1 0 2 0 0 1 0 0 0 14 0 0 1 1 1 1 0 0 1 1 0 1 0 15 1 0 0 0 0 1 0 0 0 0 1 0 0 20 0 1 0 0 0 0 0 0 0 0 0 0 0 21 0 0 0 0 0 0 1 0 0 0 0 0 0 22 0 0 0 0 0 0 0 0 0 0 0 1 0 > (V1<-dimnames(y)[[1]][cat1]) [1] "A" > (V2<-dimnames(y)[[1]][cat2]) [1] "B" > postscript(file="/var/wessaorg/rcomp/tmp/1bsoz1350942362.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/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/24bg11350942362.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test data: table1 X-squared = 121.7984, df = 132, p-value = 0.7269 Warning message: In chisq.test(table1, simulate.p.value = simulate.p.value) : Chi-squared approximation may be incorrect > 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/37q8n1350942362.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/42cmh1350942362.tab") > > try(system("convert tmp/1bsoz1350942362.ps tmp/1bsoz1350942362.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.972 0.186 3.131