R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i686-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(2,0,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,1,0,0,2,0,0,1,0,1,1,0,0,2,0,0,1,0,0,1,0,0,2,0,0,1,0,1,2,0,1,2,0,0,2,0,0,1,0,1,2,0,1,1,0,0,1,0,1,1,0,1,1,0,1,2,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,0,0,1,0,0,1,0,0,2,0,1,1,0,0,1,0,0,2,0,0,1,0,1,1,0,1,2,0,0,1,0,1,1,0,1,1,0,1,2,0,0,1,0,0,1,0,1,1,0,0,1,0,1,1,0,1,1,0,0,2,0,0,2,0,0,1,0,1,1,0,0,1,0,0,2,0,1,1,0,1,1,0,1,1,0,1,2,0,1,2,0,1,1,0,0,1,0,0,2,0,1,1,0,0,1,0,0,2,0,0,1,0,0,1,0,1,1,0,0,1,0,0,1,0,1,1,0,1,1,0,0,1,0,1,2,0,1,1,0,1,1,0,1,2,0,1,2,0,0,1,0,0,1,0,1,1,0,0,1,0,0,1,0,1,1,0,0,0,0,1,0,1,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,1,0,1,1,0,0,0,0,0,1,0,0,0,0,1,1,0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0),dim=c(3,154),dimnames=list(c('T40','T20','Outcome'),1:154)) > y <- array(NA,dim=c(3,154),dimnames=list(c('T40','T20','Outcome'),1:154)) > 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 = 'Pearson Chi-Squared' > 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] [1,] 2 0 1 [2,] 1 0 0 [3,] 1 0 0 [4,] 1 0 0 [5,] 1 0 0 [6,] 1 0 1 [7,] 1 0 0 [8,] 2 0 0 [9,] 1 0 1 [10,] 1 0 0 [11,] 2 0 0 [12,] 1 0 0 [13,] 1 0 0 [14,] 2 0 0 [15,] 1 0 1 [16,] 2 0 1 [17,] 2 0 0 [18,] 2 0 0 [19,] 1 0 1 [20,] 2 0 1 [21,] 1 0 0 [22,] 1 0 1 [23,] 1 0 1 [24,] 1 0 1 [25,] 2 0 1 [26,] 1 0 0 [27,] 1 0 1 [28,] 1 0 0 [29,] 1 0 1 [30,] 1 0 0 [31,] 1 0 0 [32,] 1 0 0 [33,] 1 0 0 [34,] 2 0 1 [35,] 1 0 0 [36,] 1 0 0 [37,] 2 0 0 [38,] 1 0 1 [39,] 1 0 1 [40,] 2 0 0 [41,] 1 0 1 [42,] 1 0 1 [43,] 1 0 1 [44,] 2 0 0 [45,] 1 0 0 [46,] 1 0 1 [47,] 1 0 0 [48,] 1 0 1 [49,] 1 0 1 [50,] 1 0 0 [51,] 2 0 0 [52,] 2 0 0 [53,] 1 0 1 [54,] 1 0 0 [55,] 1 0 0 [56,] 2 0 1 [57,] 1 0 1 [58,] 1 0 1 [59,] 1 0 1 [60,] 2 0 1 [61,] 2 0 1 [62,] 1 0 0 [63,] 1 0 0 [64,] 2 0 1 [65,] 1 0 0 [66,] 1 0 0 [67,] 2 0 0 [68,] 1 0 0 [69,] 1 0 1 [70,] 1 0 0 [71,] 1 0 0 [72,] 1 0 1 [73,] 1 0 1 [74,] 1 0 0 [75,] 1 0 1 [76,] 2 0 1 [77,] 1 0 1 [78,] 1 0 1 [79,] 2 0 1 [80,] 2 0 0 [81,] 1 0 0 [82,] 1 0 1 [83,] 1 0 0 [84,] 1 0 0 [85,] 1 0 1 [86,] 1 0 0 [87,] 0 0 1 [88,] 0 1 1 [89,] 0 0 0 [90,] 0 0 1 [91,] 0 0 0 [92,] 0 1 0 [93,] 0 0 0 [94,] 0 0 0 [95,] 0 1 0 [96,] 0 0 1 [97,] 0 1 0 [98,] 0 0 0 [99,] 0 0 0 [100,] 0 0 1 [101,] 0 0 1 [102,] 0 0 0 [103,] 0 0 0 [104,] 0 0 0 [105,] 0 1 0 [106,] 0 0 0 [107,] 0 0 0 [108,] 0 1 0 [109,] 0 0 0 [110,] 0 0 0 [111,] 0 1 0 [112,] 0 1 0 [113,] 0 0 0 [114,] 0 1 0 [115,] 0 0 0 [116,] 0 0 0 [117,] 0 0 1 [118,] 0 0 0 [119,] 0 0 0 [120,] 0 0 1 [121,] 0 0 0 [122,] 0 0 0 [123,] 0 1 0 [124,] 0 0 1 [125,] 0 0 1 [126,] 0 1 0 [127,] 0 0 0 [128,] 0 0 1 [129,] 0 0 0 [130,] 0 0 1 [131,] 0 0 0 [132,] 0 0 1 [133,] 0 0 0 [134,] 0 0 0 [135,] 0 0 0 [136,] 0 0 0 [137,] 0 0 1 [138,] 0 1 1 [139,] 0 1 0 [140,] 0 0 0 [141,] 0 0 1 [142,] 0 1 1 [143,] 0 0 0 [144,] 0 0 1 [145,] 0 0 0 [146,] 0 1 1 [147,] 0 1 0 [148,] 0 1 0 [149,] 0 0 0 [150,] 0 0 1 [151,] 0 0 1 [152,] 0 0 0 [153,] 0 0 0 [154,] 0 0 0 > (table1 <- table(z[,cat1],z[,cat2])) 0 1 0 51 17 1 63 0 2 23 0 > (V1<-dimnames(y)[[1]][cat1]) [1] "T40" > (V2<-dimnames(y)[[1]][cat2]) [1] "T20" > postscript(file="/var/fisher/rcomp/tmp/19g5a1356033829.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/fisher/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/fisher/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/fisher/rcomp/tmp/2i89j1356033829.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test data: table1 X-squared = 24.1679, df = 2, p-value = 5.65e-06 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/fisher/rcomp/tmp/3tr3c1356033829.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/fisher/rcomp/tmp/49ehn1356033829.tab") > > try(system("convert tmp/19g5a1356033829.ps tmp/19g5a1356033829.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.633 0.395 2.005