R version 3.4.4 (2018-03-15) -- "Someone to Lean On" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-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. > source('/home/pw/wessanet/cretab') > > > > myrfcuid = 'q1204881-2018' > > x <- array(list('man',"'bach'",'vrouw',"'bach'",'man',"'bach'",'vrouw',"'bach'",'man',"'bach'",'vrouw',"'bach'",'man',"'bach'",'vrouw',"'bach'",'man',"'bach'",'vrouw',"'bach'",'man',"'scha'",'vrouw',"'scha'",'man',"'scha'",'vrouw',"'scha'",'man',"'scha'",'vrouw',"'scha'",'man',"'scha'",'vrouw',"'scha'",'man',"'scha'",'vrouw',"'scha'"),dim=c(2,20),dimnames=list(c('GeslachtLabel','GroepLabel'),1:20)) > y <- array(NA,dim=c(2,20),dimnames=list(c('GeslachtLabel','GroepLabel'),1:20)) > for (i in 1:dim(x)[1]) + { + for (j in 1:dim(x)[2]) + { + y[i,j] <- as.numeric(x[i,j]) + } + } There were 40 warnings (use warnings() to see them) > par3 = 'Exact Pearson Chi-Squared by Simulation' > par2 = '2' > par1 = '1' > main = 'Association Plot' > par3 <- 'Exact Pearson Chi-Squared by Simulation' > par2 <- '2' > par1 <- '1' > #'GNU S' R Code compiled by R2WASP v. 1.2.327 (Thu, 22 Sep 2016 16:59:07 +0200) > #Author: root > #To cite this work: Wessa P. (2016), Chi-Squared Test, McNemar Test, and Fisher Exact Test (v1.0.9) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_chi_squared_tests.wasp/ > #Source of accompanying publication: > # > library(vcd) Loading required package: grid > 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,] "man" "'bach'" [2,] "vrouw" "'bach'" [3,] "man" "'bach'" [4,] "vrouw" "'bach'" [5,] "man" "'bach'" [6,] "vrouw" "'bach'" [7,] "man" "'bach'" [8,] "vrouw" "'bach'" [9,] "man" "'bach'" [10,] "vrouw" "'bach'" [11,] "man" "'scha'" [12,] "vrouw" "'scha'" [13,] "man" "'scha'" [14,] "vrouw" "'scha'" [15,] "man" "'scha'" [16,] "vrouw" "'scha'" [17,] "man" "'scha'" [18,] "vrouw" "'scha'" [19,] "man" "'scha'" [20,] "vrouw" "'scha'" > (table1 <- table(z[,cat1],z[,cat2])) 'bach' 'scha' man 5 5 vrouw 5 5 > (V1<-dimnames(y)[[1]][cat1]) [1] "GeslachtLabel" > (V2<-dimnames(y)[[1]][cat2]) [1] "GroepLabel" > postscript(file="/home/pw/wessanet/rcomp/tmp/1p9vq1548111437.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 legend(residuals, gpfun, residuals_type) : All residuals are zero. > dev.off() null device 1 > > 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="/home/pw/wessanet/rcomp/tmp/2icwe1548111437.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 = 0, df = NA, p-value = 1 > 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="/home/pw/wessanet/rcomp/tmp/3uo0n1548111437.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="/home/pw/wessanet/rcomp/tmp/461gy1548111437.tab") > > try(system("convert /home/pw/wessanet/rcomp/tmp/1p9vq1548111437.ps /home/pw/wessanet/rcomp/tmp/1p9vq1548111437.png",intern=TRUE)) character(0) > > proc.time() user system elapsed 1.712 0.132 1.843