Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Issue 216: Use [pkg::func()] in roxygen comments everywhere #263

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions R/diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions R/latent_individual.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions R/latent_lognormal.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/postprocess.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 35 additions & 10 deletions R/prior.R
Original file line number Diff line number Diff line change
@@ -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 ...
Expand All @@ -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 ... ...
Expand All @@ -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 ... ...
Expand All @@ -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 ... ...
Expand All @@ -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 ... ...
Expand All @@ -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
Expand Down
19 changes: 13 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion man/as_latent_individual.Rd

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

4 changes: 2 additions & 2 deletions man/epidist.Rd

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

4 changes: 2 additions & 2 deletions man/epidist.default.Rd

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

7 changes: 2 additions & 5 deletions man/epidist_diagnostics.Rd

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

5 changes: 3 additions & 2 deletions man/epidist_family_prior.Rd

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

4 changes: 2 additions & 2 deletions man/epidist_family_prior.default.Rd

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

4 changes: 2 additions & 2 deletions man/epidist_family_prior.lognormal.Rd

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

4 changes: 2 additions & 2 deletions man/epidist_formula.epidist_latent_individual.Rd

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

5 changes: 3 additions & 2 deletions man/epidist_model_prior.Rd

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

4 changes: 2 additions & 2 deletions man/epidist_model_prior.default.Rd

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

13 changes: 11 additions & 2 deletions man/epidist_prior.Rd

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

Loading
Loading