Machine go brrrrr

Making analysis easy and fun with computational statistics

Mark Rieke

2024-11-16

Who took stats?

Who liked stats?

What do we use stats for?

  • Pose a question
  • Estimate a value
  • Quantify uncertainty

Most stats courses look like this

This sucks

  • Statistics becomes “a box to check”
  • These procedures are brittle!
  • It’s really easy to mess up!

What works better?

Simulation!

What do we use stats for?

  • Pose a question
  • Estimate a value
  • Quantify uncertainty

How can we use simulation for statistics?

  • Frame question in terms of a process
  • Use random number generators to generate an answer
  • Do this a bunch of times
  • Quantify uncertainty

Example: weighting surveys

An example pre-election survey
Proportion of each subgroup that support the democratic candidate
party gender population K Y group mean sample proportion weight
Democrat Women 28% 237 229 97% 34% 0.83
Democrat Men 22% 178 160 90% 25% 0.87
Republican Women 25% 161 18 11% 23% 1.09
Republican Men 25% 124 4 3% 18% 1.41
  • Respondent preference varies by subgroup
  • Response rate varies by subgroup
  • Need to weight responses to make our sample representative of the population
  • Weighted mean is easy!
  • Uncertainty around the weighted mean is hard! (analytically)

Example: weighting surveys

Example: weighting surveys

Example: weighting surveys

Example: weighting surveys

Example: weighting surveys

model {
  Y ~ binomial(K, theta);
  wt_mean = sum(theta * wt * K) / sum(wt * K);
}

Example: weighting surveys

model {
  Y ~ binomial(K, theta);
  wt_mean = sum(theta * wt * K) / sum(wt * K);
}

Example: weighting surveys

model {
  Y ~ binomial(K, theta);
  wt_mean = sum(theta * wt * K) / sum(wt * K);
}

In conclusion

  • Simulation keeps your analysis tied to your research question
  • Simulation makes analysis easy
  • Simulation keeps makes statistics fun :)

Thanks!

Resources & whatnot

  • McElreath, Richard. Statistical Rethinking: A Bayesian Course with Examples in R and Stan. 2nd Edition. Chapman and Hall/CRC Press, 2018.
  • Wickham, Hadley, Mine Çetinkaya-Rundel, and Garrett Grolemund. R for Data Science: Import, Tidy, Transform, Visualize, and Model Data. 2nd Edition. O’Reilly Media, Inc., 2023.

Code and slides for this presentation can be found on github.