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