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,38,14,12,39,32,18,11,30,35,11,14,31,33,12,12,34,37,16,21,35,29,18,12,39,31,14,22,34,36,14,11,36,35,15,10,37,38,15,13,38,31,17,10,36,34,19,8,38,35,10,15,39,38,16,14,33,37,18,10,32,33,14,14,36,32,14,14,38,38,17,11,39,38,14,10,32,32,16,13,32,33,18,7,31,31,11,14,39,38,14,12,37,39,12,14,39,32,17,11,41,32,9,9,36,35,16,11,33,37,14,15,33,33,15,14,34,33,11,13,31,28,16,9,27,32,13,15,37,31,17,10,34,37,15,11,34,30,14,13,32,33,16,8,29,31,9,20,36,33,15,12,29,31,17,10,35,33,13,10,37,32,15,9,34,33,16,14,38,32,16,8,35,33,12,14,38,28,12,11,37,35,11,13,38,39,15,9,33,34,15,11,36,38,17,15,38,32,13,11,32,38,16,10,32,30,14,14,32,33,11,18,34,38,12,14,32,32,12,11,37,32,15,12,39,34,16,13,29,34,15,9,37,36,12,10,35,34,12,15,30,28,8,20,38,34,13,12),dim=c(4,62),dimnames=list(c('Connected','Separate','Happiness','Depression'),1:62)) > y <- array(NA,dim=c(4,62),dimnames=list(c('Connected','Separate','Happiness','Depression'),1:62)) > 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] [,3] [,4] [1,] 41 38 14 12 [2,] 39 32 18 11 [3,] 30 35 11 14 [4,] 31 33 12 12 [5,] 34 37 16 21 [6,] 35 29 18 12 [7,] 39 31 14 22 [8,] 34 36 14 11 [9,] 36 35 15 10 [10,] 37 38 15 13 [11,] 38 31 17 10 [12,] 36 34 19 8 [13,] 38 35 10 15 [14,] 39 38 16 14 [15,] 33 37 18 10 [16,] 32 33 14 14 [17,] 36 32 14 14 [18,] 38 38 17 11 [19,] 39 38 14 10 [20,] 32 32 16 13 [21,] 32 33 18 7 [22,] 31 31 11 14 [23,] 39 38 14 12 [24,] 37 39 12 14 [25,] 39 32 17 11 [26,] 41 32 9 9 [27,] 36 35 16 11 [28,] 33 37 14 15 [29,] 33 33 15 14 [30,] 34 33 11 13 [31,] 31 28 16 9 [32,] 27 32 13 15 [33,] 37 31 17 10 [34,] 34 37 15 11 [35,] 34 30 14 13 [36,] 32 33 16 8 [37,] 29 31 9 20 [38,] 36 33 15 12 [39,] 29 31 17 10 [40,] 35 33 13 10 [41,] 37 32 15 9 [42,] 34 33 16 14 [43,] 38 32 16 8 [44,] 35 33 12 14 [45,] 38 28 12 11 [46,] 37 35 11 13 [47,] 38 39 15 9 [48,] 33 34 15 11 [49,] 36 38 17 15 [50,] 38 32 13 11 [51,] 32 38 16 10 [52,] 32 30 14 14 [53,] 32 33 11 18 [54,] 34 38 12 14 [55,] 32 32 12 11 [56,] 37 32 15 12 [57,] 39 34 16 13 [58,] 29 34 15 9 [59,] 37 36 12 10 [60,] 35 34 12 15 [61,] 30 28 8 20 [62,] 38 34 13 12 > (table1 <- table(z[,cat1],z[,cat2])) 28 29 30 31 32 33 34 35 36 37 38 39 27 0 0 0 0 1 0 0 0 0 0 0 0 29 0 0 0 2 0 0 1 0 0 0 0 0 30 1 0 0 0 0 0 0 1 0 0 0 0 31 1 0 0 1 0 1 0 0 0 0 0 0 32 0 0 1 0 2 4 0 0 0 0 1 0 33 0 0 0 0 0 1 1 0 0 2 0 0 34 0 0 1 0 0 2 0 0 1 2 1 0 35 0 1 0 0 0 2 1 0 0 0 0 0 36 0 0 0 0 1 1 1 2 0 0 1 0 37 0 0 0 1 2 0 0 1 1 0 1 1 38 1 0 0 1 2 0 1 1 0 0 1 1 39 0 0 0 1 2 0 1 0 0 0 3 0 41 0 0 0 0 1 0 0 0 0 0 1 0 > (V1<-dimnames(y)[[1]][cat1]) [1] "Connected" > (V2<-dimnames(y)[[1]][cat2]) [1] "Separate" > postscript(file="/var/wessaorg/rcomp/tmp/1xyox1321450504.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/2j2j81321450504.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test data: table1 X-squared = 138.4518, df = 132, p-value = 0.333 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/3m8eq1321450504.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/4urhc1321450504.tab") > > try(system("convert tmp/1xyox1321450504.ps tmp/1xyox1321450504.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 2.183 0.088 2.291