R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-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('B' + ,'B' + ,'A' + ,'C' + ,'D' + ,'A' + ,'D' + ,'B' + ,'A' + ,'A' + ,'A' + ,'B' + ,'B' + ,'A' + ,'B' + ,'C' + ,'B' + ,'D' + ,'B' + ,'B' + ,'A' + ,'D' + ,'A' + ,'D' + ,'D' + ,'A' + ,'A' + ,'A' + ,'A' + ,'D' + ,'B' + ,'A' + ,'B' + ,'A' + ,'A' + ,'C' + ,'B' + ,'D' + ,'A' + ,'B' + ,'A' + ,'D' + ,'D' + ,'A' + ,'B' + ,'B' + ,'D' + ,'A' + ,'A' + ,'C' + ,'D' + ,'D' + ,'A' + ,'C' + ,'B' + ,'A' + ,'B' + ,'A' + ,'D' + ,'B' + ,'A' + ,'D' + ,'C' + ,'A' + ,'A' + ,'D' + ,'B' + ,'C' + ,'B' + ,'B' + ,'A' + ,'D' + ,'D' + ,'A' + ,'B' + ,'B' + ,'A' + ,'D' + ,'C' + ,'D' + ,'B' + ,'D' + ,'A' + ,'A' + ,'A' + ,'D' + ,'D' + ,'A' + ,'D' + ,'C' + ,'D' + ,'B' + ,'B' + ,'D' + ,'B' + ,'C' + ,'A' + ,'A' + ,'C' + ,'C' + ,'A' + ,'D' + ,'B' + ,'A' + ,'D' + ,'A' + ,'D' + ,'A' + ,'D' + ,'C' + ,'B' + ,'B' + ,'A' + ,'B' + ,'B' + ,'D' + ,'D' + ,'D' + ,'D' + ,'A' + ,'D' + ,'A' + ,'C' + ,'B' + ,'D' + ,'B' + ,'B' + ,'A' + ,'B' + ,'B' + ,'D' + ,'C' + ,'D' + ,'A' + ,'D' + ,'B' + ,'B' + ,'B' + ,'B' + ,'A' + ,'B' + ,'B' + ,'A' + ,'A' + ,'B' + ,'B' + ,'B' + ,'D' + ,'C' + ,'C' + ,'D' + ,'A' + ,'A' + ,'B' + ,'C' + ,'A' + ,'B' + ,'B' + ,'C' + ,'D' + ,'B' + ,'C' + ,'A' + ,'D' + ,'B' + ,'D' + ,'A' + ,'B' + ,'B' + ,'B' + ,'B' + ,'B' + ,'B' + ,'B' + ,'B' + ,'B' + ,'C' + ,'A' + ,'D' + ,'A' + ,'A' + ,'B' + ,'C' + ,'A' + ,'B' + ,'B' + ,'B' + ,'A' + ,'C' + ,'D' + ,'A' + ,'C' + ,'D' + ,'A' + ,'B' + ,'C' + ,'A' + ,'C' + ,'B' + ,'D' + ,'A' + ,'D' + ,'D' + ,'A' + ,'A' + ,'B' + ,'D' + ,'C' + ,'B' + ,'A' + ,'D' + ,'A' + ,'A' + ,'C' + ,'B' + ,'A' + ,'D' + ,'A' + ,'D' + ,'A' + ,'B' + ,'A' + ,'D' + ,'A' + ,'C' + ,'C' + ,'B' + ,'A' + ,'A' + ,'B' + ,'A' + ,'D' + ,'B' + ,'A' + ,'B' + ,'B' + ,'B' + ,'D' + ,'B' + ,'A' + ,'D' + ,'A' + ,'B' + ,'A' + ,'B' + ,'C' + ,'B' + ,'D' + ,'B' + ,'C' + ,'C' + ,'C' + ,'A' + ,'D' + ,'A' + ,'D' + ,'A' + ,'C' + ,'B' + ,'B' + ,'C' + ,'C' + ,'D' + ,'A' + ,'B' + ,'D' + ,'B' + ,'A' + ,'B' + ,'B' + ,'A' + ,'A' + ,'D' + ,'A' + ,'B' + ,'A' + ,'D' + ,'A' + ,'B' + ,'C' + ,'C' + ,'B' + ,'B' + ,'D' + ,'A' + ,'A' + ,'B' + ,'B' + ,'B' + ,'B' + ,'A' + ,'C' + ,'A' + ,'B' + ,'D' + ,'B' + ,'D' + ,'C' + ,'D' + ,'A' + ,'A' + ,'B' + ,'C' + ,'A' + ,'A' + ,'D' + ,'D' + ,'B' + ,'D' + ,'A' + ,'C' + ,'A' + ,'C' + ,'A' + ,'B' + ,'A' + ,'A' + ,'C' + ,'C' + ,'D' + ,'D' + ,'A' + ,'C' + ,'A') + ,dim=c(2 + ,162) + ,dimnames=list(c('Happinness' + ,'Depression') + ,1:162)) > y <- array(NA,dim=c(2,162),dimnames=list(c('Happinness','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]) + } + } There were 50 or more warnings (use warnings() to see the first 50) > par3 = 'Pearson Chi-Squared' > par2 = '2' > par1 = '1' > main = 'Association Plot' > 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,] "B" "B" [2,] "A" "C" [3,] "D" "A" [4,] "D" "B" [5,] "A" "A" [6,] "A" "B" [7,] "B" "A" [8,] "B" "C" [9,] "B" "D" [10,] "B" "B" [11,] "A" "D" [12,] "A" "D" [13,] "D" "A" [14,] "A" "A" [15,] "A" "D" [16,] "B" "A" [17,] "B" "A" [18,] "A" "C" [19,] "B" "D" [20,] "A" "B" [21,] "A" "D" [22,] "D" "A" [23,] "B" "B" [24,] "D" "A" [25,] "A" "C" [26,] "D" "D" [27,] "A" "C" [28,] "B" "A" [29,] "B" "A" [30,] "D" "B" [31,] "A" "D" [32,] "C" "A" [33,] "A" "D" [34,] "B" "C" [35,] "B" "B" [36,] "A" "D" [37,] "D" "A" [38,] "B" "B" [39,] "A" "D" [40,] "C" "D" [41,] "B" "D" [42,] "A" "A" [43,] "A" "D" [44,] "D" "A" [45,] "D" "C" [46,] "D" "B" [47,] "B" "D" [48,] "B" "C" [49,] "A" "A" [50,] "C" "C" [51,] "A" "D" [52,] "B" "A" [53,] "D" "A" [54,] "D" "A" [55,] "D" "C" [56,] "B" "B" [57,] "A" "B" [58,] "B" "D" [59,] "D" "D" [60,] "D" "A" [61,] "D" "A" [62,] "C" "B" [63,] "D" "B" [64,] "B" "A" [65,] "B" "B" [66,] "D" "C" [67,] "D" "A" [68,] "D" "B" [69,] "B" "B" [70,] "B" "A" [71,] "B" "B" [72,] "A" "A" [73,] "B" "B" [74,] "B" "D" [75,] "C" "C" [76,] "D" "A" [77,] "A" "B" [78,] "C" "A" [79,] "B" "B" [80,] "C" "D" [81,] "B" "C" [82,] "A" "D" [83,] "B" "D" [84,] "A" "B" [85,] "B" "B" [86,] "B" "B" [87,] "B" "B" [88,] "B" "B" [89,] "C" "A" [90,] "D" "A" [91,] "A" "B" [92,] "C" "A" [93,] "B" "B" [94,] "B" "A" [95,] "C" "D" [96,] "A" "C" [97,] "D" "A" [98,] "B" "C" [99,] "A" "C" [100,] "B" "D" [101,] "A" "D" [102,] "D" "A" [103,] "A" "B" [104,] "D" "C" [105,] "B" "A" [106,] "D" "A" [107,] "A" "C" [108,] "B" "A" [109,] "D" "A" [110,] "D" "A" [111,] "B" "A" [112,] "D" "A" [113,] "C" "C" [114,] "B" "A" [115,] "A" "B" [116,] "A" "D" [117,] "B" "A" [118,] "B" "B" [119,] "B" "D" [120,] "B" "A" [121,] "D" "A" [122,] "B" "A" [123,] "B" "C" [124,] "B" "D" [125,] "B" "C" [126,] "C" "C" [127,] "A" "D" [128,] "A" "D" [129,] "A" "C" [130,] "B" "B" [131,] "C" "C" [132,] "D" "A" [133,] "B" "D" [134,] "B" "A" [135,] "B" "B" [136,] "A" "A" [137,] "D" "A" [138,] "B" "A" [139,] "D" "A" [140,] "B" "C" [141,] "C" "B" [142,] "B" "D" [143,] "A" "A" [144,] "B" "B" [145,] "B" "B" [146,] "A" "C" [147,] "A" "B" [148,] "D" "B" [149,] "D" "C" [150,] "D" "A" [151,] "A" "B" [152,] "C" "A" [153,] "A" "D" [154,] "D" "B" [155,] "D" "A" [156,] "C" "A" [157,] "C" "A" [158,] "B" "A" [159,] "A" "C" [160,] "C" "D" [161,] "D" "A" [162,] "C" "A" > (table1 <- table(z[,cat1],z[,cat2])) A B C D A 7 10 10 16 B 19 21 8 12 C 8 2 5 4 D 26 7 5 2 > (V1<-dimnames(y)[[1]][cat1]) [1] "Happinness" > (V2<-dimnames(y)[[1]][cat2]) [1] "Depression" > postscript(file="/var/wessaorg/rcomp/tmp/1kh7b1355062889.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/2y7lq1355062889.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test data: table1 X-squared = 32.1927, df = 9, p-value = 0.0001844 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/3tef51355062889.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/4dul31355062889.tab") > > try(system("convert tmp/1kh7b1355062889.ps tmp/1kh7b1355062889.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.554 0.213 1.748