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(55,56,54,58,56,58,57,58,59,61,61,61,63,63,62,64,65,64,65,64,64,65,62,66,65,66,65,66,66,66,65,67,66,67,67,67,66,68,68,68,69,68,70,68,71,68,68,69,69,69,66,70,68,70,69,70,69,70,70,70,75,70,69,71,71,71,71,71,74,71,69,73,69,73,74,73,75,73,73,74,70,75,76,75,76,75,76,75,71,76,75,76,76,76,79,76,80,76,76,77,77,77,78,77,80,78,79,79,78,80,80,80,83,80,79,81,81,82,85,82,83,83,85,83,83,84,82,85,84,86,88,86,88,86,89,86,88,87,87,89,84,90,90,91,90,91,88,93,96,94,96,95,97,98,101,100,92,101,103,101,102,107,119,124),dim=c(2,82),dimnames=list(c('w','rw'),1:82)) > y <- array(NA,dim=c(2,82),dimnames=list(c('w','rw'),1:82)) > for (i in 1:dim(x)[1]) + { + for (j in 1:dim(x)[2]) + { + y[i,j] <- as.numeric(x[i,j]) + } + } > 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,] 55 56 [2,] 54 58 [3,] 56 58 [4,] 57 58 [5,] 59 61 [6,] 61 61 [7,] 63 63 [8,] 62 64 [9,] 65 64 [10,] 65 64 [11,] 64 65 [12,] 62 66 [13,] 65 66 [14,] 65 66 [15,] 66 66 [16,] 65 67 [17,] 66 67 [18,] 67 67 [19,] 66 68 [20,] 68 68 [21,] 69 68 [22,] 70 68 [23,] 71 68 [24,] 68 69 [25,] 69 69 [26,] 66 70 [27,] 68 70 [28,] 69 70 [29,] 69 70 [30,] 70 70 [31,] 75 70 [32,] 69 71 [33,] 71 71 [34,] 71 71 [35,] 74 71 [36,] 69 73 [37,] 69 73 [38,] 74 73 [39,] 75 73 [40,] 73 74 [41,] 70 75 [42,] 76 75 [43,] 76 75 [44,] 76 75 [45,] 71 76 [46,] 75 76 [47,] 76 76 [48,] 79 76 [49,] 80 76 [50,] 76 77 [51,] 77 77 [52,] 78 77 [53,] 80 78 [54,] 79 79 [55,] 78 80 [56,] 80 80 [57,] 83 80 [58,] 79 81 [59,] 81 82 [60,] 85 82 [61,] 83 83 [62,] 85 83 [63,] 83 84 [64,] 82 85 [65,] 84 86 [66,] 88 86 [67,] 88 86 [68,] 89 86 [69,] 88 87 [70,] 87 89 [71,] 84 90 [72,] 90 91 [73,] 90 91 [74,] 88 93 [75,] 96 94 [76,] 96 95 [77,] 97 98 [78,] 101 100 [79,] 92 101 [80,] 103 101 [81,] 102 107 [82,] 119 124 > (table1 <- table(z[,cat1],z[,cat2])) 56 58 61 63 64 65 66 67 68 69 70 71 73 74 75 76 77 78 79 80 81 82 83 84 54 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 55 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 56 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 57 0 1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 > (V1<-dimnames(y)[[1]][cat1]) [1] "w" > (V2<-dimnames(y)[[1]][cat2]) [1] "rw" > > #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/185cy1338546159.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test data: table1 X-squared = 1867.43, df = 1443, p-value = 2.103e-13 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/2fnfj1338546159.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/3p7rt1338546160.tab") > > > > proc.time() user system elapsed 3.160 0.111 3.276