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(38 + ,12 + ,32 + ,11 + ,35 + ,14 + ,33 + ,12 + ,37 + ,21 + ,29 + ,12 + ,31 + ,22 + ,36 + ,11 + ,35 + ,10 + ,38 + ,13 + ,31 + ,10 + ,34 + ,8 + ,35 + ,15 + ,38 + ,14 + ,37 + ,10 + ,33 + ,14 + ,32 + ,14 + ,38 + ,11 + ,38 + ,10 + ,32 + ,13 + ,33 + ,7 + ,31 + ,14 + ,38 + ,12 + ,39 + ,14 + ,32 + ,11 + ,32 + ,9 + ,35 + ,11 + ,37 + ,15 + ,33 + ,14 + ,33 + ,13 + ,28 + ,9 + ,32 + ,15 + ,31 + ,10 + ,37 + ,11 + ,30 + ,13 + ,33 + ,8 + ,31 + ,20 + ,33 + ,12 + ,31 + ,10 + ,33 + ,10 + ,32 + ,9 + ,33 + ,14 + ,32 + ,8 + ,33 + ,14 + ,28 + ,11 + ,35 + ,13 + ,39 + ,9 + ,34 + ,11 + ,38 + ,15 + ,32 + ,11 + ,38 + ,10 + ,30 + ,14 + ,33 + ,18 + ,38 + ,14 + ,32 + ,11 + ,32 + ,12 + ,34 + ,13 + ,34 + ,9 + ,36 + ,10 + ,34 + ,15 + ,28 + ,20 + ,34 + ,12 + ,35 + ,12 + ,35 + ,14 + ,31 + ,13 + ,37 + ,11 + ,35 + ,17 + ,27 + ,12 + ,40 + ,13 + ,37 + ,14 + ,36 + ,13 + ,38 + ,15 + ,39 + ,13 + ,41 + ,10 + ,27 + ,11 + ,30 + ,19 + ,37 + ,13 + ,31 + ,17 + ,31 + ,13 + ,27 + ,9 + ,36 + ,11 + ,38 + ,10 + ,37 + ,9 + ,33 + ,12 + ,34 + ,12 + ,31 + ,13 + ,39 + ,13 + ,34 + ,12 + ,32 + ,15 + ,33 + ,22 + ,36 + ,13 + ,32 + ,15 + ,41 + ,13 + ,28 + ,15 + ,30 + ,10 + ,36 + ,11 + ,35 + ,16 + ,31 + ,11 + ,34 + ,11 + ,36 + ,10 + ,36 + ,10 + ,35 + ,16 + ,37 + ,12 + ,28 + ,11 + ,39 + ,16 + ,32 + ,19 + ,35 + ,11 + ,39 + ,16 + ,35 + ,15 + ,42 + ,24 + ,34 + ,14 + ,33 + ,15 + ,41 + ,11 + ,33 + ,15 + ,34 + ,12 + ,32 + ,10 + ,40 + ,14 + ,40 + ,13 + ,35 + ,9 + ,36 + ,15 + ,37 + ,15 + ,27 + ,14 + ,39 + ,11 + ,38 + ,8 + ,31 + ,11 + ,33 + ,11 + ,32 + ,8 + ,39 + ,10 + ,36 + ,11 + ,33 + ,13 + ,33 + ,11 + ,32 + ,20 + ,37 + ,10 + ,30 + ,15 + ,38 + ,12 + ,29 + ,14 + ,22 + ,23 + ,35 + ,14 + ,35 + ,16 + ,34 + ,11 + ,35 + ,12 + ,34 + ,10 + ,34 + ,14 + ,35 + ,12 + ,23 + ,12 + ,31 + ,11 + ,27 + ,12 + ,36 + ,13 + ,31 + ,11 + ,32 + ,19 + ,39 + ,12 + ,37 + ,17 + ,38 + ,9 + ,39 + ,12 + ,34 + ,19 + ,31 + ,18 + ,32 + ,15 + ,37 + ,14 + ,36 + ,11 + ,32 + ,9 + ,35 + ,18 + ,36 + ,16) + ,dim=c(2 + ,162) + ,dimnames=list(c('Seperateness' + ,'Depression') + ,1:162)) > y <- array(NA,dim=c(2,162),dimnames=list(c('Seperateness','Depression'),1:162)) > 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,] 38 12 [2,] 32 11 [3,] 35 14 [4,] 33 12 [5,] 37 21 [6,] 29 12 [7,] 31 22 [8,] 36 11 [9,] 35 10 [10,] 38 13 [11,] 31 10 [12,] 34 8 [13,] 35 15 [14,] 38 14 [15,] 37 10 [16,] 33 14 [17,] 32 14 [18,] 38 11 [19,] 38 10 [20,] 32 13 [21,] 33 7 [22,] 31 14 [23,] 38 12 [24,] 39 14 [25,] 32 11 [26,] 32 9 [27,] 35 11 [28,] 37 15 [29,] 33 14 [30,] 33 13 [31,] 28 9 [32,] 32 15 [33,] 31 10 [34,] 37 11 [35,] 30 13 [36,] 33 8 [37,] 31 20 [38,] 33 12 [39,] 31 10 [40,] 33 10 [41,] 32 9 [42,] 33 14 [43,] 32 8 [44,] 33 14 [45,] 28 11 [46,] 35 13 [47,] 39 9 [48,] 34 11 [49,] 38 15 [50,] 32 11 [51,] 38 10 [52,] 30 14 [53,] 33 18 [54,] 38 14 [55,] 32 11 [56,] 32 12 [57,] 34 13 [58,] 34 9 [59,] 36 10 [60,] 34 15 [61,] 28 20 [62,] 34 12 [63,] 35 12 [64,] 35 14 [65,] 31 13 [66,] 37 11 [67,] 35 17 [68,] 27 12 [69,] 40 13 [70,] 37 14 [71,] 36 13 [72,] 38 15 [73,] 39 13 [74,] 41 10 [75,] 27 11 [76,] 30 19 [77,] 37 13 [78,] 31 17 [79,] 31 13 [80,] 27 9 [81,] 36 11 [82,] 38 10 [83,] 37 9 [84,] 33 12 [85,] 34 12 [86,] 31 13 [87,] 39 13 [88,] 34 12 [89,] 32 15 [90,] 33 22 [91,] 36 13 [92,] 32 15 [93,] 41 13 [94,] 28 15 [95,] 30 10 [96,] 36 11 [97,] 35 16 [98,] 31 11 [99,] 34 11 [100,] 36 10 [101,] 36 10 [102,] 35 16 [103,] 37 12 [104,] 28 11 [105,] 39 16 [106,] 32 19 [107,] 35 11 [108,] 39 16 [109,] 35 15 [110,] 42 24 [111,] 34 14 [112,] 33 15 [113,] 41 11 [114,] 33 15 [115,] 34 12 [116,] 32 10 [117,] 40 14 [118,] 40 13 [119,] 35 9 [120,] 36 15 [121,] 37 15 [122,] 27 14 [123,] 39 11 [124,] 38 8 [125,] 31 11 [126,] 33 11 [127,] 32 8 [128,] 39 10 [129,] 36 11 [130,] 33 13 [131,] 33 11 [132,] 32 20 [133,] 37 10 [134,] 30 15 [135,] 38 12 [136,] 29 14 [137,] 22 23 [138,] 35 14 [139,] 35 16 [140,] 34 11 [141,] 35 12 [142,] 34 10 [143,] 34 14 [144,] 35 12 [145,] 23 12 [146,] 31 11 [147,] 27 12 [148,] 36 13 [149,] 31 11 [150,] 32 19 [151,] 39 12 [152,] 37 17 [153,] 38 9 [154,] 39 12 [155,] 34 19 [156,] 31 18 [157,] 32 15 [158,] 37 14 [159,] 36 11 [160,] 32 9 [161,] 35 18 [162,] 36 16 > (table1 <- table(z[,cat1],z[,cat2])) 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 23 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 27 0 0 1 0 1 2 0 1 0 0 0 0 0 0 0 0 0 0 28 0 0 1 0 2 0 0 0 1 0 0 0 0 1 0 0 0 0 29 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 30 0 0 0 1 0 0 1 1 1 0 0 0 1 0 0 0 0 0 31 0 0 0 3 4 0 3 1 0 0 1 1 0 1 0 1 0 0 32 0 2 3 1 4 1 1 1 4 0 0 0 2 1 0 0 0 0 33 1 1 0 1 2 3 2 4 2 0 0 1 0 0 0 1 0 0 34 0 1 1 1 3 4 1 2 1 0 0 0 1 0 0 0 0 0 35 0 0 1 1 2 3 1 3 2 3 1 1 0 0 0 0 0 0 36 0 0 0 3 5 0 3 0 1 1 0 0 0 0 0 0 0 0 37 0 0 1 2 2 1 1 2 2 0 1 0 0 0 1 0 0 0 38 0 1 1 3 1 3 1 2 2 0 0 0 0 0 0 0 0 0 39 0 0 1 1 1 2 2 1 0 2 0 0 0 0 0 0 0 0 40 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 41 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 > (V1<-dimnames(y)[[1]][cat1]) [1] "Seperateness" > (V2<-dimnames(y)[[1]][cat2]) [1] "Depression" > postscript(file="/var/wessaorg/rcomp/tmp/1apm31321100148.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/24p9x1321100148.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test data: table1 X-squared = 506.7676, df = 289, p-value = 3.911e-14 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/370do1321100148.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/4cw311321100148.tab") > > try(system("convert tmp/1apm31321100148.ps tmp/1apm31321100148.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.138 0.100 3.241