library(tidyverse)
library(nycflights13)
delay <- flights |>
group_by(dest) |>
summarize(means = mean(dep_delay, na.rm = TRUE))
joined <- inner_join(delay, flights, by = "dest")
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(stringr) | |
data_path <- 'somefolder/planet04_rgbn_c9_r8.txt' | |
# We want to extract 9 and 8 | |
basename(data_path) | |
# Too many numbers | |
str_extract_all(basename(data_path), "([0-9]+)") | |
# [[1]] |
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) | |
expit <- function(t) exp(t)/(1 + exp(t)) | |
n <- 1000000 | |
prev_vec <- c(0.01, 0.05, 0.1, 0.25, 0.5) | |
results <- purrr::map_df(prev_vec, \(prev) { | |
# Generate data | |
dvec <- rbinom(n, prob = prev, size = 1) |
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(cowplot) | |
gg1 <- ggplot(ToothGrowth, aes(x = len)) + | |
geom_dotplot(aes(fill = as.factor(dose)), | |
binwidth = .5) + | |
guides(fill = FALSE) | |
ToothGrowth2 <- arrange(ToothGrowth, len) | |
gg2 <- ggplot(ToothGrowth, aes(x = len, group = factor(dose))) + |
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
#---- | |
# Poisson vs casebase | |
# authors: Max Turgeon, Jesse Islam and Sahir Bhatnagar | |
# date: 10/1/2021 | |
#---- | |
set.seed(1952) | |
library(casebase) | |
library(cowplot) | |
library(Epi) |
B <- 1000
n <- 20
sigma <- 10
p <- 0.9
alpha <- 0.05
results <- replicate(B, {
norm_vars1 <- rnorm(n)
# Contaminated normal
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(casebase) | |
library(survival) | |
library(splines) | |
library(tidyverse) | |
library(cowplot) | |
# 1. Fit casebase with splines---- | |
data("ERSPC") | |
ERSPC <- mutate(ERSPC, ScrArm = factor(ScrArm, | |
levels = c(0,1), |
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(RcppRoll) | |
library(rvest) | |
# Create temporary directory | |
tmp_dir <- tempdir() | |
file_path <- paste0(tmp_dir, "/vaccine_sk.csv") | |
# Download file |
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(lubridate) | |
library(readr) | |
data_hr <- read_csv("https://raw.githubusercontent.com/ishaberry/Covid19Canada/master/timeseries_hr/cases_timeseries_hr.csv") | |
# Coerce string to dates and factor provinces | |
data_cum <- data_hr %>% | |
filter(province %in% c("Alberta", "Saskatchewan")) %>% | |
mutate(date_report = lubridate::dmy(date_report)) %>% |
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(lubridate) | |
library(readr) | |
library(ggbeeswarm) | |
# Download data on cases by health region | |
data_hr <- read_csv("https://raw.githubusercontent.com/ishaberry/Covid19Canada/master/timeseries_hr/cases_timeseries_hr.csv") | |
# Filter for province, coerce string to dates, and add variable | |
# to highlight certain regions |
NewerOlder