Chi square homogeneity test using R

Data
bug.colors = c(1, 2, 1, 3, 3, 2, 2, 1, 1, 1, 2, 3, 3, 2, 1, 1 ,1 ,2, 3, 2)
bug.colors = factor(bug.colors, levels = c(1,2,3), labels = c("Yellow", "Green", "Red"))

1. Frequency table
library(expss)  
fre(bug.colors)

H0 (research hypothesis about the color distribution):
Yellow: 50% Green: 25% Red: 25%


2. Test of H0

expected.percent = c(0.5, 0.25, 0.25) 
chisq.test(table(bug.colors), p = expected.percent)

The above example is contained in the paragraph 3.2 of the book "Στατιστική ανάλυση με τη γλώσσα R" (in Greek, ISBN: 978-960-93-9445-1) published in Thessaloniki, 2017.

Comments