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