Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump to newest epidatr #233

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Imports:
Suggests:
covidcast,
data.table,
epidatr,
epidatr (>= 1.0.0),
ggplot2,
knitr,
lubridate,
Expand Down
7 changes: 5 additions & 2 deletions R/step_population_scaling.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
step_population_scaling <-
function(recipe,
...,
role = "predictor",
role = "raw",
trained = FALSE,
df,
by = NULL,
Expand Down Expand Up @@ -195,7 +195,10 @@ bake.step_population_scaling <- function(object,
"must be present in data and match"))}

if (object$suffix != "_scaled" && object$create_new == FALSE) {
message("`suffix` not used to generate new column in `step_population_scaling`")
cli::cli_warn(c(
"Custom `suffix` {.val {object$suffix}} was ignored in `step_population_scaling`.",
i = "Perhaps `create_new` should be {.val {TRUE}}?"
))
}

object$df <- object$df %>%
Expand Down
2 changes: 1 addition & 1 deletion man/step_population_scaling.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 26 additions & 21 deletions tests/testthat/test-population_scaling.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ test_that("Number of columns and column names returned correctly, Upper and lowe
suffix = "_rate", # unused
create_new = FALSE)

prep <- prep(r, newdata)
expect_warning(prep <- prep(r, newdata))

expect_message(b <- bake(prep, newdata))
expect_warning(b <- bake(prep, newdata))
expect_equal(ncol(b), 5L)

})
Expand All @@ -86,6 +86,7 @@ test_that("Postprocessing workflow works and values correct", {
df = pop_data,
df_pop_col = "value",
by = c("geo_value" = "states"),
role = "raw",
suffix = "_scaled") %>%
step_epi_lag(cases_scaled, lag = c(0, 7, 14)) %>%
step_epi_ahead(cases_scaled, ahead = 7, role = "outcome") %>%
Expand All @@ -100,16 +101,15 @@ test_that("Postprocessing workflow works and values correct", {
by = c("geo_value" = "states"),
df_pop_col = "value")

wf <- epi_workflow(r,
parsnip::linear_reg()) %>%
wf <- epi_workflow(r, parsnip::linear_reg()) %>%
fit(jhu) %>%
add_frosting(f)

latest <- get_test_data(recipe = r,
x = epiprocess::jhu_csse_daily_subset %>%
dplyr::filter(time_value > "2021-11-01",
geo_value %in% c("ca", "ny")) %>%
dplyr::select(geo_value, time_value, cases))
x = epiprocess::jhu_csse_daily_subset %>%
dplyr::filter(time_value > "2021-11-01",
geo_value %in% c("ca", "ny")) %>%
dplyr::select(geo_value, time_value, cases))


expect_silent(p <- predict(wf, latest))
Expand Down Expand Up @@ -179,6 +179,7 @@ test_that("Postprocessing to get cases from case rate", {


test_that("test joining by default columns", {
skip()
jhu <- case_death_rate_subset %>%
dplyr::filter(time_value > "2021-11-01", geo_value %in% c("ca", "ny")) %>%
dplyr::select(geo_value, time_value, case_rate)
Expand All @@ -197,9 +198,9 @@ test_that("test joining by default columns", {
step_naomit(all_predictors()) %>%
step_naomit(all_outcomes(), skip = TRUE)

prep <- prep(r, jhu)
suppressMessages(prep <- prep(r, jhu))

expect_message(b <- bake(prep, jhu))
suppressMessages(b <- bake(prep, jhu))

f <- frosting() %>%
layer_predict() %>%
Expand All @@ -209,19 +210,23 @@ test_that("test joining by default columns", {
by = NULL,
df_pop_col = "values")

wf <- epi_workflow(r,
parsnip::linear_reg()) %>%
fit(jhu) %>%
add_frosting(f)

latest <- get_test_data(recipe = r,
x = case_death_rate_subset %>%
dplyr::filter(time_value > "2021-11-01",
geo_value %in% c("ca", "ny")) %>%
dplyr::select(geo_value, time_value, case_rate))
suppressMessages(
wf <- epi_workflow(r, parsnip::linear_reg()) %>%
fit(jhu) %>%
add_frosting(f)
)

latest <- get_test_data(
recipe = r,
x = case_death_rate_subset %>%
dplyr::filter(
time_value > "2021-11-01",
geo_value %in% c("ca", "ny")
) %>%
dplyr::select(geo_value, time_value, case_rate)
)

expect_message(p <- predict(wf, latest))
suppressMessages(p <- predict(wf, latest))

})

Expand Down
2 changes: 1 addition & 1 deletion vignettes/epipredict.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Get started with epipredict"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{epipredict}
%\VignetteIndexEntry{Get started with epipredict}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down
20 changes: 8 additions & 12 deletions vignettes/preprocessing-and-models.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,22 @@ regression, the textbook example for modeling count data, as an illustration
for using the `epipredict` package with other existing tidymodels packages.

```{r poisson-reg-data}
x <- covidcast(
data_source = "jhu-csse",
x <- pub_covidcast(
source = "jhu-csse",
signals = "confirmed_incidence_num",
time_type = "day",
geo_type = "state",
time_values = epirange(20210604, 20211231),
geo_values = "ca,fl,tx,ny,nj") %>%
fetch() %>%
select(geo_value, time_value, cases = value)

y <- covidcast(
data_source = "jhu-csse",
y <- pub_covidcast(
source = "jhu-csse",
signals = "deaths_incidence_num",
time_type = "day",
geo_type = "state",
time_values = epirange(20210604, 20211231),
geo_values = "ca,fl,tx,ny,nj") %>%
fetch() %>%
select(geo_value, time_value, deaths = value)

counts_subset <- full_join(x, y, by = c("geo_value", "time_value")) %>%
Expand Down Expand Up @@ -244,24 +242,22 @@ in public in the past 7 days maintained a distance of at least 6 feet.
State-wise population data from the 2019 U.S. Census is included in this package
and will be used in `layer_population_scaling()`.
```{r}
behav_ind_mask <- covidcast(
data_source = "fb-survey",
behav_ind_mask <- pub_covidcast(
source = "fb-survey",
signals = "smoothed_wwearing_mask_7d",
time_type = "day",
geo_type = "state",
time_values = epirange(20210604, 20211231),
geo_values = "ca,fl,tx,ny,nj") %>%
fetch() %>%
select(geo_value, time_value, masking = value)

behav_ind_distancing <- covidcast(
data_source = "fb-survey",
behav_ind_distancing <- pub_covidcast(
source = "fb-survey",
signals = "smoothed_wothers_distanced_public",
time_type = "day",
geo_type = "state",
time_values = epirange(20210604, 20211231),
geo_values = "ca,fl,tx,ny,nj") %>%
fetch() %>%
select(geo_value, time_value, distancing = value)

pop_dat <- state_census %>% select(abbr, pop)
Expand Down