Chi-square tests
setwd("/Volumes/EDMS451/Summer 2021/Software Instructions")
dat <- data.frame(group1 = c(76, 28, 34, 14),
group2 = c(32, 15, 24, 7))
rownames(dat) = c("type1", "type2", "type3", "type4")
dat # view the data
group1 group2
type1 76 32
type2 28 15
type3 34 24
type4 14 7
obs <- rowSums(dat)
exp <- c(.60, .14, .16, .10)
test_gof <- chisq.test(obs, p = exp)
test_gof #test results
Chi-squared test for given probabilities
data: obs
X-squared = 22.531, df = 3, p-value = 5.057e-05
test_ind <- chisq.test(dat)
test_ind$expected #expected frequency
group1 group2
type1 71.37391 36.626087
type2 28.41739 14.582609
type3 38.33043 19.669565
type4 13.87826 7.121739
test_ind$observed #observed frequency
group1 group2
type1 76 32
type2 28 15
type3 34 24
type4 14 7
test_ind #test results
Pearson's Chi-squared test
data: dat
X-squared = 2.348, df = 3, p-value = 0.5034