Skip to content

mapply() error when trying to use percent_cli as a covariate in arx_epi_forecaster() #209

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

Closed
rachlobay opened this issue Aug 16, 2022 · 1 comment

Comments

@rachlobay
Copy link
Collaborator

Once Issue #208) in epiprocess is addressed (by removing the problematic tibble::as_tibble() %>% line from the slide function for an archive in epiprocess), we get the following error when trying to use percent_cli as a covariate in arx_epi_forecaster():

Error in mapply(.f, .x, .y, MoreArgs = list(...), SIMPLIFY = FALSE) : 
zero-length inputs cannot be mixed with those of non-zero length

Below is an example to reproduce this error (run after the related epiprocess issue is fixed):

library(epipredict)
library(epiprocess)
library(covidcast)
library(data.table)
library(dplyr)
library(tidyr)
library(ggplot2)

y <- covidcast_signals(
  c("doctor-visits", "jhu-csse"),
  c("smoothed_adj_cli", "confirmed_7dav_incidence_prop"),
  start_day = "2020-06-01",
  end_day = "2021-12-01",
  issues = c("2020-06-01", "2021-12-01"),
  geo_type = "state",
  geo_values = c("ca", "fl"))

z <- y[[1]] %>%
  select(geo_value, time_value, version = issue, percent_cli = value) %>%
  as_epi_archive()

z <- epix_merge(
  z, y[[2]] %>%
    select(geo_value, time_value, version = issue, case_rate = value) %>%
    as_epi_archive(), sync = "locf")

fc_time_values <- seq(as.Date("2020-08-01"), as.Date("2021-12-01"),
                      by = "1 month")
ahead = 7

# Old arx_forecaster works fine with percent_cli
z %>% epix_slide(fc = arx_forecaster(x = percent_cli, y = case_rate, 
                                     key_vars = geo_value, time_value = time_value,
                                     args = arx_args_list(ahead = ahead)),
                 n = 120, ref_time_values = fc_time_values)

# New forecaster - error in mapply()
z %>%
  epix_slide(function(x, ...)
    arx_epi_forecaster(x, outcome = "case_rate",
                       predictors = c("case_rate", "percent_cli"),
                       args = arx_args_list(ahead = ahead))$predictions %>%
      select(-c(geo_value, time_value)),
    n = 120, ref_time_values = fc_time_values, new_col_name = "fc")

Please look into what is causing this error and what we can do to fix it. Possibly related to the abundance of missing values in percent_cli.

I haven’t looked into this much, but here are some initial thoughts: The error looks like it traces back to the call of map2 in line #109 of layer_residual.quantiles.R. And if one of the inputs is zero, then the mapply() function (which map2 uses) gives such an error… So are there alternatives to map2 that may be useful here? Or is there something more fundamentally wrong?

@rachlobay
Copy link
Collaborator Author

Moving to epipredict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant