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