R version 2.13.0 (2011-04-13) Copyright (C) 2011 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('D' + ,'A' + ,'C' + ,'C' + ,'A' + ,'B' + ,'C' + ,'A' + ,'D' + ,'C' + ,'A' + ,'C' + ,'A' + ,'C' + ,'A' + ,'B' + ,'C' + ,'C' + ,'B' + ,'A' + ,'B' + ,'A' + ,'D' + ,'D' + ,'D' + ,'A' + ,'A' + ,'B' + ,'A' + ,'D' + ,'B' + ,'A' + ,'B' + ,'B' + ,'A' + ,'D' + ,'B' + ,'B' + ,'C' + ,'B' + ,'A' + ,'B' + ,'B' + ,'D' + ,'B' + ,'A' + ,'A' + ,'B' + ,'B' + ,'A' + ,'A' + ,'D' + ,'B' + ,'B' + ,'D' + ,'A' + ,'C' + ,'B' + ,'A' + ,'A' + ,'B' + ,'A' + ,'A' + ,'B' + ,'B' + ,'D' + ,'D' + ,'A' + ,'C' + ,'C' + ,'D' + ,'A' + ,'D' + ,'B' + ,'B' + ,'A' + ,'B' + ,'C' + ,'B' + ,'C' + ,'B' + ,'A' + ,'B' + ,'C' + ,'A' + ,'D' + ,'A' + ,'C' + ,'B' + ,'D' + ,'A' + ,'B' + ,'B' + ,'B' + ,'A' + ,'C' + ,'D' + ,'D' + ,'C' + ,'A' + ,'A' + ,'A' + ,'C' + ,'B' + ,'C' + ,'A' + ,'D' + ,'C' + ,'D' + ,'A' + ,'A' + ,'A' + ,'B' + ,'B' + ,'C' + ,'C' + ,'A' + ,'C' + ,'A' + ,'A' + ,'C' + ,'A' + ,'A' + ,'A' + ,'A' + ,'B' + ,'A' + ,'A' + ,'A' + ,'D' + ,'A' + ,'D' + ,'C' + ,'C' + ,'A' + ,'C' + ,'B' + ,'A' + ,'D' + ,'A' + ,'A' + ,'C' + ,'B' + ,'B' + ,'D' + ,'C' + ,'A' + ,'A' + ,'A' + ,'C' + ,'A' + ,'D' + ,'C' + ,'A' + ,'D' + ,'A' + ,'C' + ,'C' + ,'C' + ,'D' + ,'D' + ,'A' + ,'D' + ,'A' + ,'C' + ,'C' + ,'B' + ,'B' + ,'C' + ,'C' + ,'A' + ,'D' + ,'D' + ,'A' + ,'A' + ,'D' + ,'B' + ,'A' + ,'A' + ,'C' + ,'A' + ,'D' + ,'A' + ,'B' + ,'A' + ,'D' + ,'C' + ,'B' + ,'B' + ,'D' + ,'D' + ,'C' + ,'A' + ,'D' + ,'B' + ,'D' + ,'B' + ,'D' + ,'C' + ,'A' + ,'B' + ,'C' + ,'B' + ,'B' + ,'C' + ,'C' + ,'A' + ,'B' + ,'B' + ,'A' + ,'A' + ,'A' + ,'D' + ,'B' + ,'B' + ,'B' + ,'A' + ,'B' + ,'A' + ,'C' + ,'A' + ,'B' + ,'A' + ,'C' + ,'C' + ,'C' + ,'D' + ,'B' + ,'A' + ,'C' + ,'A' + ,'B') + ,dim=c(2 + ,116) + ,dimnames=list(c('Depression' + ,'Connected') + ,1:116)) > y <- array(NA,dim=c(2,116),dimnames=list(c('Depression','Connected'),1:116)) > 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 = 'Pearson Chi-Squared' > par2 = '2' > par1 = '1' > main = 'Association Plot' > #'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,] "D" "A" [2,] "C" "C" [3,] "A" "B" [4,] "C" "A" [5,] "D" "C" [6,] "A" "C" [7,] "A" "C" [8,] "A" "B" [9,] "C" "C" [10,] "B" "A" [11,] "B" "A" [12,] "D" "D" [13,] "D" "A" [14,] "A" "B" [15,] "A" "D" [16,] "B" "A" [17,] "B" "B" [18,] "A" "D" [19,] "B" "B" [20,] "C" "B" [21,] "A" "B" [22,] "B" "D" [23,] "B" "A" [24,] "A" "B" [25,] "B" "A" [26,] "A" "D" [27,] "B" "B" [28,] "D" "A" [29,] "C" "B" [30,] "A" "A" [31,] "B" "A" [32,] "A" "B" [33,] "B" "D" [34,] "D" "A" [35,] "C" "C" [36,] "D" "A" [37,] "D" "B" [38,] "B" "A" [39,] "B" "C" [40,] "B" "C" [41,] "B" "A" [42,] "B" "C" [43,] "A" "D" [44,] "A" "C" [45,] "B" "D" [46,] "A" "B" [47,] "B" "B" [48,] "A" "C" [49,] "D" "D" [50,] "C" "A" [51,] "A" "A" [52,] "C" "B" [53,] "C" "A" [54,] "D" "C" [55,] "D" "A" [56,] "A" "A" [57,] "B" "B" [58,] "C" "C" [59,] "A" "C" [60,] "A" "A" [61,] "C" "A" [62,] "A" "A" [63,] "A" "B" [64,] "A" "A" [65,] "A" "D" [66,] "A" "D" [67,] "C" "C" [68,] "A" "C" [69,] "B" "A" [70,] "D" "A" [71,] "A" "C" [72,] "B" "B" [73,] "D" "C" [74,] "A" "A" [75,] "A" "C" [76,] "A" "D" [77,] "C" "A" [78,] "D" "A" [79,] "C" "C" [80,] "C" "D" [81,] "D" "A" [82,] "D" "A" [83,] "C" "C" [84,] "B" "B" [85,] "C" "C" [86,] "A" "D" [87,] "D" "A" [88,] "A" "D" [89,] "B" "A" [90,] "A" "C" [91,] "A" "D" [92,] "A" "B" [93,] "A" "D" [94,] "C" "B" [95,] "B" "D" [96,] "D" "C" [97,] "A" "D" [98,] "B" "D" [99,] "B" "D" [100,] "C" "A" [101,] "B" "C" [102,] "B" "B" [103,] "C" "C" [104,] "A" "B" [105,] "B" "A" [106,] "A" "A" [107,] "D" "B" [108,] "B" "B" [109,] "A" "B" [110,] "A" "C" [111,] "A" "B" [112,] "A" "C" [113,] "C" "C" [114,] "D" "B" [115,] "A" "C" [116,] "A" "B" > (table1 <- table(z[,cat1],z[,cat2])) A B C D A 8 13 12 12 B 11 9 4 6 C 6 4 10 1 D 11 3 4 2 > (V1<-dimnames(y)[[1]][cat1]) [1] "Depression" > (V2<-dimnames(y)[[1]][cat2]) [1] "Connected" > postscript(file="/var/wessaorg/rcomp/tmp/1zrw61321456171.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/2le591321456171.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test data: table1 X-squared = 18.8813, df = 9, p-value = 0.02622 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/3p5be1321456171.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/4ewxa1321456171.tab") > > try(system("convert tmp/1zrw61321456171.ps tmp/1zrw61321456171.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.007 0.087 1.104