A p-value, two ways
You've seen before how there are usually two ways to get to the null distribution: through computation and through a mathematical approximation. The chi-squared goodness of fit test is no exception. The approximation distribution is again the "Chi-squared distribution" with degrees of freedom equal to the number of categories minus one.
In this exercise you'll compare these two approaches to calculate a p-value that measures the consistency of the distribution of the Iran first digits with Benford's Law. Note that the observed statistic that you created in the last exercise is saved in your work space as chi_obs_stat
.
This exercise is part of the course
Inference for Categorical Data in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Compute degrees of freedom
degrees_of_freedom <- ___ %>%
# Pull out first_digit vector
pull("first_digit") %>%
# Calculate n levels and subtract 1
___
# Plot both null dists
___
# Add density layer
___
# Add vertical line at obs stat
___
# Overlay chisq approx
stat_function(fun = dchisq, args = list(df = ___), color = "blue")