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