Skip to content

Instantly share code, notes, and snippets.

View andrewheiss's full-sized avatar
👨‍💻
#rstats-ing all the things

Andrew Heiss andrewheiss

👨‍💻
#rstats-ing all the things
View GitHub Profile
library(tidyverse)
library(broom)
library(scales)

model <- lm(hwy ~ displ + cyl, data = mpg)

model_results <- tidy(model, conf.int = TRUE)

# Slow boring way of pulling out exact numbers
library(tidyverse)
library(patchwork)

# Plotting a list of three variables stored as character strings
things_to_plot <- c("displ", "cty", "hwy")

# Basic function for plotting

# Notice the .data[[blah]] syntax here. That's the magical part that makes this
library(tidyverse)
library(broom)
library(gapminder)

gapminder_nested <- gapminder %>% 
  filter(continent != "Oceania") %>% 
  group_by(continent, year) %>% 
  nest()
library(tidyverse)
library(marginaleffects)

set.seed(123)

n_obs <- 1000

simulated_data <- data.frame(
  id = 1:n_obs
library(tidyverse)
library(brms)
library(modelsummary)

model1 <- brm(
  bf(hwy ~ displ + cyl,
     decomp = "QR"),
  data = mpg,
  family = gaussian,
library(tidyverse)
library(ggdist)
library(patchwork)


# Single distributions ----------------------------------------------------

# Regular ggplot way
p1 <- ggplot() +
library(tidyverse)
library(gapminder)
library(fixest)
library(lme4)
# --------------------------------
# Econometrics-style fixed effects
# --------------------------------
model_fe <- feols(lifeExp ~ gdpPercap | country,
data = gapminder)
library(tidyverse)
library(brms)
library(tidybayes)
library(patchwork)
library(scales)
library(gapminder)
# Add some zeros to gapminder
set.seed(1234)
gapminder <- gapminder %>%
\begin{aligned}
& \mathrlap{\textbf{Hurdled likelihood of aid $i$ across time $t$ within each country $j$}} \\
\text{Foreign aid}_{it_j} &\sim
\mathrlap{
\begin{cases}
\ \operatorname{Bernoulli}(\pi_{it}) & \text{if Foreign aid}_{it_j} = 0 \\
\ \operatorname{Log\,\mathcal{N}}(\mu_{it_j}, \sigma_y) + \operatorname{Bernoulli}(1 - \pi_{it}) & \text{if Foreign aid}_{it_j} > 0
\end{cases}} \\
\\
& \textbf{Models for parameters} \\