R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" Copyright (C) 2013 The R Foundation for Statistical Computing 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('Boys' + ,'Not_bul' + ,'Boys' + ,'Boys' + ,'Girls' + ,'Not_bul' + ,'Boys' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Both' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Boys' + ,'Girls' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Both' + ,'Boys' + ,'Boys' + ,'Boys' + ,'Not_bul' + ,'Both' + ,'Both' + ,'Both' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Girls' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Girls' + ,'Boys' + ,'Both' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Girls' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Boys' + ,'Boys' + ,'Girls' + ,'Not_bul' + ,'Girls' + ,'Boys' + ,'Girls' + ,'Not_bul' + ,'Girls' + ,'Not_bul' + ,'Girls' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Both' + ,'Not_bul' + ,'Both' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Both' + ,'Boys' + ,'Both' + ,'Boys' + ,'Both' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Girls' + ,'Not_bul' + ,'Girls' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Both' + ,'Boys' + ,'Girls' + ,'Boys' + ,'Girls' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Girls' + ,'Boys' + ,'Boys' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Girls' + ,'Not_bul' + ,'Boys' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Girls' + ,'Boys' + ,'Girls' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Boys' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Boys' + ,'Boys' + ,'Boys' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Boys' + ,'Girls' + ,'Not_bul' + ,'Both' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Boys' + ,'Boys' + ,'Both' + ,'Girls' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Girls' + ,'Not_bul' + ,'Boys' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Both' + ,'Boys' + ,'Both' + ,'Both' + ,'Boys' + ,'Not_bul' + ,'Not_bul' + ,'Not_bul' + ,'Both' + ,'Not_bul') + ,dim=c(2 + ,105) + ,dimnames=list(c('girls' + ,'boys') + ,1:105)) > y <- array(NA,dim=c(2,105),dimnames=list(c('girls','boys'),1:105)) > 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-Square' > par2 = '2' > par1 = '1' > par3 <- 'Pearson Chi-Square' > par2 <- '2' > par1 <- '1' > #'GNU S' R Code compiled by R2WASP v. 1.2.291 () > #Author: aston2 > #To cite this work: Ian E. Holliday, 2012, STARS Bullying Study (v1.0.3) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/Ian.Holliday/rwasp_STARS_Bullying_Study_alt.wasp/ > #Source of accompanying publication: > # > cat1 <- as.numeric(par1) # > cat2<- as.numeric(par2) # > simulate.p.value=FALSE > if (par3 == 'Exact Pearson Chi Square by simulation') simulate.p.value=TRUE > x <- t(x) > (z <- array(unlist(x),dim=c(length(x[,1]),length(x[1,])))) [,1] [,2] [1,] "Boys" "Not_bul" [2,] "Boys" "Boys" [3,] "Girls" "Not_bul" [4,] "Boys" "Boys" [5,] "Not_bul" "Boys" [6,] "Not_bul" "Boys" [7,] "Not_bul" "Boys" [8,] "Both" "Boys" [9,] "Not_bul" "Boys" [10,] "Not_bul" "Boys" [11,] "Not_bul" "Not_bul" [12,] "Boys" "Boys" [13,] "Girls" "Not_bul" [14,] "Not_bul" "Boys" [15,] "Both" "Boys" [16,] "Boys" "Boys" [17,] "Not_bul" "Both" [18,] "Both" "Both" [19,] "Not_bul" "Not_bul" [20,] "Not_bul" "Boys" [21,] "Girls" "Not_bul" [22,] "Not_bul" "Not_bul" [23,] "Not_bul" "Not_bul" [24,] "Not_bul" "Boys" [25,] "Girls" "Boys" [26,] "Both" "Not_bul" [27,] "Not_bul" "Not_bul" [28,] "Boys" "Not_bul" [29,] "Not_bul" "Boys" [30,] "Girls" "Boys" [31,] "Not_bul" "Boys" [32,] "Boys" "Boys" [33,] "Girls" "Not_bul" [34,] "Girls" "Boys" [35,] "Girls" "Not_bul" [36,] "Girls" "Not_bul" [37,] "Girls" "Boys" [38,] "Not_bul" "Not_bul" [39,] "Both" "Not_bul" [40,] "Both" "Boys" [41,] "Not_bul" "Boys" [42,] "Not_bul" "Boys" [43,] "Both" "Boys" [44,] "Both" "Boys" [45,] "Both" "Not_bul" [46,] "Not_bul" "Not_bul" [47,] "Girls" "Not_bul" [48,] "Girls" "Boys" [49,] "Not_bul" "Not_bul" [50,] "Not_bul" "Boys" [51,] "Not_bul" "Not_bul" [52,] "Both" "Boys" [53,] "Girls" "Boys" [54,] "Girls" "Boys" [55,] "Not_bul" "Boys" [56,] "Not_bul" "Boys" [57,] "Girls" "Boys" [58,] "Boys" "Boys" [59,] "Not_bul" "Boys" [60,] "Girls" "Not_bul" [61,] "Boys" "Boys" [62,] "Not_bul" "Boys" [63,] "Not_bul" "Not_bul" [64,] "Boys" "Boys" [65,] "Not_bul" "Not_bul" [66,] "Not_bul" "Not_bul" [67,] "Girls" "Boys" [68,] "Girls" "Not_bul" [69,] "Not_bul" "Boys" [70,] "Boys" "Boys" [71,] "Not_bul" "Boys" [72,] "Boys" "Boys" [73,] "Boys" "Boys" [74,] "Not_bul" "Boys" [75,] "Not_bul" "Boys" [76,] "Girls" "Not_bul" [77,] "Both" "Not_bul" [78,] "Not_bul" "Not_bul" [79,] "Boys" "Boys" [80,] "Boys" "Both" [81,] "Girls" "Boys" [82,] "Not_bul" "Not_bul" [83,] "Girls" "Not_bul" [84,] "Boys" "Boys" [85,] "Not_bul" "Not_bul" [86,] "Not_bul" "Boys" [87,] "Not_bul" "Not_bul" [88,] "Not_bul" "Not_bul" [89,] "Not_bul" "Not_bul" [90,] "Not_bul" "Not_bul" [91,] "Boys" "Not_bul" [92,] "Not_bul" "Both" [93,] "Boys" "Both" [94,] "Both" "Boys" [95,] "Not_bul" "Not_bul" [96,] "Not_bul" "Both" [97,] "Not_bul" "Boys" [98,] "Not_bul" "Boys" [99,] "Boys" "Girls" [100,] "Not_bul" "Boys" [101,] "Boys" "Not_bul" [102,] "Boys" "Not_bul" [103,] "Boys" "Not_bul" [104,] "Boys" "Both" [105,] "Boys" "Not_bul" > (table1 <- table(z[,cat1],z[,cat2])) Both Boys Girls Not_bul Both 1 7 0 4 Boys 3 13 1 7 Girls 0 10 0 11 Not_bul 3 25 0 20 > (V1<-dimnames(y)[[1]][cat1]) [1] "girls" > (V2<-dimnames(y)[[1]][cat2]) [1] "boys" > > #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/1oay41386281740.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test data: table1 X-squared = 7.9256, df = 9, p-value = 0.5417 Warning message: In chisq.test(table1, simulate.p.value = simulate.p.value) : Chi-squared approximation may be incorrect > 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/2a7wl1386281741.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/wessaorg/rcomp/tmp/3namg1386281741.tab") > > > > proc.time() user system elapsed 0.637 0.188 0.791