R version 2.12.1 (2010-12-16) 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(38 + ,14 + ,32 + ,18 + ,35 + ,11 + ,33 + ,12 + ,37 + ,16 + ,29 + ,18 + ,31 + ,14 + ,36 + ,14 + ,35 + ,15 + ,38 + ,15 + ,31 + ,17 + ,34 + ,19 + ,35 + ,10 + ,38 + ,16 + ,37 + ,18 + ,33 + ,14 + ,32 + ,14 + ,38 + ,17 + ,38 + ,14 + ,32 + ,16 + ,33 + ,18 + ,31 + ,11 + ,38 + ,14 + ,39 + ,12 + ,32 + ,17 + ,32 + ,9 + ,35 + ,16 + ,37 + ,14 + ,33 + ,15 + ,33 + ,11 + ,28 + ,16 + ,32 + ,13 + ,31 + ,17 + ,37 + ,15 + ,30 + ,14 + ,33 + ,16 + ,31 + ,9 + ,33 + ,15 + ,31 + ,17 + ,33 + ,13 + ,32 + ,15 + ,33 + ,16 + ,32 + ,16 + ,33 + ,12 + ,28 + ,12 + ,35 + ,11 + ,39 + ,15 + ,34 + ,15 + ,38 + ,17 + ,32 + ,13 + ,38 + ,16 + ,30 + ,14 + ,33 + ,11 + ,38 + ,12 + ,32 + ,12 + ,32 + ,15 + ,34 + ,16 + ,34 + ,15 + ,36 + ,12 + ,34 + ,12 + ,28 + ,8 + ,34 + ,13 + ,35 + ,11 + ,35 + ,14 + ,31 + ,15 + ,37 + ,10 + ,35 + ,11 + ,27 + ,12 + ,40 + ,15 + ,37 + ,15 + ,36 + ,14 + ,38 + ,16 + ,39 + ,15 + ,41 + ,15 + ,27 + ,13 + ,30 + ,12 + ,37 + ,17 + ,31 + ,13 + ,31 + ,15 + ,27 + ,13 + ,36 + ,15 + ,38 + ,16 + ,37 + ,15 + ,33 + ,16 + ,34 + ,15 + ,31 + ,14 + ,39 + ,15 + ,34 + ,14 + ,32 + ,13 + ,33 + ,7 + ,36 + ,17 + ,32 + ,13 + ,41 + ,15 + ,28 + ,14 + ,30 + ,13 + ,36 + ,16 + ,35 + ,12 + ,31 + ,14 + ,34 + ,17 + ,36 + ,15 + ,36 + ,17 + ,35 + ,12 + ,37 + ,16 + ,28 + ,11 + ,39 + ,15 + ,32 + ,9 + ,35 + ,16 + ,39 + ,15 + ,35 + ,10 + ,42 + ,10 + ,34 + ,15 + ,33 + ,11 + ,41 + ,13 + ,33 + ,14 + ,34 + ,18 + ,32 + ,16 + ,40 + ,14 + ,40 + ,14 + ,35 + ,14 + ,36 + ,14 + ,37 + ,12 + ,27 + ,14 + ,39 + ,15 + ,38 + ,15 + ,31 + ,15 + ,33 + ,13 + ,32 + ,17 + ,39 + ,17 + ,36 + ,19 + ,33 + ,15 + ,33 + ,13 + ,32 + ,9 + ,37 + ,15 + ,30 + ,15 + ,38 + ,15 + ,29 + ,16 + ,22 + ,11 + ,35 + ,14 + ,35 + ,11 + ,34 + ,15 + ,35 + ,13 + ,34 + ,15 + ,34 + ,16 + ,35 + ,14 + ,23 + ,15 + ,31 + ,16 + ,27 + ,16 + ,36 + ,11 + ,31 + ,12 + ,32 + ,9 + ,39 + ,16 + ,37 + ,13 + ,38 + ,16 + ,39 + ,12 + ,34 + ,9 + ,31 + ,13 + ,32 + ,13 + ,37 + ,14 + ,36 + ,19 + ,32 + ,13 + ,35 + ,12 + ,36 + ,13) + ,dim=c(2 + ,162) + ,dimnames=list(c('Separate' + ,'Happiness ') + ,1:162)) > y <- array(NA,dim=c(2,162),dimnames=list(c('Separate','Happiness '),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,] 38 14 [2,] 32 18 [3,] 35 11 [4,] 33 12 [5,] 37 16 [6,] 29 18 [7,] 31 14 [8,] 36 14 [9,] 35 15 [10,] 38 15 [11,] 31 17 [12,] 34 19 [13,] 35 10 [14,] 38 16 [15,] 37 18 [16,] 33 14 [17,] 32 14 [18,] 38 17 [19,] 38 14 [20,] 32 16 [21,] 33 18 [22,] 31 11 [23,] 38 14 [24,] 39 12 [25,] 32 17 [26,] 32 9 [27,] 35 16 [28,] 37 14 [29,] 33 15 [30,] 33 11 [31,] 28 16 [32,] 32 13 [33,] 31 17 [34,] 37 15 [35,] 30 14 [36,] 33 16 [37,] 31 9 [38,] 33 15 [39,] 31 17 [40,] 33 13 [41,] 32 15 [42,] 33 16 [43,] 32 16 [44,] 33 12 [45,] 28 12 [46,] 35 11 [47,] 39 15 [48,] 34 15 [49,] 38 17 [50,] 32 13 [51,] 38 16 [52,] 30 14 [53,] 33 11 [54,] 38 12 [55,] 32 12 [56,] 32 15 [57,] 34 16 [58,] 34 15 [59,] 36 12 [60,] 34 12 [61,] 28 8 [62,] 34 13 [63,] 35 11 [64,] 35 14 [65,] 31 15 [66,] 37 10 [67,] 35 11 [68,] 27 12 [69,] 40 15 [70,] 37 15 [71,] 36 14 [72,] 38 16 [73,] 39 15 [74,] 41 15 [75,] 27 13 [76,] 30 12 [77,] 37 17 [78,] 31 13 [79,] 31 15 [80,] 27 13 [81,] 36 15 [82,] 38 16 [83,] 37 15 [84,] 33 16 [85,] 34 15 [86,] 31 14 [87,] 39 15 [88,] 34 14 [89,] 32 13 [90,] 33 7 [91,] 36 17 [92,] 32 13 [93,] 41 15 [94,] 28 14 [95,] 30 13 [96,] 36 16 [97,] 35 12 [98,] 31 14 [99,] 34 17 [100,] 36 15 [101,] 36 17 [102,] 35 12 [103,] 37 16 [104,] 28 11 [105,] 39 15 [106,] 32 9 [107,] 35 16 [108,] 39 15 [109,] 35 10 [110,] 42 10 [111,] 34 15 [112,] 33 11 [113,] 41 13 [114,] 33 14 [115,] 34 18 [116,] 32 16 [117,] 40 14 [118,] 40 14 [119,] 35 14 [120,] 36 14 [121,] 37 12 [122,] 27 14 [123,] 39 15 [124,] 38 15 [125,] 31 15 [126,] 33 13 [127,] 32 17 [128,] 39 17 [129,] 36 19 [130,] 33 15 [131,] 33 13 [132,] 32 9 [133,] 37 15 [134,] 30 15 [135,] 38 15 [136,] 29 16 [137,] 22 11 [138,] 35 14 [139,] 35 11 [140,] 34 15 [141,] 35 13 [142,] 34 15 [143,] 34 16 [144,] 35 14 [145,] 23 15 [146,] 31 16 [147,] 27 16 [148,] 36 11 [149,] 31 12 [150,] 32 9 [151,] 39 16 [152,] 37 13 [153,] 38 16 [154,] 39 12 [155,] 34 9 [156,] 31 13 [157,] 32 13 [158,] 37 14 [159,] 36 19 [160,] 32 13 [161,] 35 12 [162,] 36 13 > (table1 <- table(z[,cat1],z[,cat2])) 7 8 9 10 11 12 13 14 15 16 17 18 19 22 0 0 0 0 1 0 0 0 0 0 0 0 0 23 0 0 0 0 0 0 0 0 1 0 0 0 0 27 0 0 0 0 0 1 2 1 0 1 0 0 0 28 0 1 0 0 1 1 0 1 0 1 0 0 0 29 0 0 0 0 0 0 0 0 0 1 0 1 0 30 0 0 0 0 0 1 1 2 1 0 0 0 0 31 0 0 1 0 1 1 2 3 3 1 3 0 0 32 0 0 4 0 0 1 6 1 2 3 2 1 0 33 1 0 0 0 3 2 3 2 3 3 0 1 0 34 0 0 1 0 0 1 1 1 6 2 1 1 1 35 0 0 0 2 5 3 1 4 1 2 0 0 0 36 0 0 0 0 1 1 1 3 2 1 2 0 2 37 0 0 0 1 0 1 1 2 4 2 1 1 0 38 0 0 0 0 0 1 0 3 3 5 2 0 0 39 0 0 0 0 0 2 0 0 6 1 1 0 0 40 0 0 0 0 0 0 0 2 1 0 0 0 0 41 0 0 0 0 0 0 1 0 2 0 0 0 0 42 0 0 0 1 0 0 0 0 0 0 0 0 0 > (V1<-dimnames(y)[[1]][cat1]) [1] "Separate" > (V2<-dimnames(y)[[1]][cat2]) [1] "Happiness\r\r\r" > postscript(file="/var/www/rcomp/tmp/1cob11321444287.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) Warning messages: 1: In grid.Call.graphics("L_text", as.graphicsAnnot(x$label), x$x, : font width unknown for character 0xd 2: In grid.Call.graphics("L_text", as.graphicsAnnot(x$label), x$x, : font width unknown for character 0xd 3: In grid.Call.graphics("L_text", as.graphicsAnnot(x$label), x$x, : font width unknown for character 0xd > 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/2bre11321444287.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/www/rcomp/tmp/3lwhq1321444287.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/4yiww1321444287.tab") > > try(system("convert tmp/1cob11321444287.ps tmp/1cob11321444287.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 3.232 0.100 3.317