Visualizing the variability of p-hat
In order to compare the variability of the sampled \(\hat{p}\) and \(\hat{p}^*\) values in the previous exercises, it is valuable to visualize their distributions. To recall, the exercises walked through two different experiments for investigating the variability of \(\hat{p}\) and \(\hat{p}^*\):
- Experiment 1: Sample (\(n = 30\)) repeatedly from an extremely large population (gold standard, but unrealistic)
- Experiment 2: Resample (\(n = 30\)) repeatedly with replacement from a single sample of size 30
This exercise is part of the course
Foundations of Inference in R
Exercise instructions
- Combine data from both experiments by calling
bind_rows()
, passingex1_props
andex2_props
. Call thisboth_ex_props
. A dataset ID column namedexperiment
will be created. - Using
both_ex_props
, plotstat
colored byexperiment
. - Add a density curve using
geom_density()
, setting the bandwidth argument,bw
, to0.1
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Combine data from both experiments
both_ex_props <- ___(___, ___, .id = "experiment")
# Using both_ex_props, plot stat colored by experiment
ggplot(___, aes(___, color = ___)) +
# Add a density layer with bandwidth 0.1
___(bw = ___)