R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-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(16,14,10,8,14,12,8,7,12,10,9,7,18,16,12,11,16,14,6,6,18,16,13,11,17,16,14,12,9,7,13,13,13,11,15,15,8,7,10,9,9,7,16,14,16,15,9,7,17,15,17,17,15,15,14,14,16,14,10,8,10,8,16,14,17,14,10,8,12,11,17,16,12,10,10,8,15,14,18,16,15,13,7,5,9,8,12,10,10,8,15,13,17,15,8,6,13,12,17,16,7,5,15,15,14,12,10,8,15,13,16,14,14,12,18,16,12,10,16,15,10,8,18,16,21,19,16,14),dim=c(2,64),dimnames=list(c('Loon','Size'),1:64)) > y <- array(NA,dim=c(2,64),dimnames=list(c('Loon','Size'),1:64)) > 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' > 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,] 16 14 [2,] 10 8 [3,] 14 12 [4,] 8 7 [5,] 12 10 [6,] 9 7 [7,] 18 16 [8,] 12 11 [9,] 16 14 [10,] 6 6 [11,] 18 16 [12,] 13 11 [13,] 17 16 [14,] 14 12 [15,] 9 7 [16,] 13 13 [17,] 13 11 [18,] 15 15 [19,] 8 7 [20,] 10 9 [21,] 9 7 [22,] 16 14 [23,] 16 15 [24,] 9 7 [25,] 17 15 [26,] 17 17 [27,] 15 15 [28,] 14 14 [29,] 16 14 [30,] 10 8 [31,] 10 8 [32,] 16 14 [33,] 17 14 [34,] 10 8 [35,] 12 11 [36,] 17 16 [37,] 12 10 [38,] 10 8 [39,] 15 14 [40,] 18 16 [41,] 15 13 [42,] 7 5 [43,] 9 8 [44,] 12 10 [45,] 10 8 [46,] 15 13 [47,] 17 15 [48,] 8 6 [49,] 13 12 [50,] 17 16 [51,] 7 5 [52,] 15 15 [53,] 14 12 [54,] 10 8 [55,] 15 13 [56,] 16 14 [57,] 14 12 [58,] 18 16 [59,] 12 10 [60,] 16 15 [61,] 10 8 [62,] 18 16 [63,] 21 19 [64,] 16 14 > (table1 <- table(z[,cat1],z[,cat2])) 5 6 7 8 9 10 11 12 13 14 15 16 17 19 6 0 1 0 0 0 0 0 0 0 0 0 0 0 0 7 2 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 1 2 0 0 0 0 0 0 0 0 0 0 0 9 0 0 4 1 0 0 0 0 0 0 0 0 0 0 10 0 0 0 8 1 0 0 0 0 0 0 0 0 0 12 0 0 0 0 0 4 2 0 0 0 0 0 0 0 13 0 0 0 0 0 0 2 1 1 0 0 0 0 0 14 0 0 0 0 0 0 0 4 0 1 0 0 0 0 15 0 0 0 0 0 0 0 0 3 1 3 0 0 0 16 0 0 0 0 0 0 0 0 0 7 2 0 0 0 17 0 0 0 0 0 0 0 0 0 1 2 3 1 0 18 0 0 0 0 0 0 0 0 0 0 0 5 0 0 21 0 0 0 0 0 0 0 0 0 0 0 0 0 1 > (V1<-dimnames(y)[[1]][cat1]) [1] "Loon" > (V2<-dimnames(y)[[1]][cat2]) [1] "Size" > postscript(file="/var/www/rcomp/tmp/1wija1324219659.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/www/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/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/www/rcomp/tmp/25wn51324219659.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test data: table1 X-squared = 470.6129, df = 156, p-value < 2.2e-16 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/www/rcomp/tmp/3ll991324219659.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/www/rcomp/tmp/4p5ng1324219659.tab") > > try(system("convert tmp/1wija1324219659.ps tmp/1wija1324219659.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.080 0.070 2.135