Skip to content

Instantly share code, notes, and snippets.

View SermetPekin's full-sized avatar

Sermet Pekin SermetPekin

View GitHub Profile
@SermetPekin
SermetPekin / nfl-example.R
Last active March 31, 2026 07:21
simulation for Andrew Gelman's blog titled "These are the three ways of attacking a statistical problem"
# testing out schedule balancing on nfl 4-game starts
# https://statmodeling.stat.columbia.edu/2026/03/30/these-are-the-three-ways-of-attacking-a-statistical-problem-illustrated-with-the-nfl-example/#comment-2412639
invlogit <- function(x) { 1 / (1 + exp(-x)) }
# Andrew's split normal for ability (bottom-heavy)
rnorm_split <- function(n, mu, sigma_neg, sigma_pos) {
z <- rnorm(n, 0, 1)
ifelse(z < 0, mu + sigma_neg * z, mu + sigma_pos * z)
}
@SermetPekin
SermetPekin / SingleFile.R
Last active October 23, 2025 05:40
Fully reproducible R and Stan script for Andrew Gelman’s “Reanalysis of that Nobel prize–winning study of patents and innovation”
# Reproduction of Andrew Gelman's blog post:
# "Reanalysis of that Nobel prizewinning study of patents and innovation (with R and Stan code)"
# https://statmodeling.stat.columbia.edu/2025/10/21/reanalysis-of-that-nobel-prizewinning-study-of-patents-and-innovation/
# This script installs packages, downloads data, compiles Stan models, and reproduces plots in one run.
# ---- install-and-load ------------------------------------------------------
# Packages you need
pkgs <- c("haven", "arm", "rstanarm", "MASS", "cmdstanr")
# Ensure pak is available (fast, respects binaries)