r:chi-square_test:code01
This is an old revision of the document!
install.packages("MASS")
library(MASS)
print(str(survey))
??MASS::survevy
wh.clap = data.frame(survey$Clap,survey$W.Hnd)
wh.clap.tbl = table(survey$Clap,survey$W.Hnd)
wh.clap.tbl
chisq <- chisq.test(wh.clap.tbl)
chisq
o <- chisq$observed
e <- chisq$expected
o
round(e, 3)
r <- (e-o)/sqrt(e)
r
chisq.cal <- sum((e-o)^2/e)
p.val <- pchisq(chisq.cal, df=2, lower.tail = F)
chisq.cal
p.val
chisq
barplot(wh.clap.tbl, beside = TRUE,
col = c("red", "lightgreen", "blue"),
main = "wh vs ex",
xlab = "Exercise Level", ylab = "Number of Students")
legend("center", legend = rownames(wh.clap.tbl),
fill = c("red", "lightgreen" ,"blue"))
r/chi-square_test/code01.1764715112.txt.gz · Last modified: by hkimscil
