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