diff --git a/R/diagnostics.R b/R/diagnostics.R index 0ffea953f..8d7a5e0a3 100644 --- a/R/diagnostics.R +++ b/R/diagnostics.R @@ -3,7 +3,6 @@ #' This 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.table` 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 @@ -15,8 +14,7 @@ #' `max_treedepth` #' * `per_at_max_treedepth`: the proportion of samples which attained the #' `max_treedepth` -#' -#' When the fitting algorithm is not `"sampling"` (see `?brms::brm` for other +#' When the fitting algorithm is not `"sampling"` (see [brms::brm()] for other #' possible algorithms) then diagnostics are yet to be implemented. #' @param fit A fitted model of class `epidist_fit` #' @family diagnostics diff --git a/R/generics.R b/R/generics.R index 6a97d882b..85c0f9219 100644 --- a/R/generics.R +++ b/R/generics.R @@ -44,8 +44,8 @@ epidist_stancode <- function(data, ...) { #' @param formula ... #' @param family ... #' @param prior ... -#' @param fn Likely `brms::brm`. Also possible to be `brms::make_stancode` or -#' `brms::make_standata`. +#' @param fn Likely [brms::brm()]. Also possible to be [brms::make_stancode()] +#' or [brms::make_standata()]. #' @param ... Additional arguments for method. #' @family generics #' @export diff --git a/R/latent_individual.R b/R/latent_individual.R index 6ef83ca44..fc20cc8fa 100644 --- a/R/latent_individual.R +++ b/R/latent_individual.R @@ -32,7 +32,7 @@ assert_latent_individual_input <- function(data) { #' (positive, numeric) upper and lower bounds for the primary and secondary #' event times, as well as a (positive, numeric) time that observation takes #' place. The output of this function is a `epidist_latent_individual` class -#' object, which may be passed to `epidist()` to perform inference for the +#' object, which may be passed to [epidist()] to perform inference for the #' model. #' #' @param data A `data.frame` or `data.table` containing line list data @@ -143,8 +143,8 @@ epidist_family.epidist_latent_individual <- function(data, #' Define a formula for the latent_individual model #' #' @param data ... -#' @param family The output of `epidist_family()` -#' @param formula As produced by `brms::brmsformula` +#' @param family The output of [epidist_family()] +#' @param formula As produced by [brms::brmsformula()] #' @param ... ... #' @method epidist_formula epidist_latent_individual #' @family latent_individual diff --git a/R/latent_lognormal.R b/R/latent_lognormal.R index 1df20e30e..ddd2029b5 100644 --- a/R/latent_lognormal.R +++ b/R/latent_lognormal.R @@ -1,9 +1,9 @@ #' Draws from the posterior predictive distribution #' -#' See [`brms::posterior_predict`]. +#' See [brms::posterior_predict()]. #' #' @param i The index of the observation to predict -#' @param prep The result of a call to [`brms::posterior_predict`] +#' @param prep The result of a call to [brms::posterior_predict()] #' @param ... Additional arguments #' @family postprocess #' @autoglobal @@ -32,7 +32,7 @@ posterior_predict_latent_lognormal <- function(i, prep, ...) { # nolint: object_ #' Draws from the expected value of the posterior predictive distribution #' -#' See [`brms::posterior_epred`]. +#' See [brms::posterior_epred()]. #' #' @param prep The result of a call to [`brms::prepare_predictions`] #' @family postprocess diff --git a/R/postprocess.R b/R/postprocess.R index 03e61163c..de9f71b73 100644 --- a/R/postprocess.R +++ b/R/postprocess.R @@ -1,8 +1,8 @@ #' Extract samples of the delay distribution parameters #' -#' @param fit A model fit with `epidist::epidist` +#' @param fit A model fit with [epidist::epidist()] #' @inheritParams brms::prepare_predictions -#' @param ... Additional arguments passed to `brms::prepare_predictions` +#' @param ... Additional arguments passed to [brms::prepare_predictions()] #' @family postprocess #' @autoglobal #' @export diff --git a/R/prior.R b/R/prior.R index 1c7c89c85..7f01990e8 100644 --- a/R/prior.R +++ b/R/prior.R @@ -1,4 +1,13 @@ -#' Define prior from defaults, model, family, user +#' Define prior distributions using `brms` defaults, model specific priors, +#' family specific priors, and user provided priors +#' +#' This function obtains the `brms` default prior distributions for a particular +#' model, then uses [replace_prior()] to update the prior distributions using: +#' 1. Model specific prior distributions from [epidist_model_prior()] +#' 2. Family specific prior distributions from [epidist_family_prior()] +#' 3. User provided prior distributions +#' Each element of this list overwrites previous elements, such that user +#' provided prior distribution have the highest priority. #' #' @param data ... #' @param family ... @@ -17,7 +26,10 @@ epidist_prior <- function(data, family, formula, prior) { return(prior) } -#' Model specific prior +#' Model specific prior distributions +#' +#' This function contains `brms` prior distributions which are specific to +#' particular `epidist` models e.g. the `latent_lognormal` model. #' #' @inheritParams epidist_prior #' @param ... ... @@ -28,19 +40,22 @@ epidist_model_prior <- function(data, ...) { UseMethod("epidist_model_prior") } -#' Default empty model specific prior +#' Default model specific prior distributions +#' +#' By default, we do not return any model specific prior distributions. #' #' @inheritParams epidist_prior #' @param ... ... #' @family prior #' @export epidist_model_prior.default <- function(data, formula, ...) { - # Currently there are not model-specific priors - # In future there might be, but we need to be careful about Stan code return(NULL) } -#' Family specific prior +#' Family specific prior distributions +#' +#' This function contains `brms` prior distributions which are specific to +#' particular likelihood families e.g. [brms::lognormal()]. #' #' @inheritParams epidist_prior #' @param ... ... @@ -51,7 +66,9 @@ epidist_family_prior <- function(family, ...) { UseMethod("epidist_family_prior") } -#' Default empty family specific prior +#' Default family specific prior distributions +#' +#' By default, we do not return any family specific prior distributions. #' #' @inheritParams epidist_prior #' @param ... ... @@ -61,7 +78,9 @@ epidist_family_prior.default <- function(family, formula, ...) { return(NULL) } -#' Family specific prior for lognormal +#' Family specific prior distributions for the lognormal family +#' +#' We suggest priors to overwrite the `brms` defaults for the lognormal family. #' #' @inheritParams epidist_prior #' @param ... ... @@ -76,10 +95,16 @@ epidist_family_prior.lognormal <- function(family, formula, ...) { return(prior) } -#' Replace a brms prior only if it exists +#' Replace `brms` prior distributions +#' +#' This function takes `old_prior` and replaces any prior distributions +#' contained in it by the corresponding prior distribution in `new_prior`. +#' If there is a prior distribution in `new_prior` with no match in `old_prior` +#' then the function will error and give the name of the new prior distribution +#' with no match. #' #' @param old_prior One or more prior distributions in the class `brmsprior` -#' @param new_prior One prior distribution in the class `brmsprior` +#' @param new_prior One or more prior distributions in the class `brmsprior` #' @family prior #' @importFrom cli cli_inform #' @importFrom utils capture.output diff --git a/R/utils.R b/R/utils.R index cf5a0123b..ca3328d8b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,6 +1,9 @@ -#' Read in a epidist Stan code chunk +#' Read in an `epidist` Stan code chunk #' -#' @param path The path within the "stan" folder of the installed epidist +#' This function is used to obtain Stan code chunks from the `stan/` folder of +#' the `epidist` package. It is used within the [epidist_stancode()] function. +#' +#' @param path The path within the `stan/` folder of the installed `epidist` #' package to the Stan code chunk of interest. #' @return A character string containing the Stan code chunk of interest. #' @family utils @@ -10,10 +13,14 @@ epidist_stan_chunk <- function(path) { paste(readLines(local_path), collapse = "\n") } -#' Label a epidist Stan model with a version indicator +#' Label a `epidist` Stan model with a version indicator +#' +#' This function is used within [epidist_stancode()] to label the generated Stan +#' code with the version of `epidist` used. To view the full Stan code for any +#' particular `epidist` model, we recommend use of [brms::make_stancode()]. #' -#' @return A brms stanvar chunk containing the package version used to build -#' the Stan code. +#' @return A `brms` Stan chunk containing the `epidist` package version used to +#' build the Stan code. #' @family utils #' @export epidist_version_stanvar <- function() { @@ -26,7 +33,7 @@ epidist_version_stanvar <- function() { #' #' This function rounds an input `x` down to the nearest multiple of some number #' `f`. For example, if `f = 0.2` and `x = 1.5` then the output would be 1.4. -#' Or, if `f = 1` then `floor_mult` behaves as `floor`. +#' If `f = 1` then `floor_mult` behaves as `floor`. #' #' @param x A number to be rounded down #' @param f A number specifying the multiple to be rounded down to diff --git a/man/as_latent_individual.Rd b/man/as_latent_individual.Rd index fec553654..9e7d35c9f 100644 --- a/man/as_latent_individual.Rd +++ b/man/as_latent_individual.Rd @@ -19,7 +19,7 @@ this, the \code{data} must already have columns for the case number (integer), (positive, numeric) upper and lower bounds for the primary and secondary event times, as well as a (positive, numeric) time that observation takes place. The output of this function is a \code{epidist_latent_individual} class -object, which may be passed to \code{epidist()} to perform inference for the +object, which may be passed to \code{\link[=epidist]{epidist()}} to perform inference for the model. } \seealso{ diff --git a/man/epidist.Rd b/man/epidist.Rd index ed53cc29b..0d10ca789 100644 --- a/man/epidist.Rd +++ b/man/epidist.Rd @@ -15,8 +15,8 @@ epidist(data, formula, family, prior, fn, ...) \item{prior}{...} -\item{fn}{Likely \code{brms::brm}. Also possible to be \code{brms::make_stancode} or -\code{brms::make_standata}.} +\item{fn}{Likely \code{\link[brms:brm]{brms::brm()}}. Also possible to be \code{\link[brms:stancode]{brms::make_stancode()}} +or \code{\link[brms:standata]{brms::make_standata()}}.} \item{...}{Additional arguments for method.} } diff --git a/man/epidist.default.Rd b/man/epidist.default.Rd index e8750d7f2..0c7f5a0af 100644 --- a/man/epidist.default.Rd +++ b/man/epidist.default.Rd @@ -22,8 +22,8 @@ \item{prior}{...} -\item{fn}{Likely \code{brms::brm}. Also possible to be \code{brms::make_stancode} or -\code{brms::make_standata}.} +\item{fn}{Likely \code{\link[brms:brm]{brms::brm()}}. Also possible to be \code{\link[brms:stancode]{brms::make_stancode()}} +or \code{\link[brms:standata]{brms::make_standata()}}.} \item{...}{Additional arguments for method.} } diff --git a/man/epidist_diagnostics.Rd b/man/epidist_diagnostics.Rd index 4a44b5e8f..6860a82b4 100644 --- a/man/epidist_diagnostics.Rd +++ b/man/epidist_diagnostics.Rd @@ -13,8 +13,6 @@ epidist_diagnostics(fit) This function computes diagnostics to assess the quality of a fitted model. When the fitting algorithm used is \code{"sampling"} (HMC) then the output of \code{epidist_diagnostics} is a \code{data.table} containing: -} -\details{ \itemize{ \item \code{time}: the total time taken to fit all chains \item \code{samples}: the total number of samples across all chains @@ -27,9 +25,8 @@ transitions \code{max_treedepth} \item \code{per_at_max_treedepth}: the proportion of samples which attained the \code{max_treedepth} -} - -When the fitting algorithm is not \code{"sampling"} (see \code{?brms::brm} for other +When the fitting algorithm is not \code{"sampling"} (see \code{\link[brms:brm]{brms::brm()}} for other possible algorithms) then diagnostics are yet to be implemented. } +} \concept{diagnostics} diff --git a/man/epidist_family_prior.Rd b/man/epidist_family_prior.Rd index 826f9ae5e..47e3aeac4 100644 --- a/man/epidist_family_prior.Rd +++ b/man/epidist_family_prior.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/prior.R \name{epidist_family_prior} \alias{epidist_family_prior} -\title{Family specific prior} +\title{Family specific prior distributions} \usage{ epidist_family_prior(family, ...) } @@ -12,7 +12,8 @@ epidist_family_prior(family, ...) \item{...}{...} } \description{ -Family specific prior +This function contains \code{brms} prior distributions which are specific to +particular likelihood families e.g. \code{\link[brms:brmsfamily]{brms::lognormal()}}. } \seealso{ Other prior: diff --git a/man/epidist_family_prior.default.Rd b/man/epidist_family_prior.default.Rd index 11d65481a..26ba82edf 100644 --- a/man/epidist_family_prior.default.Rd +++ b/man/epidist_family_prior.default.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/prior.R \name{epidist_family_prior.default} \alias{epidist_family_prior.default} -\title{Default empty family specific prior} +\title{Default family specific prior distributions} \usage{ \method{epidist_family_prior}{default}(family, formula, ...) } @@ -14,7 +14,7 @@ \item{...}{...} } \description{ -Default empty family specific prior +By default, we do not return any family specific prior distributions. } \seealso{ Other prior: diff --git a/man/epidist_family_prior.lognormal.Rd b/man/epidist_family_prior.lognormal.Rd index 74a92ab64..a6cb7012d 100644 --- a/man/epidist_family_prior.lognormal.Rd +++ b/man/epidist_family_prior.lognormal.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/prior.R \name{epidist_family_prior.lognormal} \alias{epidist_family_prior.lognormal} -\title{Family specific prior for lognormal} +\title{Family specific prior distributions for the lognormal family} \usage{ \method{epidist_family_prior}{lognormal}(family, formula, ...) } @@ -14,7 +14,7 @@ \item{...}{...} } \description{ -Family specific prior for lognormal +We suggest priors to overwrite the \code{brms} defaults for the lognormal family. } \seealso{ Other prior: diff --git a/man/epidist_formula.epidist_latent_individual.Rd b/man/epidist_formula.epidist_latent_individual.Rd index dd7198373..818052280 100644 --- a/man/epidist_formula.epidist_latent_individual.Rd +++ b/man/epidist_formula.epidist_latent_individual.Rd @@ -9,9 +9,9 @@ \arguments{ \item{data}{...} -\item{family}{The output of \code{epidist_family()}} +\item{family}{The output of \code{\link[=epidist_family]{epidist_family()}}} -\item{formula}{As produced by \code{brms::brmsformula}} +\item{formula}{As produced by \code{\link[brms:brmsformula]{brms::brmsformula()}}} \item{...}{...} } diff --git a/man/epidist_model_prior.Rd b/man/epidist_model_prior.Rd index 094789c3e..822eac736 100644 --- a/man/epidist_model_prior.Rd +++ b/man/epidist_model_prior.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/prior.R \name{epidist_model_prior} \alias{epidist_model_prior} -\title{Model specific prior} +\title{Model specific prior distributions} \usage{ epidist_model_prior(data, ...) } @@ -12,7 +12,8 @@ epidist_model_prior(data, ...) \item{...}{...} } \description{ -Model specific prior +This function contains \code{brms} prior distributions which are specific to +particular \code{epidist} models e.g. the \code{latent_lognormal} model. } \seealso{ Other prior: diff --git a/man/epidist_model_prior.default.Rd b/man/epidist_model_prior.default.Rd index 1c3a0a83e..a99bfe555 100644 --- a/man/epidist_model_prior.default.Rd +++ b/man/epidist_model_prior.default.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/prior.R \name{epidist_model_prior.default} \alias{epidist_model_prior.default} -\title{Default empty model specific prior} +\title{Default model specific prior distributions} \usage{ \method{epidist_model_prior}{default}(data, formula, ...) } @@ -14,7 +14,7 @@ \item{...}{...} } \description{ -Default empty model specific prior +By default, we do not return any model specific prior distributions. } \seealso{ Other prior: diff --git a/man/epidist_prior.Rd b/man/epidist_prior.Rd index 34990b62a..1649fabd5 100644 --- a/man/epidist_prior.Rd +++ b/man/epidist_prior.Rd @@ -2,7 +2,8 @@ % Please edit documentation in R/prior.R \name{epidist_prior} \alias{epidist_prior} -\title{Define prior from defaults, model, family, user} +\title{Define prior distributions using \code{brms} defaults, model specific priors, +family specific priors, and user provided priors} \usage{ epidist_prior(data, family, formula, prior) } @@ -16,7 +17,15 @@ epidist_prior(data, family, formula, prior) \item{prior}{...} } \description{ -Define prior from defaults, model, family, user +This function obtains the \code{brms} default prior distributions for a particular +model, then uses \code{\link[=replace_prior]{replace_prior()}} to update the prior distributions using: +\enumerate{ +\item Model specific prior distributions from \code{\link[=epidist_model_prior]{epidist_model_prior()}} +\item Family specific prior distributions from \code{\link[=epidist_family_prior]{epidist_family_prior()}} +\item User provided prior distributions +Each element of this list overwrites previous elements, such that user +provided prior distribution have the highest priority. +} } \seealso{ Other prior: diff --git a/man/epidist_stan_chunk.Rd b/man/epidist_stan_chunk.Rd index 69a7738aa..24edc5068 100644 --- a/man/epidist_stan_chunk.Rd +++ b/man/epidist_stan_chunk.Rd @@ -2,19 +2,20 @@ % Please edit documentation in R/utils.R \name{epidist_stan_chunk} \alias{epidist_stan_chunk} -\title{Read in a epidist Stan code chunk} +\title{Read in an \code{epidist} Stan code chunk} \usage{ epidist_stan_chunk(path) } \arguments{ -\item{path}{The path within the "stan" folder of the installed epidist +\item{path}{The path within the \verb{stan/} folder of the installed \code{epidist} package to the Stan code chunk of interest.} } \value{ A character string containing the Stan code chunk of interest. } \description{ -Read in a epidist Stan code chunk +This function is used to obtain Stan code chunks from the \verb{stan/} folder of +the \code{epidist} package. It is used within the \code{\link[=epidist_stancode]{epidist_stancode()}} function. } \seealso{ Other utils: diff --git a/man/epidist_version_stanvar.Rd b/man/epidist_version_stanvar.Rd index 41d4dde01..e4bbfdfda 100644 --- a/man/epidist_version_stanvar.Rd +++ b/man/epidist_version_stanvar.Rd @@ -2,16 +2,18 @@ % Please edit documentation in R/utils.R \name{epidist_version_stanvar} \alias{epidist_version_stanvar} -\title{Label a epidist Stan model with a version indicator} +\title{Label a \code{epidist} Stan model with a version indicator} \usage{ epidist_version_stanvar() } \value{ -A brms stanvar chunk containing the package version used to build -the Stan code. +A \code{brms} Stan chunk containing the \code{epidist} package version used to +build the Stan code. } \description{ -Label a epidist Stan model with a version indicator +This function is used within \code{\link[=epidist_stancode]{epidist_stancode()}} to label the generated Stan +code with the version of \code{epidist} used. To view the full Stan code for any +particular \code{epidist} model, we recommend use of \code{\link[brms:stancode]{brms::make_stancode()}}. } \seealso{ Other utils: diff --git a/man/floor_mult.Rd b/man/floor_mult.Rd index 4047204a1..eff78a994 100644 --- a/man/floor_mult.Rd +++ b/man/floor_mult.Rd @@ -14,7 +14,7 @@ floor_mult(x, f = 1) \description{ This function rounds an input \code{x} down to the nearest multiple of some number \code{f}. For example, if \code{f = 0.2} and \code{x = 1.5} then the output would be 1.4. -Or, if \code{f = 1} then \code{floor_mult} behaves as \code{floor}. +If \code{f = 1} then \code{floor_mult} behaves as \code{floor}. } \seealso{ Other utils: diff --git a/man/posterior_epred_latent_lognormal.Rd b/man/posterior_epred_latent_lognormal.Rd index a7d888a81..1aac298a9 100644 --- a/man/posterior_epred_latent_lognormal.Rd +++ b/man/posterior_epred_latent_lognormal.Rd @@ -10,7 +10,7 @@ posterior_epred_latent_lognormal(prep) \item{prep}{The result of a call to \code{\link[brms:prepare_predictions]{brms::prepare_predictions}}} } \description{ -See \code{\link[brms:posterior_epred.brmsfit]{brms::posterior_epred}}. +See \code{\link[brms:posterior_epred.brmsfit]{brms::posterior_epred()}}. } \seealso{ Other postprocess: diff --git a/man/posterior_predict_latent_lognormal.Rd b/man/posterior_predict_latent_lognormal.Rd index b6878de78..5417415b9 100644 --- a/man/posterior_predict_latent_lognormal.Rd +++ b/man/posterior_predict_latent_lognormal.Rd @@ -9,12 +9,12 @@ posterior_predict_latent_lognormal(i, prep, ...) \arguments{ \item{i}{The index of the observation to predict} -\item{prep}{The result of a call to \code{\link[brms:posterior_predict.brmsfit]{brms::posterior_predict}}} +\item{prep}{The result of a call to \code{\link[brms:posterior_predict.brmsfit]{brms::posterior_predict()}}} \item{...}{Additional arguments} } \description{ -See \code{\link[brms:posterior_predict.brmsfit]{brms::posterior_predict}}. +See \code{\link[brms:posterior_predict.brmsfit]{brms::posterior_predict()}}. } \seealso{ Other postprocess: diff --git a/man/predict_delay_parameters.Rd b/man/predict_delay_parameters.Rd index 29b004a36..91aa79b71 100644 --- a/man/predict_delay_parameters.Rd +++ b/man/predict_delay_parameters.Rd @@ -10,7 +10,7 @@ predict_delay_parameters(fit, newdata = NULL, ...) predict_dpar(fit, newdata = NULL, ...) } \arguments{ -\item{fit}{A model fit with \code{epidist::epidist}} +\item{fit}{A model fit with \code{\link[=epidist]{epidist()}}} \item{newdata}{An optional data.frame for which to evaluate predictions. If \code{NULL} (default), the original data of the model is used. @@ -18,7 +18,7 @@ predict_dpar(fit, newdata = NULL, ...) variables of this factor are zero. This allows, for instance, to make predictions of the grand mean when using sum coding.} -\item{...}{Additional arguments passed to \code{brms::prepare_predictions}} +\item{...}{Additional arguments passed to \code{\link[brms:prepare_predictions]{brms::prepare_predictions()}}} } \description{ Extract samples of the delay distribution parameters diff --git a/man/replace_prior.Rd b/man/replace_prior.Rd index 006b3fd38..94e1a5a9a 100644 --- a/man/replace_prior.Rd +++ b/man/replace_prior.Rd @@ -2,17 +2,21 @@ % Please edit documentation in R/prior.R \name{replace_prior} \alias{replace_prior} -\title{Replace a brms prior only if it exists} +\title{Replace \code{brms} prior distributions} \usage{ replace_prior(old_prior, new_prior) } \arguments{ \item{old_prior}{One or more prior distributions in the class \code{brmsprior}} -\item{new_prior}{One prior distribution in the class \code{brmsprior}} +\item{new_prior}{One or more prior distributions in the class \code{brmsprior}} } \description{ -Replace a brms prior only if it exists +This function takes \code{old_prior} and replaces any prior distributions +contained in it by the corresponding prior distribution in \code{new_prior}. +If there is a prior distribution in \code{new_prior} with no match in \code{old_prior} +then the function will error and give the name of the new prior distribution +with no match. } \seealso{ Other prior: