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