Created
December 27, 2022 01:23
-
-
Save lundquist-ecology-lab/96fb7d1bd831afb4dd4113215ad9d32b to your computer and use it in GitHub Desktop.
Example chi-square goodness of fit test in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example chi-square | |
chi_square <- ((50 - 56.25)^2 / 56.25) + | |
((20 - 18.75)^2 / 18.75) + | |
((20 - 18.75)^2 / 18.75) + | |
((10 - 6.25)^2 / 6.25) | |
print(chi_square) | |
## Chi-square distribution | |
pchisq(3.11, df = 3, lower.tail = FALSE) | |
## Check to our results | |
obs <- c(50, 20, 20, 10) | |
expect_prob <- c(9 / 16, 3 / 16, 3 / 16, 1 / 16) | |
chisq.test(obs, p = expect_prob) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment