-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Start working on double dispatch refactor * Set up the double dispatch structure * Documentation fixes * Standardise documentation a bit * Remove scratch * Fix to lintr * Start moving things into epidist_family_family * Add family to pkgdown * Rework of double dispatch. The family_family part is best as only a reparameterisation, the rest is the same for all families * Move the additional dpar info into helper, correct bug with "other" name, document and lint * Missing manual page * Add dispatch on family into reparam * Start thinking about tests * Add or move tests for the family functionality * Bug fix for dispatch on family * Move .add_dpar_info() into epidist_family * Improve documentation for .add_dpar_info() and move it to utils.R * Add test for .add_dpar_info * Fix to reparam.gamam documentation * Move data validation into higher level and lint
- Loading branch information
Showing
32 changed files
with
367 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#' Define `epidist` family | ||
#' | ||
#' This 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()]. | ||
#' | ||
#' @param data A `data.frame` containing line list data | ||
#' @param family Output of a call to `brms::brmsfamily()` | ||
#' @param ... ... | ||
#' | ||
#' @family family | ||
#' @export | ||
epidist_family <- function(data, family = "lognormal", ...) { | ||
epidist_validate(data) | ||
family <- brms:::validate_family(family) | ||
class(family) <- c(family$family, class(family)) | ||
family <- .add_dpar_info(family) | ||
custom_family <- epidist_family_model(data, family, ...) | ||
class(custom_family) <- c(family$family, class(custom_family)) | ||
custom_family <- epidist_family_reparam(custom_family) | ||
return(custom_family) | ||
} | ||
|
||
#' The model-specific parts of an `epidist_family()` call | ||
#' | ||
#' @inheritParams epidist_family | ||
#' @param family Output of a call to `brms::brmsfamily()` with additional | ||
#' information as provided by `.add_dpar_info()` | ||
#' @param ... Additional arguments passed to method. | ||
#' @rdname epidist_family_model | ||
#' @family family | ||
#' @export | ||
epidist_family_model <- function(data, family, ...) { | ||
UseMethod("epidist_family_model") | ||
} | ||
|
||
#' Default method for defining a model specific family | ||
#' | ||
#' @inheritParams epidist_family_model | ||
#' @param ... Additional arguments passed to method. | ||
#' @family family | ||
#' @export | ||
epidist_family_model.default <- function(data, ...) { | ||
cli_abort( | ||
"No epidist_family_model method implemented for the class ", class(data), | ||
"\n", "See methods(epidist_family_model) for available methods" | ||
) | ||
} | ||
|
||
#' Reparameterise an `epidist` family to align `brms` and Stan | ||
#' | ||
#' @inheritParams epidist_family | ||
#' @param ... Additional arguments passed to method. | ||
#' @rdname epidist_family_reparam | ||
#' @family family | ||
#' @export | ||
epidist_family_reparam <- function(family, ...) { | ||
UseMethod("epidist_family_reparam") | ||
} | ||
|
||
#' Default method for families which do not require a reparameterisation | ||
#' | ||
#' @inheritParams epidist_family_reparam | ||
#' @param ... Additional arguments passed to method. | ||
#' @family family | ||
#' @export | ||
epidist_family_reparam.default <- function(family, ...) { | ||
family$reparam <- family$dpars | ||
return(family) | ||
} | ||
|
||
#' Reparameterisation for the gamma family | ||
#' | ||
#' @inheritParams epidist_family_reparam | ||
#' @param ... Additional arguments passed to method. | ||
#' @family family | ||
#' @export | ||
epidist_family_reparam.gamma <- function(family, ...) { | ||
family$reparam <- c("shape", "shape ./ mu") | ||
return(family) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.