Skip to content

Instantly share code, notes, and snippets.

@lundquist-ecology-lab
Created December 27, 2022 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lundquist-ecology-lab/96fb7d1bd831afb4dd4113215ad9d32b to your computer and use it in GitHub Desktop.
Save lundquist-ecology-lab/96fb7d1bd831afb4dd4113215ad9d32b to your computer and use it in GitHub Desktop.
Example chi-square goodness of fit test in R
# 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