Get startedGet started for free

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

View Course

Exercise instructions

  • Combine data from both experiments by calling bind_rows(), passing ex1_props and ex2_props. Call this both_ex_props. A dataset ID column named experiment will be created.
  • Using both_ex_props, plot stat colored by experiment.
  • Add a density curve using geom_density(), setting the bandwidth argument, bw, to 0.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 = ___)
Edit and Run Code