Title: | Estimate Epidemiological Delay Distributions With brms |
---|---|
Description: | Understanding and accurately estimating epidemiological delay distributions is important for public health policy. These estimates influence epidemic situational awareness, control strategies, and resource allocation. This package provides methods to address the key challenges in estimating these distributions, including truncation, interval censoring, and dynamical biases. These issues are frequently overlooked, resulting in biased conclusions. |
Authors: | Adam Howes [aut] |
Maintainer: | Sam Abbott <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2025-02-12 15:29:06 UTC |
Source: | https://github.com/epinowcast/epidist |
Add natural scale mean and standard deviation parameters
add_mean_sd(data, ...)
add_mean_sd(data, ...)
data |
A dataframe of distributional parameters. |
... |
Additional arguments for method. |
Other postprocess:
add_mean_sd.default()
,
add_mean_sd.gamma_samples()
,
add_mean_sd.lognormal_samples()
,
predict_delay_parameters()
Default method for add natural scale parameters
## Default S3 method: add_mean_sd(data, ...)
## Default S3 method: add_mean_sd(data, ...)
data |
A dataframe of distributional parameters. |
... |
Additional arguments for method. |
Other postprocess:
add_mean_sd()
,
add_mean_sd.gamma_samples()
,
add_mean_sd.lognormal_samples()
,
predict_delay_parameters()
Again, mu
and shape
here are the distributional parameters of brms
.
## S3 method for class 'gamma_samples' add_mean_sd(data, ...)
## S3 method for class 'gamma_samples' add_mean_sd(data, ...)
data |
A dataframe of distributional parameters. |
... |
Additional arguments for method. |
Other postprocess:
add_mean_sd()
,
add_mean_sd.default()
,
add_mean_sd.lognormal_samples()
,
predict_delay_parameters()
Note that the input parameters here are mu
and sigma
, corresponding to
the distributional parameters used by brms
for the lognormal
family.
## S3 method for class 'lognormal_samples' add_mean_sd(data, ...)
## S3 method for class 'lognormal_samples' add_mean_sd(data, ...)
data |
A dataframe of distributional parameters. |
... |
Additional arguments for method. |
Other postprocess:
add_mean_sd()
,
add_mean_sd.default()
,
add_mean_sd.gamma_samples()
,
predict_delay_parameters()
Creates an epidist_aggregate_data object from various input formats. This is useful when working with pre-aggregated data where each row represents multiple identical observations. See the specific methods for details on supported input formats and usage examples.
as_epidist_aggregate_data(data, ...)
as_epidist_aggregate_data(data, ...)
data |
The data to convert |
... |
Additional arguments passed to methods |
Other aggregate_data:
as_epidist_aggregate_data.data.frame()
,
as_epidist_aggregate_data.default()
,
as_epidist_aggregate_data.epidist_linelist_data()
,
assert_epidist.epidist_aggregate_data()
,
is_epidist_aggregate_data()
,
new_epidist_aggregate_data()
This method takes a data.frame containing event dates (primary/secondary
event dates and observation date) along with counts and creates an
epidist_aggregate_data
object. This format is useful when working with
pre-aggregated data where each row represents multiple identical observations
with the count stored in a specified column. Internally it makes use of
as_epidist_linelist_data.data.frame()
to convert the data to a linelist
format before adding the count column. See the other methods for other data
input options.
## S3 method for class 'data.frame' as_epidist_aggregate_data( data, n = NULL, pdate_lwr = NULL, sdate_lwr = NULL, pdate_upr = NULL, sdate_upr = NULL, obs_date = NULL, ... )
## S3 method for class 'data.frame' as_epidist_aggregate_data( data, n = NULL, pdate_lwr = NULL, sdate_lwr = NULL, pdate_upr = NULL, sdate_upr = NULL, obs_date = NULL, ... )
data |
A data.frame containing line list data |
n |
A character string giving the name of the column containing the
counts for each row. If |
pdate_lwr |
A string giving the column of |
sdate_lwr |
A string giving the column of |
pdate_upr |
A string giving the column of |
sdate_upr |
A string giving the column of |
obs_date |
A string giving the column of |
... |
Additional arguments passed to methods |
Other aggregate_data:
as_epidist_aggregate_data()
,
as_epidist_aggregate_data.default()
,
as_epidist_aggregate_data.epidist_linelist_data()
,
assert_epidist.epidist_aggregate_data()
,
is_epidist_aggregate_data()
,
new_epidist_aggregate_data()
sierra_leone_ebola_data |> dplyr::count(date_of_symptom_onset, date_of_sample_tested) |> as_epidist_aggregate_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested", n = "n" )
sierra_leone_ebola_data |> dplyr::count(date_of_symptom_onset, date_of_sample_tested) |> as_epidist_aggregate_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested", n = "n" )
This method takes vectors of event times (primary/secondary event times and
observation time) along with counts and creates an epidist_aggregate_data
object. This format is useful when working with pre-aggregated data where
each row represents multiple identical observations with the count stored in
the n
column. Internally it makes use of
as_epidist_linelist_data.default()
to convert the data to a linelist
format before adding the count column. See the other methods for other data
input options.
## Default S3 method: as_epidist_aggregate_data( data, n = NULL, ptime_upr = NULL, stime_lwr = NULL, stime_upr = NULL, obs_time = NULL, ... )
## Default S3 method: as_epidist_aggregate_data( data, n = NULL, ptime_upr = NULL, stime_lwr = NULL, stime_upr = NULL, obs_time = NULL, ... )
data |
Numeric vector giving lower bounds for primary times. |
n |
An integerish vector containing the counts for each row. Must be the same length as the input data vector. |
ptime_upr |
Numeric vector giving upper bounds for primary times. |
stime_lwr , stime_upr
|
Numeric vectors giving lower and upper bounds for secondary times. |
obs_time |
Numeric vector giving observation times. |
... |
Additional columns to add to the epidist_linelist_data object. |
Other aggregate_data:
as_epidist_aggregate_data()
,
as_epidist_aggregate_data.data.frame()
,
as_epidist_aggregate_data.epidist_linelist_data()
,
assert_epidist.epidist_aggregate_data()
,
is_epidist_aggregate_data()
,
new_epidist_aggregate_data()
as_epidist_aggregate_data( data = c(1, 2, 3), ptime_upr = c(2, 3, 4), stime_lwr = c(3, 4, 5), stime_upr = c(4, 5, 6), obs_time = c(5, 6, 7), n = c(1, 2, 3) )
as_epidist_aggregate_data( data = c(1, 2, 3), ptime_upr = c(2, 3, 4), stime_lwr = c(3, 4, 5), stime_upr = c(4, 5, 6), obs_time = c(5, 6, 7), n = c(1, 2, 3) )
This method takes an epidist_linelist_data
object (see
as_epidist_linelist_data()
) and aggregates it by counting unique
combinations of the required time variables (primary/secondary event times
and observation time) and any additional variables specified in by
. The
result is a more compact representation of the same data where each row
represents multiple identical observations with the count stored in the n
column.
## S3 method for class 'epidist_linelist_data' as_epidist_aggregate_data(data, by = NULL, ...)
## S3 method for class 'epidist_linelist_data' as_epidist_aggregate_data(data, by = NULL, ...)
data |
The data to convert |
by |
Character vector of additional variables to stratify by, beyond the required time variables. |
... |
Additional arguments passed to methods |
Other aggregate_data:
as_epidist_aggregate_data()
,
as_epidist_aggregate_data.data.frame()
,
as_epidist_aggregate_data.default()
,
assert_epidist.epidist_aggregate_data()
,
is_epidist_aggregate_data()
,
new_epidist_aggregate_data()
# Default stratification by required time variables only sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_aggregate_data() # Additional stratification by other variables sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_aggregate_data(by = "age")
# Default stratification by required time variables only sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_aggregate_data() # Additional stratification by other variables sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_aggregate_data(by = "age")
epidist_latent_model
objectCreates an epidist_latent_model
object from various input formats.
This enables fitting latent variable models for epidemiological delays using
epidist()
, as described in Park et al. (2024) and Charniga et al. (2024)
The latent model approach accounts for double interval censoring and right
truncation in delay data.
as_epidist_latent_model(data, ...)
as_epidist_latent_model(data, ...)
data |
An object to be converted to the class |
... |
Additional arguments passed to methods. |
Other latent_model:
as_epidist_latent_model.epidist_aggregate_data()
,
as_epidist_latent_model.epidist_linelist_data()
,
epidist_family_model.epidist_latent_model()
,
epidist_formula_model.epidist_latent_model()
,
epidist_model_prior.epidist_latent_model()
,
is_epidist_latent_model()
,
new_epidist_latent_model()
epidist_aggregate_data
objectsThis method converts aggregate data to a latent model format by first
converting it to linelist format using
as_epidist_linelist_data.epidist_aggregate_data()
and then passing it to
as_epidist_latent_model.epidist_linelist_data()
. This ensures that the
counts in the aggregate data are properly expanded into individual
observations before fitting the latent model.
## S3 method for class 'epidist_aggregate_data' as_epidist_latent_model(data, ...)
## S3 method for class 'epidist_aggregate_data' as_epidist_latent_model(data, ...)
data |
An |
... |
Not used in this method. |
Other latent_model:
as_epidist_latent_model()
,
as_epidist_latent_model.epidist_linelist_data()
,
epidist_family_model.epidist_latent_model()
,
epidist_formula_model.epidist_latent_model()
,
epidist_model_prior.epidist_latent_model()
,
is_epidist_latent_model()
,
new_epidist_latent_model()
sierra_leone_ebola_data |> dplyr::count(date_of_symptom_onset, date_of_sample_tested) |> as_epidist_aggregate_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested", n = "n" ) |> as_epidist_latent_model()
sierra_leone_ebola_data |> dplyr::count(date_of_symptom_onset, date_of_sample_tested) |> as_epidist_aggregate_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested", n = "n" ) |> as_epidist_latent_model()
epidist_linelist_data
objectsThis method takes an epidist_linelist_data
object and converts it to a
format suitable for fitting latent variable models. It calculates key
variables needed for the latent variable method described in Park et al.
(2024) and Charniga et al. (2024). This approach adjusts for double
interval censoring and right truncation in the data.
## S3 method for class 'epidist_linelist_data' as_epidist_latent_model(data, ...)
## S3 method for class 'epidist_linelist_data' as_epidist_latent_model(data, ...)
data |
An |
... |
Not used in this method. |
Other latent_model:
as_epidist_latent_model()
,
as_epidist_latent_model.epidist_aggregate_data()
,
epidist_family_model.epidist_latent_model()
,
epidist_formula_model.epidist_latent_model()
,
epidist_model_prior.epidist_latent_model()
,
is_epidist_latent_model()
,
new_epidist_latent_model()
sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_latent_model()
sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_latent_model()
Creates an epidist_linelist_data object from various input formats. This is useful when working with individual-level data where each row represents a single observation with primary and secondary event times. See the specific methods for details on supported input formats and usage examples.
as_epidist_linelist_data(data, ...)
as_epidist_linelist_data(data, ...)
data |
The data to convert |
... |
Additional arguments passed to methods |
Other linelist_data:
as_epidist_linelist_data.data.frame()
,
as_epidist_linelist_data.default()
,
as_epidist_linelist_data.epidist_aggregate_data()
,
assert_epidist.epidist_linelist_data()
,
is_epidist_linelist_data()
,
new_epidist_linelist_data()
This method takes a data.frame containing event dates (primary/secondary
event dates and observation date) and creates an epidist_linelist_data
object. This format is useful when working with individual-level data where
each row represents a single observation. Internally it converts dates to
numeric times relative to the earliest primary event date and uses
as_epidist_linelist_data.default()
to create the final object. See the
other methods for other data input options.
## S3 method for class 'data.frame' as_epidist_linelist_data( data, pdate_lwr = NULL, sdate_lwr = NULL, pdate_upr = NULL, sdate_upr = NULL, obs_date = NULL, ... )
## S3 method for class 'data.frame' as_epidist_linelist_data( data, pdate_lwr = NULL, sdate_lwr = NULL, pdate_upr = NULL, sdate_upr = NULL, obs_date = NULL, ... )
data |
A data.frame containing line list data |
pdate_lwr |
A string giving the column of |
sdate_lwr |
A string giving the column of |
pdate_upr |
A string giving the column of |
sdate_upr |
A string giving the column of |
obs_date |
A string giving the column of |
... |
Additional arguments passed to methods |
Other linelist_data:
as_epidist_linelist_data()
,
as_epidist_linelist_data.default()
,
as_epidist_linelist_data.epidist_aggregate_data()
,
assert_epidist.epidist_linelist_data()
,
is_epidist_linelist_data()
,
new_epidist_linelist_data()
sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" )
sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" )
This method takes vectors of event times (primary/secondary event times and
observation time) and creates an epidist_linelist_data
object. This format
is useful when working with individual-level data where each row represents a
single observation. See the other methods for other data input options.
## Default S3 method: as_epidist_linelist_data( data, ptime_upr = NULL, stime_lwr = NULL, stime_upr = NULL, obs_time = NULL, ... )
## Default S3 method: as_epidist_linelist_data( data, ptime_upr = NULL, stime_lwr = NULL, stime_upr = NULL, obs_time = NULL, ... )
data |
Numeric vector giving lower bounds for primary times. |
ptime_upr |
Numeric vector giving upper bounds for primary times. |
stime_lwr , stime_upr
|
Numeric vectors giving lower and upper bounds for secondary times. |
obs_time |
Numeric vector giving observation times. |
... |
Additional columns to add to the epidist_linelist_data object. |
Other linelist_data:
as_epidist_linelist_data()
,
as_epidist_linelist_data.data.frame()
,
as_epidist_linelist_data.epidist_aggregate_data()
,
assert_epidist.epidist_linelist_data()
,
is_epidist_linelist_data()
,
new_epidist_linelist_data()
as_epidist_linelist_data( data = c(1, 2, 3), ptime_upr = c(2, 3, 4), stime_lwr = c(3, 4, 5), stime_upr = c(4, 5, 6), obs_time = c(5, 6, 7) )
as_epidist_linelist_data( data = c(1, 2, 3), ptime_upr = c(2, 3, 4), stime_lwr = c(3, 4, 5), stime_upr = c(4, 5, 6), obs_time = c(5, 6, 7) )
This method expands an epidist_aggregate_data
object into individual
observations by uncounting the n
column, then converts it to linelist
format using as_epidist_linelist_data.data.frame()
.
## S3 method for class 'epidist_aggregate_data' as_epidist_linelist_data(data, ...)
## S3 method for class 'epidist_aggregate_data' as_epidist_linelist_data(data, ...)
data |
The data to convert |
... |
Additional arguments passed to methods |
Other linelist_data:
as_epidist_linelist_data()
,
as_epidist_linelist_data.data.frame()
,
as_epidist_linelist_data.default()
,
assert_epidist.epidist_linelist_data()
,
is_epidist_linelist_data()
,
new_epidist_linelist_data()
sierra_leone_ebola_data |> dplyr::count(date_of_symptom_onset, date_of_sample_tested) |> as_epidist_aggregate_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested", n = "n" ) |> as_epidist_linelist_data()
sierra_leone_ebola_data |> dplyr::count(date_of_symptom_onset, date_of_sample_tested) |> as_epidist_aggregate_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested", n = "n" ) |> as_epidist_linelist_data()
epidist_marginal_model
objectCreates an epidist_marginal_model
object from various input formats.
This enables fitting marginal models for epidemiological delays using
epidist()
. The marginal model approach uses the likelihood from the
primarycensored package to
efficiently handle censoring in both primary and secondary events as well as
truncation due to observation times. See the specific methods
as_epidist_marginal_model.epidist_linelist_data()
and
as_epidist_marginal_model.epidist_aggregate_data()
for details on
supported input formats and usage examples.
as_epidist_marginal_model(data, ...)
as_epidist_marginal_model(data, ...)
data |
An object to be converted to the class |
... |
Additional arguments passed to methods. |
Other marginal_model:
as_epidist_marginal_model.epidist_aggregate_data()
,
as_epidist_marginal_model.epidist_linelist_data()
,
epidist_family_model.epidist_marginal_model()
,
epidist_formula_model.epidist_marginal_model()
,
epidist_transform_data_model.epidist_marginal_model()
,
is_epidist_marginal_model()
,
new_epidist_marginal_model()
epidist_aggregate_data
objectsThis method converts aggregate data to a marginal model format by
passing it to as_epidist_marginal_model.epidist_linelist_data()
with the n
column used as weights. This ensures that the likelihood is
weighted by the counts in the aggregate data.
## S3 method for class 'epidist_aggregate_data' as_epidist_marginal_model(data, obs_time_threshold = 2, ...)
## S3 method for class 'epidist_aggregate_data' as_epidist_marginal_model(data, obs_time_threshold = 2, ...)
data |
An |
obs_time_threshold |
Ratio used to determine threshold for setting
relative observation times to Inf. Observation times greater than
|
... |
Not used in this method. |
Other marginal_model:
as_epidist_marginal_model()
,
as_epidist_marginal_model.epidist_linelist_data()
,
epidist_family_model.epidist_marginal_model()
,
epidist_formula_model.epidist_marginal_model()
,
epidist_transform_data_model.epidist_marginal_model()
,
is_epidist_marginal_model()
,
new_epidist_marginal_model()
sierra_leone_ebola_data |> dplyr::count(date_of_symptom_onset, date_of_sample_tested) |> as_epidist_aggregate_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested", n = "n" ) |> as_epidist_marginal_model()
sierra_leone_ebola_data |> dplyr::count(date_of_symptom_onset, date_of_sample_tested) |> as_epidist_aggregate_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested", n = "n" ) |> as_epidist_marginal_model()
epidist_linelist_data
objectsThis method converts linelist data to a marginal model format by calculating
delays between primary and secondary events, along with observation times and
censoring windows. The likelihood used is imported from the
primarycensored package
which handles censoring in both primary and secondary events as well as
truncation due to observation times. In principle, this method should be
more accurate and more computationally efficient than the latent model
(as_epidist_latent_model()
) approach in most setting except when the
number of unique strata approaches the number of observations.
## S3 method for class 'epidist_linelist_data' as_epidist_marginal_model(data, obs_time_threshold = 2, weight = NULL, ...)
## S3 method for class 'epidist_linelist_data' as_epidist_marginal_model(data, obs_time_threshold = 2, weight = NULL, ...)
data |
An |
obs_time_threshold |
Ratio used to determine threshold for setting
relative observation times to Inf. Observation times greater than
|
weight |
A column name to use for weighting the data in the likelihood. Default is NULL. Internally this is used to define the 'n' column of the returned object. |
... |
Not used in this method. |
When a formula is specified in epidist()
, the data will be transformed
using epidist_transform_data_model.epidist_marginal_model()
to prepare it
for model fitting. This transformation summarises the data by counting unique
combinations of delays, observation times, censoring windows and any
variables in the model formula.
Other marginal_model:
as_epidist_marginal_model()
,
as_epidist_marginal_model.epidist_aggregate_data()
,
epidist_family_model.epidist_marginal_model()
,
epidist_formula_model.epidist_marginal_model()
,
epidist_transform_data_model.epidist_marginal_model()
,
is_epidist_marginal_model()
,
new_epidist_marginal_model()
sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_marginal_model()
sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_marginal_model()
epidist_naive_model
objectCreates an epidist_naive_model
object from various input formats.
This enables fitting naive models for epidemiological delays using
epidist()
. The naive model approach ignores censoring and truncation in
the data, using only the lower bounds of the intervals as point estimates.
This is the simplest approach but may lead to biased estimates if there is
substantial censoring or truncation in the data.
as_epidist_naive_model(data, ...)
as_epidist_naive_model(data, ...)
data |
An object to be converted to the class |
... |
Additional arguments passed to methods. |
Other naive_model:
as_epidist_naive_model.epidist_aggregate_data()
,
as_epidist_naive_model.epidist_linelist_data()
,
epidist_formula_model.epidist_naive_model()
,
epidist_transform_data_model.epidist_naive_model()
,
is_epidist_naive_model()
,
new_epidist_naive_model()
epidist_aggregate_data
objectsThis method converts aggregate data to a naive model format by passing it to
as_epidist_naive_model.epidist_linelist_data()
with the n
column used as
weights. This ensures that the likelihood is weighted by the counts in the
aggregate data.
## S3 method for class 'epidist_aggregate_data' as_epidist_naive_model(data, ...)
## S3 method for class 'epidist_aggregate_data' as_epidist_naive_model(data, ...)
data |
An |
... |
Additional arguments passed to methods. |
Other naive_model:
as_epidist_naive_model()
,
as_epidist_naive_model.epidist_linelist_data()
,
epidist_formula_model.epidist_naive_model()
,
epidist_transform_data_model.epidist_naive_model()
,
is_epidist_naive_model()
,
new_epidist_naive_model()
sierra_leone_ebola_data |> dplyr::count(date_of_symptom_onset, date_of_sample_tested) |> as_epidist_aggregate_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested", n = "n" ) |> as_epidist_naive_model()
sierra_leone_ebola_data |> dplyr::count(date_of_symptom_onset, date_of_sample_tested) |> as_epidist_aggregate_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested", n = "n" ) |> as_epidist_naive_model()
epidist_linelist_data
objectsThis method converts linelist data to a naive model format by calculating
delays between primary and secondary events to enable model fitting
in epidist()
. If the input data contains an n
column (e.g. from
aggregated data), the likelihood will be weighted by these counts.
## S3 method for class 'epidist_linelist_data' as_epidist_naive_model(data, weight = NULL, ...)
## S3 method for class 'epidist_linelist_data' as_epidist_naive_model(data, weight = NULL, ...)
data |
An |
weight |
A column name to use for weighting the data in the likelihood. Default is NULL. Internally this is used to define the 'n' column of the returned object. |
... |
Additional arguments passed to methods. |
When a formula is specified in epidist()
, the data will be transformed
using epidist_transform_data_model.epidist_naive_model()
to prepare it for
model fitting. This transformation summarises the data by counting unique
combinations of delays and any variables in the model formula.
The naive model is the simplest approach but ignores censoring and truncation
in the data by using only lower bounds as point estimates. For data with
substantial censoring or truncation, consider using
as_epidist_latent_model()
or as_epidist_marginal_model()
which properly
account for these features.
Other naive_model:
as_epidist_naive_model()
,
as_epidist_naive_model.epidist_aggregate_data()
,
epidist_formula_model.epidist_naive_model()
,
epidist_transform_data_model.epidist_naive_model()
,
is_epidist_naive_model()
,
new_epidist_naive_model()
sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_naive_model()
sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_naive_model()
Validation for epidist objects
assert_epidist(data, ...)
assert_epidist(data, ...)
data |
Object to validate |
... |
Additional arguments |
NULL invisibly
epidist_aggregate_data
objectsAssert validity of epidist_aggregate_data
objects
## S3 method for class 'epidist_aggregate_data' assert_epidist(data, ...)
## S3 method for class 'epidist_aggregate_data' assert_epidist(data, ...)
data |
An object to check |
... |
Additional arguments |
Other aggregate_data:
as_epidist_aggregate_data()
,
as_epidist_aggregate_data.data.frame()
,
as_epidist_aggregate_data.default()
,
as_epidist_aggregate_data.epidist_linelist_data()
,
is_epidist_aggregate_data()
,
new_epidist_aggregate_data()
sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_aggregate_data() |> assert_epidist()
sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_aggregate_data() |> assert_epidist()
epidist_linelist_data
objectsAssert validity of epidist_linelist_data
objects
## S3 method for class 'epidist_linelist_data' assert_epidist(data, ...)
## S3 method for class 'epidist_linelist_data' assert_epidist(data, ...)
data |
An object to check for validity. |
... |
Additional arguments |
Other linelist_data:
as_epidist_linelist_data()
,
as_epidist_linelist_data.data.frame()
,
as_epidist_linelist_data.default()
,
as_epidist_linelist_data.epidist_aggregate_data()
,
is_epidist_linelist_data()
,
new_epidist_linelist_data()
brms
interfaceFit epidemiological delay distributions using a brms
interface
epidist( data, formula = mu ~ 1, family = lognormal(), prior = NULL, merge_priors = TRUE, fn = brms::brm, ... )
epidist( data, formula = mu ~ 1, family = lognormal(), prior = NULL, merge_priors = TRUE, fn = brms::brm, ... )
data |
An object with class corresponding to an implemented model. |
formula |
An object of class stats::formula or brms::brmsformula
(or one that can be coerced to those classes). A symbolic description of
the model to be fitted. A formula must be provided for the distributional
parameter |
family |
A description of the response distribution and link function to
be used in the model. Every family function has a link argument allowing
users to specify the link function to be applied on the response variable.
If not specified, default links are used. For details of all supported
families see |
prior |
One or more |
merge_priors |
If |
fn |
The internal function to be called. By default this is
|
... |
Additional arguments passed to |
fit <- sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_aggregate_data() |> as_epidist_marginal_model() |> epidist(chains = 2, cores = 2, refresh = ifelse(interactive(), 250, 0)) summary(fit)
fit <- sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_aggregate_data() |> as_epidist_marginal_model() |> epidist(chains = 2, cores = 2, refresh = ifelse(interactive(), 250, 0)) summary(fit)
epidist_fit
modelsThis function computes diagnostics to assess the quality of a fitted model.
When the fitting algorithm used is "sampling"
(HMC) then the output of
epidist_diagnostics
is a data.frame
containing:
time
: the total time taken to fit all chains
samples
: the total number of samples across all chains
max_rhat
: the highest value of the Gelman-Rubin statistic
divergent_transitions
: the total number of divergent transitions
per_divergent_transitions
: the proportion of samples which had divergent
transitions
max_treedepth
: the highest value of the treedepth HMC parameter
no_at_max_treedepth
: the number of samples which attained the
max_treedepth
per_at_max_treedepth
: the proportion of samples which attained the
max_treedepth
epidist_diagnostics(fit)
epidist_diagnostics(fit)
fit |
A fitted model of class |
When the fitting algorithm is not "sampling"
(see brms::brm()
for other
possible algorithms) then diagnostics are yet to be implemented.
fit <- sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_aggregate_data() |> as_epidist_marginal_model() |> epidist(chains = 2, cores = 2, refresh = ifelse(interactive(), 250, 0)) epidist_diagnostics(fit)
fit <- sierra_leone_ebola_data |> as_epidist_linelist_data( pdate_lwr = "date_of_symptom_onset", sdate_lwr = "date_of_sample_tested" ) |> as_epidist_aggregate_data() |> as_epidist_marginal_model() |> epidist(chains = 2, cores = 2, refresh = ifelse(interactive(), 250, 0)) epidist_diagnostics(fit)
epidist
familyThis function is used within epidist()
to create a model specific custom
brms
family object. This custom family is passed to brms
. It is unlikely
that as a user you will need this function, but we export it nonetheless to
be transparent about what happens inside of a call to epidist()
.
epidist_family(data, family = lognormal(), ...)
epidist_family(data, family = lognormal(), ...)
data |
An object with class corresponding to an implemented model. |
family |
A description of the response distribution and link function to
be used in the model. Every family function has a link argument allowing
users to specify the link function to be applied on the response variable.
If not specified, default links are used. For details of all supported
families see |
... |
Additional arguments passed to |
Other family:
epidist_family_model()
,
epidist_family_model.default()
,
epidist_family_param()
,
epidist_family_param.default()
epidist_family()
callThe model-specific parts of an epidist_family()
call
The model-specific parts of an epidist_formula()
call
epidist_family_model(data, family, ...) epidist_formula_model(data, formula, ...)
epidist_family_model(data, family, ...) epidist_formula_model(data, formula, ...)
data |
An object with class corresponding to an implemented model. |
family |
Output of a call to |
... |
Additional arguments passed to |
formula |
An object of class stats::formula or brms::brmsformula
(or one that can be coerced to those classes). A symbolic description of
the model to be fitted. A formula must be provided for the distributional
parameter |
Other family:
epidist_family()
,
epidist_family_model.default()
,
epidist_family_param()
,
epidist_family_param.default()
Other formula:
epidist_formula()
,
epidist_formula_model.default()
Default method for defining a model specific family
## Default S3 method: epidist_family_model(data, family, ...)
## Default S3 method: epidist_family_model(data, family, ...)
data |
An object with class corresponding to an implemented model. |
family |
Output of a call to |
... |
Additional arguments passed to |
Other family:
epidist_family()
,
epidist_family_model()
,
epidist_family_param()
,
epidist_family_param.default()
epidist
custom familyCreate the model-specific component of an epidist
custom family
## S3 method for class 'epidist_latent_model' epidist_family_model(data, family, ...)
## S3 method for class 'epidist_latent_model' epidist_family_model(data, family, ...)
data |
An object with class corresponding to an implemented model. |
family |
Output of a call to |
... |
Additional arguments passed to method. |
Other latent_model:
as_epidist_latent_model()
,
as_epidist_latent_model.epidist_aggregate_data()
,
as_epidist_latent_model.epidist_linelist_data()
,
epidist_formula_model.epidist_latent_model()
,
epidist_model_prior.epidist_latent_model()
,
is_epidist_latent_model()
,
new_epidist_latent_model()
epidist
custom familyCreate the model-specific component of an epidist
custom family
## S3 method for class 'epidist_marginal_model' epidist_family_model(data, family, ...)
## S3 method for class 'epidist_marginal_model' epidist_family_model(data, family, ...)
data |
An object with class corresponding to an implemented model. |
family |
Output of a call to |
... |
Additional arguments passed to method. |
Other marginal_model:
as_epidist_marginal_model()
,
as_epidist_marginal_model.epidist_aggregate_data()
,
as_epidist_marginal_model.epidist_linelist_data()
,
epidist_formula_model.epidist_marginal_model()
,
epidist_transform_data_model.epidist_marginal_model()
,
is_epidist_marginal_model()
,
new_epidist_marginal_model()
epidist
family to align brms
and StanReparameterise an epidist
family to align brms
and Stan
epidist_family_param(family, ...)
epidist_family_param(family, ...)
family |
A description of the response distribution and link function to
be used in the model. Every family function has a link argument allowing
users to specify the link function to be applied on the response variable.
If not specified, default links are used. For details of all supported
families see |
... |
Additional arguments passed to |
Other family:
epidist_family()
,
epidist_family_model()
,
epidist_family_model.default()
,
epidist_family_param.default()
This function extracts the Stan parameterisation for a given brms family by creating a dummy model and parsing its Stan code. It looks for the log probability density function (lpdf) call in the Stan code and extracts the parameter order used by Stan. This is needed because brms and Stan may use different parameter orderings for the same distribution.
## Default S3 method: epidist_family_param(family, ...)
## Default S3 method: epidist_family_param(family, ...)
family |
A brms family object containing at minimum a |
... |
Additional arguments passed to methods (not used) |
The function works by:
Creating a minimal dummy model using the specified family
Extracting the Stan code for this model
Finding the lpdf function call for the family
Parsing out the parameter ordering used in Stan
Adding this as the param
element to the family object
The input family object with an additional param
element containing
the Stan parameter ordering as a string
Other family:
epidist_family()
,
epidist_family_model()
,
epidist_family_model.default()
,
epidist_family_param()
This function contains brms
prior distributions which are specific to
particular likelihood families e.g. brms::lognormal()
.
epidist_family_prior(family, ...)
epidist_family_prior(family, ...)
family |
A description of the response distribution and link function to
be used in the model. Every family function has a link argument allowing
users to specify the link function to be applied on the response variable.
If not specified, default links are used. For details of all supported
families see |
... |
Additional arguments passed to |
Other prior:
epidist_family_prior.default()
,
epidist_family_prior.lognormal()
,
epidist_model_prior()
,
epidist_model_prior.default()
,
epidist_prior()
By default, we do not return any family specific prior distributions.
## Default S3 method: epidist_family_prior(family, formula, ...)
## Default S3 method: epidist_family_prior(family, formula, ...)
family |
A description of the response distribution and link function to
be used in the model. Every family function has a link argument allowing
users to specify the link function to be applied on the response variable.
If not specified, default links are used. For details of all supported
families see |
formula |
An object of class stats::formula or brms::brmsformula
(or one that can be coerced to those classes). A symbolic description of
the model to be fitted. A formula must be provided for the distributional
parameter |
... |
Additional arguments passed to |
Other prior:
epidist_family_prior()
,
epidist_family_prior.lognormal()
,
epidist_model_prior()
,
epidist_model_prior.default()
,
epidist_prior()
We suggest priors to overwrite the brms
defaults for the lognormal family.
## S3 method for class 'lognormal' epidist_family_prior(family, formula, ...)
## S3 method for class 'lognormal' epidist_family_prior(family, formula, ...)
family |
A description of the response distribution and link function to
be used in the model. Every family function has a link argument allowing
users to specify the link function to be applied on the response variable.
If not specified, default links are used. For details of all supported
families see |
formula |
An object of class stats::formula or brms::brmsformula
(or one that can be coerced to those classes). A symbolic description of
the model to be fitted. A formula must be provided for the distributional
parameter |
... |
Additional arguments passed to |
Other prior:
epidist_family_prior()
,
epidist_family_prior.default()
,
epidist_model_prior()
,
epidist_model_prior.default()
,
epidist_prior()
This function is used within epidist()
to create the formula object passed
to brms
. It is unlikely that as a user you will need this function, but we
export it nonetheless to be transparent about what exactly is happening
inside of a call to epidist()
.
epidist_formula(data, family, formula, ...)
epidist_formula(data, family, formula, ...)
data |
An object with class corresponding to an implemented model. |
family |
A description of the response distribution and link function to
be used in the model created using |
formula |
An object of class stats::formula or brms::brmsformula
(or one that can be coerced to those classes). A symbolic description of
the model to be fitted. A formula must be provided for the distributional
parameter |
... |
Additional arguments passed to |
Other formula:
epidist_family_model()
,
epidist_formula_model.default()
Default method for defining a model specific formula
## Default S3 method: epidist_formula_model(data, formula, ...)
## Default S3 method: epidist_formula_model(data, formula, ...)
data |
An object with class corresponding to an implemented model. |
formula |
An object of class stats::formula or brms::brmsformula
(or one that can be coerced to those classes). A symbolic description of
the model to be fitted. A formula must be provided for the distributional
parameter |
... |
Additional arguments passed to |
Other formula:
epidist_family_model()
,
epidist_formula()
epidist
custom formula for the
latent modelDefine the model-specific component of an epidist
custom formula for the
latent model
## S3 method for class 'epidist_latent_model' epidist_formula_model(data, formula, ...)
## S3 method for class 'epidist_latent_model' epidist_formula_model(data, formula, ...)
data |
An object with class corresponding to an implemented model. |
formula |
An object of class stats::formula or brms::brmsformula
(or one that can be coerced to those classes). A symbolic description of
the model to be fitted. A formula must be provided for the distributional
parameter |
... |
Additional arguments passed to method. |
Other latent_model:
as_epidist_latent_model()
,
as_epidist_latent_model.epidist_aggregate_data()
,
as_epidist_latent_model.epidist_linelist_data()
,
epidist_family_model.epidist_latent_model()
,
epidist_model_prior.epidist_latent_model()
,
is_epidist_latent_model()
,
new_epidist_latent_model()
epidist
custom formula for the
marginal modelDefine the model-specific component of an epidist
custom formula for the
marginal model
## S3 method for class 'epidist_marginal_model' epidist_formula_model(data, formula, ...)
## S3 method for class 'epidist_marginal_model' epidist_formula_model(data, formula, ...)
data |
An object with class corresponding to an implemented model. |
formula |
An object of class stats::formula or brms::brmsformula
(or one that can be coerced to those classes). A symbolic description of
the model to be fitted. A formula must be provided for the distributional
parameter |
... |
Additional arguments passed to method. |
Other marginal_model:
as_epidist_marginal_model()
,
as_epidist_marginal_model.epidist_aggregate_data()
,
as_epidist_marginal_model.epidist_linelist_data()
,
epidist_family_model.epidist_marginal_model()
,
epidist_transform_data_model.epidist_marginal_model()
,
is_epidist_marginal_model()
,
new_epidist_marginal_model()
epidist
custom formula for the
naive modelDefine the model-specific component of an epidist
custom formula for the
naive model
## S3 method for class 'epidist_naive_model' epidist_formula_model(data, formula, ...)
## S3 method for class 'epidist_naive_model' epidist_formula_model(data, formula, ...)
data |
An object with class corresponding to an implemented model. |
formula |
An object of class stats::formula or brms::brmsformula
(or one that can be coerced to those classes). A symbolic description of
the model to be fitted. A formula must be provided for the distributional
parameter |
... |
Additional arguments passed to method. |
Other naive_model:
as_epidist_naive_model()
,
as_epidist_naive_model.epidist_aggregate_data()
,
as_epidist_naive_model.epidist_linelist_data()
,
epidist_transform_data_model.epidist_naive_model()
,
is_epidist_naive_model()
,
new_epidist_naive_model()
This function creates a log likelihood function that calculates the marginal
likelihood for a single observation by integrating over the latent primary
and secondary event windows. The integration is performed numerically using
primarycensored::dpcens()
which handles the double censoring and truncation
of the delay distribution.
epidist_gen_log_lik(family)
epidist_gen_log_lik(family)
family |
A description of the response distribution and link function to
be used in the model. Every family function has a link argument allowing
users to specify the link function to be applied on the response variable.
If not specified, default links are used. For details of all supported
families see |
The marginal likelihood accounts for uncertainty in both the primary and secondary event windows by integrating over their possible values, weighted by their respective uniform distributions.
A function that calculates the marginal log likelihood for a single observation. The prep object must have the following variables:
vreal1
: relative observation time
vreal2
: primary event window
vreal3
: secondary event window
brms::log_lik()
for details on the brms log likelihood interface.
Other gen:
epidist_gen_posterior_epred()
,
epidist_gen_posterior_predict()
This function creates a function that calculates the expected value of the
posterior predictive distribution for a latent model. The returned function
takes a prep
argument (from brms) and returns posterior expected values.
This is used internally by brms::posterior_epred()
to calculate expected
values for latent models.
epidist_gen_posterior_epred(family)
epidist_gen_posterior_epred(family)
family |
A description of the response distribution and link function to
be used in the model. Every family function has a link argument allowing
users to specify the link function to be applied on the response variable.
If not specified, default links are used. For details of all supported
families see |
A function that takes a prep argument from brms and returns a matrix of posterior expected values, with one row per posterior draw and one column per observation.
brms::posterior_epred()
for details on how this is used within
brms
.
Other gen:
epidist_gen_log_lik()
,
epidist_gen_posterior_predict()
This function creates a function that draws from the posterior predictive
distribution for a latent model using primarycensored::rpcens()
to handle
censoring and truncation. The returned function takes a prep
argument from
brms
and returns posterior predictions. This is used internally by
brms::posterior_predict()
to generate predictions for latent models.
epidist_gen_posterior_predict(family)
epidist_gen_posterior_predict(family)
family |
A description of the response distribution and link function to
be used in the model. Every family function has a link argument allowing
users to specify the link function to be applied on the response variable.
If not specified, default links are used. For details of all supported
families see |
A function that takes a prep
argument from brms and returns a
matrix of posterior predictions, with one row per posterior draw and one
column per observation. The prep
object must have the following variables:
vreal1
: relative observation time
vreal2
: primary event window
vreal3
: secondary event window
brms::posterior_predict()
for details on how this is used within
brms
, primarycensored::rpcens()
for details on the censoring approach
Other gen:
epidist_gen_log_lik()
,
epidist_gen_posterior_epred()
This function contains brms
prior distributions which are specific to
particular epidist
models e.g. the latent_lognormal
model.
epidist_model_prior(data, ...)
epidist_model_prior(data, ...)
data |
An object with class corresponding to an implemented model. |
... |
Additional arguments passed to |
Other prior:
epidist_family_prior()
,
epidist_family_prior.default()
,
epidist_family_prior.lognormal()
,
epidist_model_prior.default()
,
epidist_prior()
By default, we do not return any model specific prior distributions.
## Default S3 method: epidist_model_prior(data, formula, ...)
## Default S3 method: epidist_model_prior(data, formula, ...)
data |
An object with class corresponding to an implemented model. |
formula |
An object of class stats::formula or brms::brmsformula
(or one that can be coerced to those classes). A symbolic description of
the model to be fitted. A formula must be provided for the distributional
parameter |
... |
Additional arguments passed to |
Other prior:
epidist_family_prior()
,
epidist_family_prior.default()
,
epidist_family_prior.lognormal()
,
epidist_model_prior()
,
epidist_prior()
Defines prior distributions for the latent model parameters pwindow_raw
and
swindow_raw
which control the width of the observation windows.
## S3 method for class 'epidist_latent_model' epidist_model_prior(data, formula, ...)
## S3 method for class 'epidist_latent_model' epidist_model_prior(data, formula, ...)
data |
An object with class corresponding to an implemented model. |
formula |
An object of class stats::formula or brms::brmsformula
(or one that can be coerced to those classes). A symbolic description of
the model to be fitted. A formula must be provided for the distributional
parameter |
... |
Additional arguments passed to |
Other latent_model:
as_epidist_latent_model()
,
as_epidist_latent_model.epidist_aggregate_data()
,
as_epidist_latent_model.epidist_linelist_data()
,
epidist_family_model.epidist_latent_model()
,
epidist_formula_model.epidist_latent_model()
,
is_epidist_latent_model()
,
new_epidist_latent_model()
This function combines model specific prior distributions from
epidist_model_prior()
, family specific prior distributions from
epidist_family_prior()
, and user provided prior distributions into a single
set of custom priors. Each element overwrites previous elements, such that
user provided prior distributions have the highest priority. If a user prior
distribution is provided which is not included in the model, a warning will
be shown.
epidist_prior( data, family, formula, prior, merge = TRUE, enforce_presence = FALSE )
epidist_prior( data, family, formula, prior, merge = TRUE, enforce_presence = FALSE )
data |
An object with class corresponding to an implemented model. |
family |
A description of the response distribution and link function to
be used in the model created using |
formula |
A symbolic description of the model to be fitted created using
|
prior |
One or more |
merge |
If |
enforce_presence |
If |
Note that the matching of priors is imperfect as it does not use brms' internal prior matching functionality. For example, it cannot distinguish between a prior for all coefficients (class = "b") and a prior for a specific coefficient (class = "b" and coef specified).
A brmsprior
object containing the combined custom prior
distributions.
Other prior:
epidist_family_prior()
,
epidist_family_prior.default()
,
epidist_family_prior.lognormal()
,
epidist_model_prior()
,
epidist_model_prior.default()
This function is used within epidist()
to create any custom Stan code which
is injected into brms
via the stanvars
argument. It is unlikely that
as a user you will need this function, but we export it nonetheless to be
transparent about what exactly is happening inside of a call to epidist()
.
epidist_stancode(data, ...)
epidist_stancode(data, ...)
data |
An object with class corresponding to an implemented model. |
... |
Additional arguments passed to |
Other stan:
epidist_stancode.default()
Default method for defining model specific Stan code
## Default S3 method: epidist_stancode(data, ...)
## Default S3 method: epidist_stancode(data, ...)
data |
An object with class corresponding to an implemented model. |
... |
Additional arguments passed to |
Other stan:
epidist_stancode()
This function is used within epidist()
to transform data before passing to
brms
. It is unlikely that as a user you will need this function, but we
export it nonetheless to be transparent about what happens inside of a call
to epidist()
.
epidist_transform_data(data, family, formula, ...)
epidist_transform_data(data, family, formula, ...)
data |
An object with class corresponding to an implemented model. |
family |
A description of the response distribution and link function to
be used in the model created using |
formula |
A formula object created using |
... |
Additional arguments passed to |
Other transform_data:
epidist_transform_data_model()
,
epidist_transform_data_model.default()
epidist_transform_data()
callThe model-specific parts of an epidist_transform_data()
call
epidist_transform_data_model(data, family, formula, ...)
epidist_transform_data_model(data, family, formula, ...)
data |
An object with class corresponding to an implemented model. |
family |
A description of the response distribution and link function to
be used in the model created using |
formula |
A formula object created using |
... |
Additional arguments passed to |
Other transform_data:
epidist_transform_data()
,
epidist_transform_data_model.default()
Default method for transforming data for a model
## Default S3 method: epidist_transform_data_model(data, family, formula, ...)
## Default S3 method: epidist_transform_data_model(data, family, formula, ...)
data |
An object with class corresponding to an implemented model. |
family |
A description of the response distribution and link function to
be used in the model created using |
formula |
A formula object created using |
... |
Additional arguments passed to |
Other transform_data:
epidist_transform_data()
,
epidist_transform_data_model()
This method transforms data into the format required by the marginal model by:
Identifying required columns for the marginal model
Summarising the data by counting unique combinations of these columns and
any variables in the model formula using .summarise_n_by_formula()
Converting the summarised data to a marginal model object using
new_epidist_marginal_model()
Informing the user about any data aggregation that occurred using
.inform_data_summarised()
## S3 method for class 'epidist_marginal_model' epidist_transform_data_model(data, family, formula, ...)
## S3 method for class 'epidist_marginal_model' epidist_transform_data_model(data, family, formula, ...)
data |
The data to transform |
family |
The epidist family object specifying the distribution |
formula |
The model formula |
... |
Additional arguments passed to methods |
Other marginal_model:
as_epidist_marginal_model()
,
as_epidist_marginal_model.epidist_aggregate_data()
,
as_epidist_marginal_model.epidist_linelist_data()
,
epidist_family_model.epidist_marginal_model()
,
epidist_formula_model.epidist_marginal_model()
,
is_epidist_marginal_model()
,
new_epidist_marginal_model()
This method transforms data into the format required by the naive model by:
Identifying required columns for the naive model
Summarising the data by counting unique combinations of these columns and
any variables in the model formula using .summarise_n_by_formula()
Converting the summarised data to a naive model object using
new_epidist_naive_model()
Informing the user about any data aggregation that occurred using
.inform_data_summarised()
## S3 method for class 'epidist_naive_model' epidist_transform_data_model(data, family, formula, ...)
## S3 method for class 'epidist_naive_model' epidist_transform_data_model(data, family, formula, ...)
data |
The data to transform |
family |
The epidist family object specifying the distribution |
formula |
The model formula |
... |
Additional arguments passed to methods |
Other naive_model:
as_epidist_naive_model()
,
as_epidist_naive_model.epidist_aggregate_data()
,
as_epidist_naive_model.epidist_linelist_data()
,
epidist_formula_model.epidist_naive_model()
,
is_epidist_naive_model()
,
new_epidist_naive_model()
epidist_aggregate_data
classCheck if data has the epidist_aggregate_data
class
is_epidist_aggregate_data(data, ...)
is_epidist_aggregate_data(data, ...)
data |
The data to convert |
... |
Additional arguments |
Other aggregate_data:
as_epidist_aggregate_data()
,
as_epidist_aggregate_data.data.frame()
,
as_epidist_aggregate_data.default()
,
as_epidist_aggregate_data.epidist_linelist_data()
,
assert_epidist.epidist_aggregate_data()
,
new_epidist_aggregate_data()
epidist_latent_model
classCheck if data has the epidist_latent_model
class
is_epidist_latent_model(data)
is_epidist_latent_model(data)
data |
An object |
Other latent_model:
as_epidist_latent_model()
,
as_epidist_latent_model.epidist_aggregate_data()
,
as_epidist_latent_model.epidist_linelist_data()
,
epidist_family_model.epidist_latent_model()
,
epidist_formula_model.epidist_latent_model()
,
epidist_model_prior.epidist_latent_model()
,
new_epidist_latent_model()
epidist_linelist_data
classCheck if data has the epidist_linelist_data
class
is_epidist_linelist_data(data, ...)
is_epidist_linelist_data(data, ...)
data |
The data to convert |
... |
Additional arguments |
Other linelist_data:
as_epidist_linelist_data()
,
as_epidist_linelist_data.data.frame()
,
as_epidist_linelist_data.default()
,
as_epidist_linelist_data.epidist_aggregate_data()
,
assert_epidist.epidist_linelist_data()
,
new_epidist_linelist_data()
epidist_marginal_model
classCheck if data has the epidist_marginal_model
class
is_epidist_marginal_model(data)
is_epidist_marginal_model(data)
data |
A |
Other marginal_model:
as_epidist_marginal_model()
,
as_epidist_marginal_model.epidist_aggregate_data()
,
as_epidist_marginal_model.epidist_linelist_data()
,
epidist_family_model.epidist_marginal_model()
,
epidist_formula_model.epidist_marginal_model()
,
epidist_transform_data_model.epidist_marginal_model()
,
new_epidist_marginal_model()
epidist_naive_model
classCheck if data has the epidist_naive_model
class
is_epidist_naive_model(data)
is_epidist_naive_model(data)
data |
An object. |
Other naive_model:
as_epidist_naive_model()
,
as_epidist_naive_model.epidist_aggregate_data()
,
as_epidist_naive_model.epidist_linelist_data()
,
epidist_formula_model.epidist_naive_model()
,
epidist_transform_data_model.epidist_naive_model()
,
new_epidist_naive_model()
epidist_aggregate_data
objectsClass constructor for epidist_aggregate_data
objects
new_epidist_aggregate_data(data)
new_epidist_aggregate_data(data)
data |
A data.frame to convert |
An object of class epidist_aggregate_data
Other aggregate_data:
as_epidist_aggregate_data()
,
as_epidist_aggregate_data.data.frame()
,
as_epidist_aggregate_data.default()
,
as_epidist_aggregate_data.epidist_linelist_data()
,
assert_epidist.epidist_aggregate_data()
,
is_epidist_aggregate_data()
df <- new_epidist_aggregate_data(data.frame()) class(df)
df <- new_epidist_aggregate_data(data.frame()) class(df)
epidist_latent_model
objectsClass constructor for epidist_latent_model
objects
new_epidist_latent_model(data, ...)
new_epidist_latent_model(data, ...)
data |
An object to be set with the class |
... |
Additional arguments passed to methods. |
An object of class epidist_latent_model
Other latent_model:
as_epidist_latent_model()
,
as_epidist_latent_model.epidist_aggregate_data()
,
as_epidist_latent_model.epidist_linelist_data()
,
epidist_family_model.epidist_latent_model()
,
epidist_formula_model.epidist_latent_model()
,
epidist_model_prior.epidist_latent_model()
,
is_epidist_latent_model()
epidist_linelist_data
objectsClass constructor for epidist_linelist_data
objects
new_epidist_linelist_data(data)
new_epidist_linelist_data(data)
data |
A data.frame to convert |
An object of class epidist_linelist_data
Other linelist_data:
as_epidist_linelist_data()
,
as_epidist_linelist_data.data.frame()
,
as_epidist_linelist_data.default()
,
as_epidist_linelist_data.epidist_aggregate_data()
,
assert_epidist.epidist_linelist_data()
,
is_epidist_linelist_data()
epidist_marginal_model
objectsClass constructor for epidist_marginal_model
objects
new_epidist_marginal_model(data)
new_epidist_marginal_model(data)
data |
A data.frame to convert |
An object of class epidist_marginal_model
Other marginal_model:
as_epidist_marginal_model()
,
as_epidist_marginal_model.epidist_aggregate_data()
,
as_epidist_marginal_model.epidist_linelist_data()
,
epidist_family_model.epidist_marginal_model()
,
epidist_formula_model.epidist_marginal_model()
,
epidist_transform_data_model.epidist_marginal_model()
,
is_epidist_marginal_model()
epidist_naive_model
objectsClass constructor for epidist_naive_model
objects
new_epidist_naive_model(data)
new_epidist_naive_model(data)
data |
An object to be set with the class |
An object of class epidist_naive_model
.
Other naive_model:
as_epidist_naive_model()
,
as_epidist_naive_model.epidist_aggregate_data()
,
as_epidist_naive_model.epidist_linelist_data()
,
epidist_formula_model.epidist_naive_model()
,
epidist_transform_data_model.epidist_naive_model()
,
is_epidist_naive_model()
Extract samples of the delay distribution parameters
predict_delay_parameters(fit, newdata = NULL, ...) predict_dpar(fit, newdata = NULL, ...)
predict_delay_parameters(fit, newdata = NULL, ...) predict_dpar(fit, newdata = NULL, ...)
fit |
A model fit with |
newdata |
An optional data.frame for which to evaluate predictions. If
|
... |
Additional arguments passed to |
Other postprocess:
add_mean_sd()
,
add_mean_sd.default()
,
add_mean_sd.gamma_samples()
,
add_mean_sd.lognormal_samples()
Linelist data for the Ebola virus collected in Sierra Leone. If you use this data in your work, please cite the corresponding paper.
sierra_leone_ebola_data
sierra_leone_ebola_data
A tibble
with 8,358 rows and 8 columns:
Unique identification number for the case
Name as character, omitted
Age as numeric
Sex as character, either "F", "M" or NA
The date symptoms began
The date the sample was tested
The district (ADM2)
The chiefdom (ADM3)
https://www.pnas.org/doi/full/10.1073/pnas.1518587113
This function simulates cases from an exponential distribution. The user may
specify the rate parameter r
, the sample size, and the upper bound of the
survival time. If the rate parameter is 0, then this function defaults to the
uniform distribution.
simulate_exponential_cases(r = 0.2, sample_size = 10000, seed, t = 30)
simulate_exponential_cases(r = 0.2, sample_size = 10000, seed, t = 30)
r |
The exponential growth rate parameter. Defaults to 0.2. |
sample_size |
The number of cases to simulate. Defaults to 10000. |
seed |
The random seed to be used in the simulation process. |
t |
Upper bound of the survival time. Defaults to 30. |
A data.frame
with two columns: case
(case number) and ptime
(primary event time).
Other simulate:
simulate_gillespie()
,
simulate_secondary()
,
simulate_uniform_cases()
This function simulates cases from an stochastic SIR model. The user may
specify the initial epidemic growth rate , the rate of recovery gamma
, the initial number of infected cases
, and the total
population size
.
simulate_gillespie(r = 0.2, gamma = 1/7, I0 = 50, N = 10000, seed)
simulate_gillespie(r = 0.2, gamma = 1/7, I0 = 50, N = 10000, seed)
r |
The initial epidemic growth rate. Defaults to 0.2. |
gamma |
The rate of recovery. Defaults to 1/7. |
I0 |
The initial number of infected people. Defaults to 50. |
N |
The total population size. Defaults to 10000. |
seed |
The random seed to be used in the simulation process. |
A data.frame
with two columns: case
(case number) and ptime
(primary event time).
Other simulate:
simulate_exponential_cases()
,
simulate_secondary()
,
simulate_uniform_cases()
This function simulates secondary events based on a given delay
distribution. The input dataset should have the primary event times in a
column named ptime
.
simulate_secondary(data, dist = rlnorm, ...)
simulate_secondary(data, dist = rlnorm, ...)
data |
A data frame with the primary event times. |
dist |
The delay distribution to be used. Defaults to |
... |
Arguments to be passed to the delay distribution function. |
A data.frame
that augments data
with two new columns: delay
(secondary event latency) and stime
(the time of the secondary event).
Other simulate:
simulate_exponential_cases()
,
simulate_gillespie()
,
simulate_uniform_cases()
This function simulates cases from a uniform distribution, where the primary
event times are uniformly distributed between 0 and t
.
simulate_uniform_cases(sample_size = 1000, t = 60)
simulate_uniform_cases(sample_size = 1000, t = 60)
sample_size |
The number of cases to simulate. |
t |
Upper bound of the uniform distribution to generate primary event times. |
A data.frame
with two columns: case
(case number) and ptime
(primary event time).
Other simulate:
simulate_exponential_cases()
,
simulate_gillespie()
,
simulate_secondary()