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