R version 2.9.0 (2009-04-17) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 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('g','Many','Often','Both','Outside','Same','Boys','Usually','Usually','Yes','Yes','Rarely','g','Few','Not_bul','Physical','Outside','Same','Boys','Usually','Rarely','Yes','No','Dont_bul','g','Many','Rarely','Mental','Outside','Same','Girls','Dont_know','Dont_know','Yes','No','Dont_bul','g','Many','Rarely','Mental','Not_bul','Differnt','Boys','Dont_know','Rarely','No','Yes','Dont_bul','b','Many','Not_bul','Physical','Not_bul','Not_bul','Not_bul','Dont_know','Dont_know','Not_bul','Not_bul','Dont_bul','b','Many','Not_bul','Physical','Outside','Differnt','Boys','Dont_know','Dont_know','No','No','Dont_bul','b','One','Not_bul','Not_bul','Not_bul','Same','Not_bul','Dont_know','Dont_know','Not_bul','Not_bul','Dont_bul'),dim=c(12,7),dimnames=list(c('gender','friends','how_often_bullied','type_of_bullying','where_bullied','which_year','gender_of_bully','teachers_stop','children_stop','told_teacher','told_home','how_often_bully'),1:7)) > y <- array(NA,dim=c(12,7),dimnames=list(c('gender','friends','how_often_bullied','type_of_bullying','where_bullied','which_year','gender_of_bully','teachers_stop','children_stop','told_teacher','told_home','how_often_bully'),1:7)) > 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 = '3' > par1 = '1' > ylab = 'Y Variable Name' > xlab = 'X Variable Name' > main = 'Title Goes Here' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Dr. Ian E. Holliday > #To cite this work: Ian E. Holliday, 2009, STARS Bullying Study (v1.0.1) 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#output/ > #Source of accompanying publication: > #Technical description: > 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] [,5] [,6] [,7] [1,] "g" "Many" "Often" "Both" "Outside" "Same" "Boys" [2,] "g" "Few" "Not_bul" "Physical" "Outside" "Same" "Boys" [3,] "g" "Many" "Rarely" "Mental" "Outside" "Same" "Girls" [4,] "g" "Many" "Rarely" "Mental" "Not_bul" "Differnt" "Boys" [5,] "b" "Many" "Not_bul" "Physical" "Not_bul" "Not_bul" "Not_bul" [6,] "b" "Many" "Not_bul" "Physical" "Outside" "Differnt" "Boys" [7,] "b" "One" "Not_bul" "Not_bul" "Not_bul" "Same" "Not_bul" [,8] [,9] [,10] [,11] [,12] [1,] "Usually" "Usually" "Yes" "Yes" "Rarely" [2,] "Usually" "Rarely" "Yes" "No" "Dont_bul" [3,] "Dont_know" "Dont_know" "Yes" "No" "Dont_bul" [4,] "Dont_know" "Rarely" "No" "Yes" "Dont_bul" [5,] "Dont_know" "Dont_know" "Not_bul" "Not_bul" "Dont_bul" [6,] "Dont_know" "Dont_know" "No" "No" "Dont_bul" [7,] "Dont_know" "Dont_know" "Not_bul" "Not_bul" "Dont_bul" > (table1 <- table(z[,cat1],z[,cat2])) Not_bul Often Rarely b 3 0 0 g 1 1 2 > (V1<-dimnames(y)[[1]][cat1]) [1] "gender" > (V2<-dimnames(y)[[1]][cat2]) [1] "how_often_bullied" > > #Note: the /var/www/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/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/www/html/rcomp/tmp/1cmx41259244988.tab") > (cst<-chisq.test(table1, simulate.p.value=simulate.p.value) ) Pearson's Chi-squared test data: table1 X-squared = 3.9375, df = 2, p-value = 0.1396 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/www/html/rcomp/tmp/2a8rw1259244988.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/www/html/rcomp/tmp/3dddj1259244988.tab") > > > > proc.time() user system elapsed 0.221 0.034 0.262