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