Skip to content

Instantly share code, notes, and snippets.

View carlislerainey's full-sized avatar

Carlisle Rainey carlislerainey

View GitHub Profile
@carlislerainey
carlislerainey / tasting-tea-sim.R
Created December 2, 2025 13:25
Tasting Tea Simulation
# ---- set up experiment
cups <- c(
rep("Milk First", 4),
rep("Tea First", 4)
)
cups
randomization <- sample(cups)

Basics: 36" (w) x 24" (h)

We need to create a document that's 36 inches wide by 24 inches tall. You email me the pdf, and I'll print it.

  • Keep font sizes about 28 points or larger.^[The body font on the "Dealing with Separation" poster outside my office is 28 points.]
  • Save figures as PDF--this will guarantee they don't look blurry when printed (e.g., ggsave("filename.pdf", height = 4, width = 6, scale = 1.5)).

Objective

The poster is NOT a substitute for a paper. There's no need to cram as much information on there as you can.

@carlislerainey
carlislerainey / mrp-solution.R
Created November 12, 2025 11:24
MRP solution
# load packages
library(tidyverse)
library(brms)
library(marginaleffects)
library(ggdist)
library(maps) # for map_data("state")
library(viridisLite) # palettes (used via scale_fill_viridis_c)
# set seed for reproducibility
@carlislerainey
carlislerainey / answers.R
Created November 5, 2025 20:40
An IRT model for for answers to 55 questions from 100 students
# load packages
library(tidyverse)
library(rstan)
library(tidybayes)
# load data
answers <- read_csv("https://pos5747.github.io/data/example-answers.csv") |>
glimpse()
@carlislerainey
carlislerainey / mrp-example.R
Last active November 4, 2025 18:10
MRP Example
# from: https://marginaleffects.com/chapters/mrp.html
# load packages
library(tidyverse)
library(brms)
library(marginaleffects)
library(ggdist)
library(maps) # for map_data("state")
library(viridisLite) # palettes (used via scale_fill_viridis_c)
# set seed for reproducibility
@carlislerainey
carlislerainey / eight-schools.R
Created October 22, 2025 19:48
Eight schools example
# load packages
library(tidyverse)
library(rstan)
library(tidybayes)
# eight-schools data; from my 2nd ed. of BDA on p. 140
est <- c(28, 8, -3, 7, -1, 1, 18, 12)
se_est <- c(15, 10, 16, 11, 9, 11, 10, 18)
J <- length(est)
@carlislerainey
carlislerainey / brms-logit.R
Created October 8, 2025 12:33
Illustrating logistic regression with {brms}
# ---- setup ----
# nice printing
options(digits = 3)
# load packages
library(tidyverse)
library(brms)
# load only the turnout data frame and hard-code rescaled variables
@carlislerainey
carlislerainey / logit-stan.R
Created October 8, 2025 12:30
Illustrating logistic regression with {rstan} and {cmdstanr}
# ---- setup ----
# nice printing
options(digits = 3)
# load packages
library(tidyverse)
# ---- data for stan ----
@carlislerainey
carlislerainey / logit-metropolis.R
Created October 8, 2025 10:22
Illustrating the metropolis algorithm with logistic regression
# ---- setup ----
# nice printing
options(digits = 3)
# load packages
library(tidyverse)
library(posterior)
library(foreach)
library(doParallel)
@carlislerainey
carlislerainey / toothpaste-metropolis.R
Created October 8, 2025 10:04
Illustrating the Metropolis algorithm with a beta(11, 165) posterior
# ---- setup ----
# nice printing
options(digits = 3)
# load packages
library(tidyverse)
library(posterior)
library(foreach)
library(doParallel)