R version 2.9.0 (2009-04-17) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 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(5,5,4,3,3,2,4,3,4,5,3,1,4,3,4,4,4,4,4,2,4,3,5,4,4,4,4,4,4,5,4,3,4,4,5,5,5,5,3,3,4,2,4,4,4,4,5,4,5,5,2,4,4,5,4,3,2,4,4,4,5,5,3,3,4,4,4,4,4,4,4,5,3,3,5,4,4,4,4,4,5,3,4,4,5,4,4,4,2,5,5,4,4,5,4,4,4,4,4,5,4,3,4,4,4,2,4,4,2,3,4,5,5,5,4,3,4,4,4,5,4,3,4,3,5,5,4,5,4,5,5,5,4,4,4,2,4,4,4,4,4,4,4,4,2,5,5,5,4,4,3,2,4,4,3,4,2,2,4,4,3,4,5,3,4,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,5,5,5,4,4,4,4,4,2,4,4,5,3,4,4,4,5,4,4,3,4,5,4,5,4,2,4,4,4,4,3,4,5,4,4,5,4,5,5,5,4,3,2,3,3,4,4,4,2,4,4,3,4,3,4,4,4,4,4,3,3,4,4,3,5,5,4,4,4,4,4,4,5,4,4,4,4,4,4,4,5,3,3,2,4,5,2,3,4,4,2,4,4,4,4,3,4,4,4,4,3,3,4,5,2,4,4,4,2,3,4,4,4,2,4,3,4,4,3,3,4,4,5,3,2,4,4,4,4,4,2,2,5,4,1,5,4,4,4,3,4,4,4,4),dim=c(2,162),dimnames=list(c('A','B'),1:162)) > y <- array(NA,dim=c(2,162),dimnames=list(c('A','B'),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 = 'Exact Pearson Chi-Squared by Simulation' > 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,] 5 5 [2,] 4 3 [3,] 3 2 [4,] 4 3 [5,] 4 5 [6,] 3 1 [7,] 4 3 [8,] 4 4 [9,] 4 4 [10,] 4 2 [11,] 4 3 [12,] 5 4 [13,] 4 4 [14,] 4 4 [15,] 4 5 [16,] 4 3 [17,] 4 4 [18,] 5 5 [19,] 5 5 [20,] 3 3 [21,] 4 2 [22,] 4 4 [23,] 4 4 [24,] 5 4 [25,] 5 5 [26,] 2 4 [27,] 4 5 [28,] 4 3 [29,] 2 4 [30,] 4 4 [31,] 5 5 [32,] 3 3 [33,] 4 4 [34,] 4 4 [35,] 4 4 [36,] 4 5 [37,] 3 3 [38,] 5 4 [39,] 4 4 [40,] 4 4 [41,] 5 3 [42,] 4 4 [43,] 5 4 [44,] 4 4 [45,] 2 5 [46,] 5 4 [47,] 4 5 [48,] 4 4 [49,] 4 4 [50,] 4 5 [51,] 4 3 [52,] 4 4 [53,] 4 2 [54,] 4 4 [55,] 2 3 [56,] 4 5 [57,] 5 5 [58,] 4 3 [59,] 4 4 [60,] 4 5 [61,] 4 3 [62,] 4 3 [63,] 5 5 [64,] 4 5 [65,] 4 5 [66,] 5 5 [67,] 4 4 [68,] 4 2 [69,] 4 4 [70,] 4 4 [71,] 4 4 [72,] 4 4 [73,] 2 5 [74,] 5 5 [75,] 4 4 [76,] 3 2 [77,] 4 4 [78,] 3 4 [79,] 2 2 [80,] 4 4 [81,] 3 4 [82,] 5 3 [83,] 4 4 [84,] 4 4 [85,] 4 4 [86,] 4 4 [87,] 4 4 [88,] 4 3 [89,] 4 4 [90,] 4 4 [91,] 5 5 [92,] 5 4 [93,] 4 4 [94,] 4 4 [95,] 2 4 [96,] 4 5 [97,] 3 4 [98,] 4 4 [99,] 5 4 [100,] 4 3 [101,] 4 5 [102,] 4 5 [103,] 4 2 [104,] 4 4 [105,] 4 4 [106,] 3 4 [107,] 5 4 [108,] 4 5 [109,] 4 5 [110,] 5 5 [111,] 4 3 [112,] 2 3 [113,] 3 4 [114,] 4 4 [115,] 2 4 [116,] 4 3 [117,] 4 3 [118,] 4 4 [119,] 4 4 [120,] 4 3 [121,] 3 4 [122,] 4 3 [123,] 5 5 [124,] 4 4 [125,] 4 4 [126,] 4 4 [127,] 5 4 [128,] 4 4 [129,] 4 4 [130,] 4 4 [131,] 5 3 [132,] 3 2 [133,] 4 5 [134,] 2 3 [135,] 4 4 [136,] 2 4 [137,] 4 4 [138,] 4 3 [139,] 4 4 [140,] 4 4 [141,] 3 3 [142,] 4 5 [143,] 2 4 [144,] 4 4 [145,] 2 3 [146,] 4 4 [147,] 4 2 [148,] 4 3 [149,] 4 4 [150,] 3 3 [151,] 4 4 [152,] 5 3 [153,] 2 4 [154,] 4 4 [155,] 4 4 [156,] 2 2 [157,] 5 4 [158,] 1 5 [159,] 4 4 [160,] 4 3 [161,] 4 4 [162,] 4 4 > (table1 <- table(z[,cat1],z[,cat2])) 1 2 3 4 5 1 0 0 0 0 1 2 0 2 4 7 2 3 1 3 5 6 0 4 0 6 20 62 17 5 0 0 4 10 12 > (V1<-dimnames(y)[[1]][cat1]) [1] "A" > (V2<-dimnames(y)[[1]][cat2]) [1] "B" > postscript(file="/var/www/html/rcomp/tmp/1riu91290777888.ps",horizontal=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/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/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/html/rcomp/tmp/2d0tx1290777888.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test with simulated p-value (based on 2000 replicates) data: table1 X-squared = 38.0421, df = NA, p-value = 0.005997 > if (par3 == 'McNemar Chi-Squared') { + (cst <- mcnemar.test(table1)) + } > if (par3 != 'McNemar Chi-Squared') { + 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/html/rcomp/tmp/3y1r31290777888.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) > a<-table.element(a, 'Chi Square Statistic', 1, TRUE) > a<-table.element(a, round(cst$statistic, digits=2), 1,FALSE) > a<-table.row.end(a) > if(!simulate.p.value){ + 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/html/rcomp/tmp/4kj891290777888.tab") > > try(system("convert tmp/1riu91290777888.ps tmp/1riu91290777888.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.902 0.228 1.911