Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
#rstats-ing all the things

Andrew Heiss andrewheiss

👨‍💻
#rstats-ing all the things
View GitHub Profile
View bayes_imputation.md
library(tidyverse)
library(brms)
library(Amelia)
library(broom)

set.seed(1234)
data("africa")

# Impute missing data with Amelia (since it handles country/year panel stuff really well)
View melded-p-values.md
library(tidyverse)
library(Amelia)
library(broom)

# Use the africa dataset from Amelia
data(africa)
set.seed(1234)
imp_amelia <- amelia(x = africa, m = 5, cs = "country", ts = "year", logs = "gdp_pc", p2s = 0)
View letter-on-racism-and-respect-for-humanity.md

June 7, 2020

Dear Members and Friends of the Lilburn Stake,

As I see the ongoing attitudes of prejudice and injustice being done to our African American friends and neighbors, my heart is deeply disturbed. I am moved by the growing number of protesters across our nation, some of them my own children, standing against racism and the disregard for human life. Ia am writing this letter to the members of our stake to let you know where we stand as your leaders on this critical issue.

I remember driving through our neighborhood following the attack on September 11, 2001. For days our neighbors were out on their lawns waving to us driving home from work. These neighbors were of middle eastern decent, people of similar culture to those who attacked our nation, yet not associated with the attack. They wanted us to know they were friendly and supported the freedom in our country. They were fearful the people of our country would retaliate.

After recently joining in to support a march, the president of my

View ologit_stuff.md
library(MASS) # Has to come first because of dplyr::select
library(tidyverse)
library(broom)
library(haven)

example_df <- read_stata("http://stats.idre.ucla.edu/stat/data/ologit.dta") %>% 
  mutate(apply = factor(apply, levels = 1:3, 
                        labels = c("unlikely", "somewhat likely", "very likely"), 
                        ordered = TRUE))
View little_women.R
library(tidyverse)
library(tidytext)
library(gutenbergr)
library(cleanNLP)
little_women_raw <- gutenberg_download(514, meta_fields = "title")
little_women <- little_women_raw %>%
slice(70:n()) %>%
mutate(chapter_start = str_detect(text, "^CHAPTER"),
View tornado_plot.R
library(tidyverse)
library(patchwork)
tornado <- tibble(x = 1:10,
y = c(2, 4, 5, 5.5, 4, 6, 7.5, 8, 7.5, 9)) %>%
mutate(dy = y - lag(y))
plot1 <- ggplot(tornado, aes(x = x, y = y)) +
geom_path(size = 2, linejoin = "round", lineend = "round") +
geom_point(size = 3) +
View retail_sales_decomposition.md
library(tidyverse)  # For ggplot, dplyr, and friends
library(tidyquant)  # For getting financial data from FRED, other places
library(tsibble)    # For working with time-based data
library(fable)      # For time series analysis
library(scales)     # For fun things like comma() and percent()
library(ggtext)     # For text magic in ggplot

# Get data from FRED
# https://fred.stlouisfed.org/series/RSXFSN
View emission_rankings.md
library(tidyverse)  # For ggplot, dplyr, and friends
library(WDI)        # Get data from the World Bank
library(ggrepel)    # For non-overlapping labels
library(ggtext)     # For better text styling

indicators <- c("SP.POP.TOTL",     # Population
                "EN.ATM.CO2E.PC",  # CO2 emissions
                "NY.GDP.PCAP.KD")  # GDP per capita
View broom_odds_ratios.md
library(tidyverse)
library(broom)

# Basic logit predicting if a car is an SUV or not
cars_binary <- mpg %>% 
  # Make new column marking if it's an SUV or not
  mutate(suv = class == "suv")

model <- glm(suv ~ cty + displ, 
View aaa_folder_structure.txt
.
├── slide-adventures.Rproj
├── slides
│   └── test.Rmd
└── styles
└── test.css
You can’t perform that action at this time.