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(modelr) | |
library(tidyverse) | |
library(gapminder) | |
# nest data by continent and label test/train data | |
nested_gap <- gapminder %>% | |
mutate(test_train = ifelse(year < 1992, "train", "test")) %>% | |
group_by(continent) %>% | |
nest() |
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
# Test/Train split | |
set.seed(2018) # for reproducability | |
daily %>% | |
mutate(test_train = ifelse(rbinom(n=n(), size = 1, prob = .75) == 1, | |
"train","test")) %>% | |
count(test_train) |
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(purrr) | |
library(broom) | |
library(modelr) | |
#data set up | |
my_iris <- iris %>% | |
mutate(train_test = ifelse(rbinom(n=n(), size = 1, prob = .85) == 1, | |
"train","test")) | |
#set up model function |
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
#https://purrple.cat/blog/2018/03/02/multiple-lags-with-tidy-evaluation/ | |
lags <- function(var, n=10){ | |
var <- enquo(var) | |
indices <- seq_len(n) | |
map( indices, ~quo(lag(!!var, !!.x)) ) %>% | |
set_names(sprintf("lag_%s_%02d", quo_text(var), indices)) | |
} |
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
ggthemes::geom_tufteboxplot(aes(color = pre_post), size = 2)+ | |
scale_color_viridis(discrete=TRUE, option = "magma", end = .8) |
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(gumballthemes) | |
dat <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018-09-11/cats_vs_dogs.csv") | |
dat <- dat %>% | |
mutate(household_label = ifelse(n_dog_households > n_cat_households, "more dog households", "more cat households")) | |
p <- ggplot(dat, aes(x = percent_cat_owners, y = percent_dog_owners, color = household_label)) + | |
geom_point() + | |
ylab("% Dog Owners") + |
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
sudo docker run -dit --restart unless-stopped -v $PWD/share:/home/rstudio/share -p 8787:8787 -e PASSWORD=*** --name rstudio rocker/rstudio |
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) | |
Sacramento %>% str() | |
y <- Sacramento %>% select(price) %>% as.matrix() | |
x <- Sacramento %>% as.matrix() %>% scale() | |
fit <- glmnet::glmnet(x, y, lambda = 4192.847) | |
str(fit) | |
tidy_glmnet <- function(fit){ | |
lasso_coeffs <- tibble(index = seq(1:fit$dim[1]) - 1, terms = row.names(fit$beta)) %>% |
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) | |
# naive forecast method example | |
sales <- tibble(g = c(rep("insample", 23), rep("outsample", 12)), | |
y = c(0,2,0,1,0,10,0,0,0,2,0,6,3,0,0,0,0,0,7,0,0,0,0, 0, 0, 0, 3, 1, 0, 0, 1, 0, 1, 0, 0), | |
y_hat = ifelse(g == "insample", lag(y), last(y)), | |
error = abs(y - y_hat)) | |
sales | |
sales %>% |
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
taskscheduleR::taskscheduler_create(taskname = "myfancyscript_5min", rscript = myscript, | |
schedule = "MINUTE", starttime = "11:19", modifier = 1, startdate = format(as.Date("2019-01-19"), "%m/%d/%Y")) |