Skip to content

Instantly share code, notes, and snippets.

View mattwarkentin's full-sized avatar

Matt Warkentin mattwarkentin

View GitHub Profile
library(ggplot2)
library(dplyr)
dd <- tibble(
x = 1:10,
y = runif(length(x))
)
dd %>%
ggplot(aes(x, y)) +
## Getting Standardized Betas
# Recall that standardized betas are:
# beta * (sx / sy)
# Where sx and sy are the standard deviations of X and Y
# Let's fit a simple model
mod <- lm(Sepal.Length ~ Sepal.Width, data = iris)
# Manual standardization after fitting model
betas <- coef(mod)[[2]] # extract beta
@mattwarkentin
mattwarkentin / nested_map_auc.R
Created March 12, 2020 15:48
Nested map functions for AUC
library(tidyverse)
library(yardstick)
set.seed(123456)
xx <-
matrix(runif(100), nrow = 10) %>%
as_tibble() %>%
nest(x = everything())
yy <-
@mattwarkentin
mattwarkentin / sdss-abstract.Rmd
Last active January 19, 2020 19:52
SDSS 2020 Abstract
---
title: "Symposium on Data Science and Statistics (SDSS 2020)"
subtitle: "Submission and Formatting Instructions for Extended Abstracts"
author:
- name: First Author
affiliation:
- Affiliation 1
- Affiliation 2
email: email@domain
- name: Second Author
#' Install version-locked packages and dependencies
#'
#' @description Install packages and dependencies based on the current version of R and its corresponding MRAN date.
#'
#' @param pkgs Charactor vector of package names.
#' @param quiet Logical. Should installation be done quietly? Default is TRUE.
#'
#' @details R versions and MRAN dates are based on the Rocker project (https://github.com/rocker-org/rocker-versioned/blob/master/VERSIONS.md).
#'
#' @author Matthew T. Warkentin, \email{warkentin@@lunenfeld.ca}
library(dplyr)
library(ggplot2)
library(patchwork)
library(broom)
theme_set(theme_light())
p1 <- anscombe %>%
ggplot(aes(x1, y1)) +
geom_point() +
@mattwarkentin
mattwarkentin / render-beamer.R
Last active October 9, 2019 20:47
R function to double-render a R Markdown document destined to be a Beamer presentation. Solves the total frame number issue.
render_beamer <- function(input = NULL, cleanup = FALSE, ...){
assertthat::assert_that(fs::file_exists(input))
bare_input <- fs::path_ext_remove(input)
out_dir <- fs::path_dir(input)
rmarkdown::render(input, ...)
pre_dir <- rbind(tibble::enframe(fs::dir_ls(out_dir)),
glue::glue('{fs::as_fs_path(bare_input)}.pdf'),