A model that assumes that a secondary observations can be predicted using a convolution of a primary observation multipled by some scaling factor. An example use case of this model is to estimate the case fatality rate (with the primary observation being cases and the secondary observation being deaths) and then explore factors that influence it.

# S3 method for idbrms_convolution
idbrm(
  data,
  formula = id_formula(data),
  family = negbinomial(link = "identity"),
  priors = id_priors(data),
  custom_stancode = id_stancode(data),
  dry = FALSE,
  ...
)

Arguments

data

A data.frame as produced by prepare that must contain the date, location (as loc), primary (the data that the outcome is a convolution of) and secondary (the observation of interest. Should have class "idbrms_convolution".

formula

A formula as defined using id_formula or as supported by brms::brm.

family

A observation model family as defined in brms.

priors

A list of priors as defined using brms or id_priors. Defaults to the the id_priors defined for the model class being fit.

custom_stancode

A list of stanvars used to define custom stancode in brms. By default uses the code designed for the model class being fit (as specified using id_stancode).

dry

Logical, defaults to TRUE. For testing purposes should just the stan code be output with not fitting done.

...

Additional parameters passed to brms::brm.

Value

A "brmsfit" object or stan code (if dry = TRUE).

Author

Sam Abbott

Examples

# \donttest{
# define some example data
library(data.table)
dt <- data.table(
   region = "France", cases = seq(10, 500, by = 10),
   date = seq(as.Date("2020-10-01"), by = "days", length.out = 50)
   )
dt[, deaths := as.integer(shift(cases, 5) * 0.1)]
#>     region cases       date deaths
#>  1: France    10 2020-10-01     NA
#>  2: France    20 2020-10-02     NA
#>  3: France    30 2020-10-03     NA
#>  4: France    40 2020-10-04     NA
#>  5: France    50 2020-10-05     NA
#>  6: France    60 2020-10-06      1
#>  7: France    70 2020-10-07      2
#>  8: France    80 2020-10-08      3
#>  9: France    90 2020-10-09      4
#> 10: France   100 2020-10-10      5
#> 11: France   110 2020-10-11      6
#> 12: France   120 2020-10-12      7
#> 13: France   130 2020-10-13      8
#> 14: France   140 2020-10-14      9
#> 15: France   150 2020-10-15     10
#> 16: France   160 2020-10-16     11
#> 17: France   170 2020-10-17     12
#> 18: France   180 2020-10-18     13
#> 19: France   190 2020-10-19     14
#> 20: France   200 2020-10-20     15
#> 21: France   210 2020-10-21     16
#> 22: France   220 2020-10-22     17
#> 23: France   230 2020-10-23     18
#> 24: France   240 2020-10-24     19
#> 25: France   250 2020-10-25     20
#> 26: France   260 2020-10-26     21
#> 27: France   270 2020-10-27     22
#> 28: France   280 2020-10-28     23
#> 29: France   290 2020-10-29     24
#> 30: France   300 2020-10-30     25
#> 31: France   310 2020-10-31     26
#> 32: France   320 2020-11-01     27
#> 33: France   330 2020-11-02     28
#> 34: France   340 2020-11-03     29
#> 35: France   350 2020-11-04     30
#> 36: France   360 2020-11-05     31
#> 37: France   370 2020-11-06     32
#> 38: France   380 2020-11-07     33
#> 39: France   390 2020-11-08     34
#> 40: France   400 2020-11-09     35
#> 41: France   410 2020-11-10     36
#> 42: France   420 2020-11-11     37
#> 43: France   430 2020-11-12     38
#> 44: France   440 2020-11-13     39
#> 45: France   450 2020-11-14     40
#> 46: France   460 2020-11-15     41
#> 47: France   470 2020-11-16     42
#> 48: France   480 2020-11-17     43
#> 49: France   490 2020-11-18     44
#> 50: France   500 2020-11-19     45
#>     region cases       date deaths
dt[is.na(deaths), deaths := 0]
#>     region cases       date deaths
#>  1: France    10 2020-10-01      0
#>  2: France    20 2020-10-02      0
#>  3: France    30 2020-10-03      0
#>  4: France    40 2020-10-04      0
#>  5: France    50 2020-10-05      0
#>  6: France    60 2020-10-06      1
#>  7: France    70 2020-10-07      2
#>  8: France    80 2020-10-08      3
#>  9: France    90 2020-10-09      4
#> 10: France   100 2020-10-10      5
#> 11: France   110 2020-10-11      6
#> 12: France   120 2020-10-12      7
#> 13: France   130 2020-10-13      8
#> 14: France   140 2020-10-14      9
#> 15: France   150 2020-10-15     10
#> 16: France   160 2020-10-16     11
#> 17: France   170 2020-10-17     12
#> 18: France   180 2020-10-18     13
#> 19: France   190 2020-10-19     14
#> 20: France   200 2020-10-20     15
#> 21: France   210 2020-10-21     16
#> 22: France   220 2020-10-22     17
#> 23: France   230 2020-10-23     18
#> 24: France   240 2020-10-24     19
#> 25: France   250 2020-10-25     20
#> 26: France   260 2020-10-26     21
#> 27: France   270 2020-10-27     22
#> 28: France   280 2020-10-28     23
#> 29: France   290 2020-10-29     24
#> 30: France   300 2020-10-30     25
#> 31: France   310 2020-10-31     26
#> 32: France   320 2020-11-01     27
#> 33: France   330 2020-11-02     28
#> 34: France   340 2020-11-03     29
#> 35: France   350 2020-11-04     30
#> 36: France   360 2020-11-05     31
#> 37: France   370 2020-11-06     32
#> 38: France   380 2020-11-07     33
#> 39: France   390 2020-11-08     34
#> 40: France   400 2020-11-09     35
#> 41: France   410 2020-11-10     36
#> 42: France   420 2020-11-11     37
#> 43: France   430 2020-11-12     38
#> 44: France   440 2020-11-13     39
#> 45: France   450 2020-11-14     40
#> 46: France   460 2020-11-15     41
#> 47: France   470 2020-11-16     42
#> 48: France   480 2020-11-17     43
#> 49: France   490 2020-11-18     44
#> 50: France   500 2020-11-19     45
#>     region cases       date deaths

dt <- prepare(
  dt, model = "convolution", location = "region",
  primary = "cases", secondary = "deaths",
  )

# fit the convolution model using a Poisson observation model
fit <- idbrm(data = dt, family = poisson(identity = "link"))
#> Error in poisson(identity = "link") unused argument (identity = "link")
# }