Visualizing goodness of fit
The chi-square goodness of fit test compares proportions of each level of a categorical variable to hypothesized values. Before running such a test, it can be helpful to visually compare the distribution in the sample to the hypothesized distribution.
Recall the vendor incoterms in the late_shipments dataset. Let's hypothesize that the four values occur with these frequencies in the population of shipments.
EXW: 0.75CIP: 0.05DDP: 0.1FCA: 0.1
late_shipments is available; tibble, dplyr, ggplot2, and infer are loaded.
This exercise is part of the course
Hypothesis Testing in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Using late_shipments, count the vendor incoterms
vendor_inco_term_counts <- ___
# Get the number of rows in the whole sample
n_total <- ___
hypothesized <- tribble(
~ vendor_inco_term, ~ prop,
"EXW", 0.75,
"CIP", 0.05,
"DDP", 0.1,
"FCA", 0.1
) %>%
# Add a column of hypothesized counts for the incoterms
___
# See the results
hypothesized