R version 2.13.0 (2011-04-13) Copyright (C) 2011 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(7 + ,7 + ,7 + ,5 + ,5 + ,5 + ,5 + ,5 + ,6 + ,5 + ,4 + ,4 + ,4 + ,5 + ,5 + ,5 + ,5 + ,5 + ,5 + ,5 + ,6 + ,6 + ,6 + ,7 + ,7 + ,4 + ,7 + ,7 + ,6 + ,5 + ,5 + ,6 + ,6 + ,7 + ,7 + ,6 + ,6 + ,5 + ,5 + ,6 + ,5 + ,2 + ,4 + ,6 + ,5 + ,5 + ,6 + ,6 + ,4 + ,5 + ,4 + ,6 + ,6 + ,6 + ,6 + ,6 + ,6 + ,6 + ,7 + ,7 + ,5 + ,5 + ,6 + ,5 + ,3 + ,3 + ,4 + ,3 + ,7 + ,6 + ,6 + ,7 + ,3 + ,5 + ,6 + ,6 + ,5 + ,5 + ,6 + ,6 + ,3 + ,3 + ,4 + ,4 + ,5 + ,5 + ,5 + ,6 + ,2 + ,1 + ,2 + ,2 + ,6 + ,5 + ,6 + ,6 + ,3 + ,4 + ,5 + ,5 + ,6 + ,6 + ,6 + ,7 + ,6 + ,6 + ,6 + ,7 + ,5 + ,4 + ,5 + ,5 + ,5 + ,4 + ,5 + ,6 + ,7 + ,5 + ,5 + ,6 + ,6 + ,4 + ,6 + ,6 + ,5 + ,5 + ,6 + ,6 + ,5 + ,6 + ,5 + ,5 + ,4 + ,3 + ,4 + ,4 + ,4 + ,5 + ,6 + ,5 + ,6 + ,5 + ,5 + ,6 + ,5 + ,3 + ,5 + ,5 + ,5 + ,5 + ,5 + ,5 + ,7 + ,7 + ,7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,5 + ,5 + ,5 + ,5 + ,2 + ,3 + ,2 + ,2 + ,5 + ,6 + ,6 + ,7 + ,7 + ,5 + ,6 + ,7 + ,4 + ,6 + ,5 + ,5 + ,4 + ,5 + ,6 + ,6 + ,7 + ,6 + ,7 + ,5 + ,6 + ,5 + ,5 + ,6 + ,5 + ,6 + ,5 + ,5 + ,5 + ,5 + ,5 + ,6 + ,5 + ,5 + ,6 + ,6 + ,7 + ,6 + ,7 + ,7 + ,6 + ,5 + ,7 + ,6 + ,6 + ,6 + ,6 + ,6 + ,5 + ,5 + ,5 + ,6 + ,2 + ,4 + ,6 + ,6 + ,4 + ,4 + ,4 + ,4 + ,6 + ,4 + ,6 + ,6 + ,5 + ,5 + ,6 + ,4 + ,5 + ,4 + ,4 + ,5 + ,5 + ,5 + ,5 + ,5) + ,dim=c(4 + ,162) + ,dimnames=list(c('Q2' + ,'Q9' + ,'Q16' + ,'Q23') + ,1:162)) > y <- array(NA,dim=c(4,162),dimnames=list(c('Q2','Q9','Q16','Q23'),1:162)) > for (i in 1:dim(x)[1]) + { + for (j in 1:dim(x)[2]) + { + y[i,j] <- as.numeric(x[i,j]) + } + } > par20 = '' > par19 = '' > par18 = '' > par17 = '' > par16 = '' > par15 = '' > par14 = '' > par13 = '' > par12 = '' > par11 = '' > par10 = '' > par9 = '' > par8 = '' > par7 = '' > par6 = '' > par5 = '' > par4 = '' > par3 = 'Exact Pearson Chi-Squared by Simulation' > 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] [,3] [,4] [1,] 7 7 7 5 [2,] 5 5 5 5 [3,] 6 5 4 4 [4,] 4 5 5 5 [5,] 5 5 5 5 [6,] 6 6 6 7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5 5 [86,] 7 6 6 6 [87,] 6 5 6 7 [88,] 4 4 4 5 [89,] 4 5 6 4 [90,] 5 5 5 5 [91,] 3 4 4 4 [92,] 7 7 7 6 [93,] 6 4 6 6 [94,] 6 6 6 5 [95,] 4 4 4 4 [96,] 5 4 5 5 [97,] 6 6 6 7 [98,] 5 3 5 6 [99,] 6 4 4 5 [100,] 6 7 7 6 [101,] 4 5 6 6 [102,] 5 5 5 5 [103,] 6 6 6 6 [104,] 5 5 6 6 [105,] 5 5 5 5 [106,] 4 4 5 5 [107,] 4 5 5 4 [108,] 6 6 5 7 [109,] 5 5 7 7 [110,] 6 5 6 5 [111,] 5 4 7 7 [112,] 6 4 6 6 [113,] 5 5 5 5 [114,] 4 5 4 5 [115,] 6 6 6 7 [116,] 4 5 4 5 [117,] 5 3 3 5 [118,] 5 5 5 5 [119,] 6 3 5 5 [120,] 3 4 5 3 [121,] 5 4 5 5 [122,] 4 5 5 5 [123,] 5 2 5 4 [124,] 5 5 3 4 [125,] 7 7 7 7 [126,] 5 6 6 6 [127,] 7 6 6 6 [128,] 5 5 4 6 [129,] 4 4 4 5 [130,] 6 6 6 5 [131,] 4 3 4 5 [132,] 4 7 6 6 [133,] 4 3 2 2 [134,] 4 4 5 5 [135,] 6 6 5 7 [136,] 6 5 6 6 [137,] 5 6 5 5 [138,] 3 4 4 5 [139,] 6 6 6 6 [140,] 5 6 6 6 [141,] 4 4 5 5 [142,] 5 5 5 5 [143,] 2 3 2 2 [144,] 5 6 6 7 [145,] 7 5 6 7 [146,] 4 6 5 5 [147,] 4 5 6 6 [148,] 7 6 7 5 [149,] 6 5 5 6 [150,] 5 6 5 5 [151,] 5 5 5 6 [152,] 5 5 6 6 [153,] 7 6 7 7 [154,] 6 5 7 6 [155,] 6 6 6 6 [156,] 5 5 5 6 [157,] 2 4 6 6 [158,] 4 4 4 4 [159,] 6 4 6 6 [160,] 5 5 6 4 [161,] 5 4 4 5 [162,] 5 5 5 5 > (table1 <- table(z[,cat1],z[,cat2])) 1 2 3 4 5 6 7 1 0 0 0 1 0 0 0 2 1 1 1 1 0 0 0 3 0 0 3 6 1 0 0 4 0 0 4 12 11 1 1 5 0 2 5 10 27 11 0 6 0 2 1 5 16 22 2 7 0 0 0 1 2 7 5 > (V1<-dimnames(y)[[1]][cat1]) [1] "Q2" > (V2<-dimnames(y)[[1]][cat2]) [1] "Q9" > postscript(file="/var/wessaorg/rcomp/tmp/1t8ck1322834619.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/27buq1322834619.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 = 135.2867, df = NA, p-value = 0.005997 > 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/3fpd41322834619.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/4fu2n1322834619.tab") > > try(system("convert tmp/1t8ck1322834619.ps tmp/1t8ck1322834619.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.326 0.081 1.439