library(tidyverse)
sim_risk_ratios <- function(x){
events <- map2(rep(c(TRUE, FALSE), 5), c(31, 414 - 31, 82, 1492 - 82, 252, 4832 - 252, 423, 11831 - 423, 52, 1509-52), rep) %>% unlist()
outcomes <- tibble(
group = map2(c("<8 h", "8<10 h", "10<12 h", "12-16 h", ">16 h"), c(414, 1492, 4832, 11831, 1509), rep) %>% unlist()) %>%
mutate(event_sim = sample(events, n(), replace = TRUE)) %>%
group_by(group) %>%
summarise(risk = mean(event_sim))
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(tidymodels) | |
# Control function used as part of `prep_interval()` | |
ctrl_fit_recipe <- function(x){ | |
list(fit = workflows::pull_workflow_fit(x), | |
recipe = workflows::pull_workflow_prepped_recipe(x) | |
) | |
} |
library(palmerpenguins)
library(dplyr)
#' @param rmse Root mean squared error on your sample
#' @param df Degrees of Freedom in your model. In this case it should be the
#' same as the number of observations in your sample.
rmse_interval <- function(rmse, deg_free, p_lower = 0.025, p_upper = 0.975){
tibble(.pred_lower = sqrt(deg_free / qchisq(p_upper, df = deg_free)) * rmse,
.pred_upper = sqrt(deg_free / qchisq(p_lower, df = deg_free)) * rmse)
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(magrittr) | |
find_in_files <- function(path, pattern){ | |
path %>% | |
fs::dir_ls(recurse = TRUE, type = "file", regexp = "(\\.[rR])$") %>% | |
purrr::map(~grep(pattern, readLines(.x, warn = FALSE), value = TRUE)) %>% | |
purrr::keep(~length(.x) > 0) | |
} |
library(tidyverse)
library(httr)
library(jsonlite)
# downloaded data from: https://data.seattle.gov/Permitting/Building-Permits/76t5-zqzr
data_permits <- read_csv("Building_Permits.csv")
data_permits %>%
filter(PermitTypeDesc == "New") %>%
library(tidyverse)
urls <- tibble(month = month.name, month_num = 1:12) %>%
cross_join(tibble(year = 2019:2023)) %>%
arrange(year) %>%
mutate(year_month = make_date(year = year, month = month_num)) %>%
filter(year_month < floor_date(today(), "months")) %>%
mutate(urls = paste0("https://www.seattle.gov/documents/Departments/SDCI/Resources/Stats/", year, month, "Summary", ".xlsx"))
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
# This example only includes a value in the rolling mean() if the close date on | |
# the historical dates comes after the snapshot date for row of interest | |
### CREATE SAMPLE DATA | |
library(tidyverse) | |
library(slider) | |
library(lubridate) | |
sample_size <- 5000 |
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
# This example only includes a value in the rolling mean() if the close date on | |
# the historical dates comes after the snapshot date for row of interest | |
### CREATE SAMPLE DATA | |
library(tidyverse) | |
library(slider) | |
sample_size <- 5000 | |
obs_per_day <- 100 |
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) | |
#' Confusion Matrix With Observation Weights | |
#' | |
#' @param df dataframe | |
#' @param truth Column that represents 'truth' | |
#' @param extimate Columns that rrepresents class prediction | |
#' @param wt Column with observation weights. | |
#' @param scale_weights_one Whether observations in confusion matrix should equal number of observations. | |
#' @param dnn Character vector of dimnames for the table |
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(magrittr) | |
library(stringr) | |
library(readr) | |
library(purrr) | |
library(glue) | |
library(knitr) | |
source_rmd_chunks <- function(file, chunk_labels, skip_plots = TRUE, output_temp = FALSE){ | |
temp <- tempfile(fileext=".R") |
NewerOlder