Machine go brrrrr

Statistics is easy if you let the computer do all the work

Mark Rieke

2024-11-16

Who took stats?

Who liked stats?

Most stats courses look like this

This sucks

  • Just checking a box
  • Classroom examples vs real-world data
  • Easy to mess up!

What works better?

Simulation!

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 (machine go brrrrr)
  • 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

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 makes statistics easy
  • This lets you focus on your research question
  • Simulation keeps 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.