This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ---- fit logit model with optim() ---- | |
| # data | |
| devtools::install_github("jrnold/ZeligData") | |
| turnout <- ZeligData::turnout | |
| # formula | |
| f <- vote ~ age + educate + income + race |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load packages | |
| library(tidyverse) | |
| library(numDeriv) # for numerical gradients | |
| # get the data ready | |
| # ------------------ | |
| # nominate data I use for teaching | |
| nom <- read_csv("https://pos3713ri.github.io/data/nominate.csv") |> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pi_hat <- 8/150 # ml estimate from observed data | |
| n_bs <- 2000 | |
| bs_est <- numeric(n_bs) # a container for the estimates | |
| for (i in 1:n_bs) { | |
| bs_y <- rbinom(150, size = 1, prob = 8/150) | |
| bs_est[i] <- mean(bs_y) | |
| } | |
| print(sd(bs_est), digits = 2) # se estimate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # illustrate the sampling distribution of our poisson estimator | |
| lambda <- 3 | |
| N <- 100 # sample size | |
| n_reps <- 1000 # number of imagined repeated studies | |
| lambda_hat <- numeric(n_reps) # a (now empty) container | |
| for (i in 1:n_reps) { | |
| y <- rpois(N, lambda = lambda) # simulate a dataset (or "study") | |
| lambda_hat[i] <- mean(y) # compute ml estimate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://election.lab.ufl.edu/2024-general-election-turnout/ | |
| library(tibble) | |
| turnout_2024 <- tribble( | |
| ~state, ~vep_turnout, | |
| "Alabama", 0.5893, | |
| "Alaska", 0.6378, | |
| "Arizona", 0.6360, | |
| "Arkansas", 0.5348, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load packages | |
| library(tidyverse) | |
| library(patchwork) | |
| # load holland's data (once per session) | |
| holland2015 <- crdata::holland2015 |> | |
| glimpse() | |
| # get data for lima |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load packages | |
| library(tidyverse) | |
| library(Lahman) # data from Lahman's baseball database | |
| # using dbeta shortcut (good!) | |
| ll_fn <- function(theta, y) { | |
| alpha <- theta[1] | |
| beta <- theta[2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| library(cranlogs) | |
| ggplot2_extensions <- c("ggQQunif", "ggupset", "xmrr", "gg3D", "ggQC", "ggdist", "ggedit", "ggpage", "ggpca", "ggbreak", | |
| "ggimg", "gganatogram", "ggforce", "ggalt", "ggiraph", "ggmuller", "ggstance", "ggrepel", "ggraph", | |
| "gginnards", "ggpp", "ggpmisc", "geomnet", "ggExtra", "ggfortify", "autoplotly", "gganimate", | |
| "ggfx", "plotROC", "ggbump", "ggthemes", "ggspectra", "ggstatsplot", "ggnetwork", "ggtech", | |
| "ggradar", "ggx", "ggTimeSeries", "ggtree", "ggseas", "ggsci", "ggmosaic", "survminer", "ggeasy", | |
| "ggside", "ggcorrplot", "ggpubr", "ggthemr", "GGally", "ggseqlogo", "ggChernoff", "ggridges", | |
| "lemon", "cowplot", "qqplotr", "ggalluvial", "patchwork", "ggquiver", "ggsignif", "ggdag", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| game_id | period_id | time_of_hit | seconds_played_in_season | seconds_btw_hits | |
|---|---|---|---|---|---|
| 1 | 1 | 25S | 25S | NA | |
| 1 | 1 | 2M 8S | 128S | 103S | |
| 1 | 1 | 2M 58S | 178S | 50S | |
| 1 | 1 | 3M 8S | 188S | 10S | |
| 1 | 1 | 4M 13S | 253S | 65S | |
| 1 | 1 | 9M 20S | 560S | 307S | |
| 1 | 1 | 10M 43S | 643S | 83S | |
| 1 | 2 | 3M 27S | 1407S | 764S | |
| 1 | 2 | 10M 25S | 1825S | 418S |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % custom LaTeXit preamble | |
| % for 5747 slides | |
| % maintained at: https://gist.github.com/carlislerainey/1096250dee536183dfc054c22ac2dd3a | |
| \documentclass[10pt]{article} | |
| % Font: Helvetica (not Neue, compatible with pdfLaTeX) | |
| \usepackage[scaled]{helvet} | |
| \renewcommand{\familydefault}{\sfdefault} |