library(tidyverse)
library(broom)
library(latex2exp)
library(patchwork)
set.seed(1234)
logit_df <- tibble(x = seq(-5, 5, length.out = 100)) %>%
mutate(p = 1/(1 + exp(-x))) %>%
mutate(y = rbinom(n(), size = 1, prob = p))
This file contains 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
# Credits to this Stack Overflow post | |
# https://stackoverflow.com/questions/13445753/force-ggplot2-scatter-plot-to-be-square-shaped | |
library(ggplot2) | |
library(grid) | |
rotation <- 45 | |
p <- | |
ggplot() + |
This file contains 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
########################################################## | |
# Get Ages of Top 100 Super Smash Brothers Melee Players # | |
########################################################## | |
# Tutorial ---------------------------------------------------------------- | |
# https://www.r-bloggers.com/2020/05/intro-to-polite-web-scraping-of-soccer-data-with-r/ | |
# Library ----------------------------------------------------------------- |
This file contains 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
# devtools::install_github("sharlagelfand/ggkeyboard", ref = "main") | |
library(ggkeyboard) | |
library(dplyr) | |
library(ggplot2) | |
# mac keys | |
keys <- tkl | |
keys$r1$key[1:7] <- c("Fn", "Ctrl", "\u2325", "\u2318", "Spacebar", "\u2318", "\u2325") | |
keys$r1$width[1:7] <- c(rep(1.05, 4), 8.25, rep(1.25, 2)) |
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)
This file contains 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(broom) | |
library(scales) | |
theme_set(theme_light()) | |
US <- read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us.csv") %>% | |
mutate(new_deaths = deaths - lag(deaths)) %>% | |
filter(date >= "2020-02-26") | |
today <- max(US$date) |
This file contains 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(broom) | |
US <- read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us.csv") %>% | |
mutate(new_deaths = deaths - lag(deaths)) %>% | |
filter(date >= "2020-02-26") | |
models <- tibble(degrees = 2:4) %>% | |
mutate(model = map(degrees, ~ lm(log(new_deaths + 1) ~ poly(date, .), data = US))) |
This file contains 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
# Install and load required packages | |
install.packages("needs") | |
library(needs) | |
needs(tidyverse, magrittr, animation, pdftools, png, scales) | |
# Function that extracts data from Google Mobility PDFs | |
process_google_mobility <- function(country_code, start_date, end_date){ | |
# Convert first page of PDF into high-res PNG | |
pdf_convert(paste0("https://www.gstatic.com/covid19/mobility/",end_date,"_",country_code,"_Mobility_Report_en.pdf"), format = "png", pages = 1, dpi = 300, filenames = "IMG1.png") |
This file contains 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(dplyr) | |
library(slider) | |
library(lubridate) | |
library(tsibbledata) | |
# Google, Apple, Facebook, Amazon stock | |
gafa_stock <- as_tibble(gafa_stock) | |
gafa_stock <- select(gafa_stock, Symbol, Date, Close, Volume) | |
head(gafa_stock, 2) |
NewerOlder