-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issues 82 and 83: Use term generics and add generic defaults with sto…
…p message (#91) * Rename methods to generics, add more defaults, add family tags * Update stop message to be more informative
- Loading branch information
Showing
16 changed files
with
299 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#' Default method used when preparing data | ||
#' | ||
#' @param model Character string, model type to prepare to use. | ||
#' Supported options are "ltcad". | ||
#' @param ... Additional arguments passed to model specific `epidist_prepare` | ||
#' functions | ||
#' @rdname epidist_prepare | ||
#' @method epidist_prepare default | ||
#' @family defaults | ||
#' @export | ||
epidist_prepare.default <- function(data, model, ...) { | ||
model <- match.arg(model, choices = c("ltcad")) | ||
class(data) <- c(class(data), paste0("epidist_", model)) | ||
epidist_prepare(data, ...) | ||
} | ||
|
||
#' Default method for defining a model specific formula | ||
#' | ||
#' @inheritParams epidist_formula | ||
#' @param ... Additional arguments for method. | ||
#' @family defaults | ||
#' @export | ||
epidist_formula.default <- function(data, ...) { | ||
stop( | ||
"No epidist_formula method implemented for the class ", class(x), "\n", | ||
"See methods(epidist_formula) for available methods" | ||
) | ||
} | ||
|
||
#' Default method for defining a model specific family | ||
#' | ||
#' @inheritParams epidist_family | ||
#' @param ... Additional arguments for method. | ||
#' @family defaults | ||
#' @export | ||
epidist_family.default <- function(data, ...) { | ||
stop( | ||
"No epidist_family method implemented for the class ", class(x), "\n", | ||
"See methods(epidist_family) for available methods" | ||
) | ||
} | ||
|
||
#' Default method for defining model specific priors | ||
#' | ||
#' @inheritParams epidist_priors | ||
#' @param ... Additional arguments for method. | ||
#' @family defaults | ||
#' @export | ||
epidist_priors.default <- function(data, ...) { | ||
stop( | ||
"No epidist_priors method implemented for the class ", class(x), "\n", | ||
"See methods(epidist_priors) for available methods" | ||
) | ||
} | ||
|
||
#' Default method for defining model specific Stan code | ||
#' | ||
#' @inheritParams epidist_stancode | ||
#' @param ... Additional arguments for method. | ||
#' @family defaults | ||
#' @export | ||
epidist_stancode.default <- function(data, ...) { | ||
stop( | ||
"No epidist_stancode method implemented for the class ", class(x), "\n", | ||
"See methods(epidist_stancode) for available methods" | ||
) | ||
} | ||
|
||
#' Default method used for interface using `brms` | ||
#' | ||
#' @inheritParams epidist | ||
#' @rdname epidist.default | ||
#' @method epidist default | ||
#' @family defaults | ||
#' @export | ||
epidist.default <- function(data, formula = epidist_formula(data), | ||
family = epidist_family(data), | ||
priors = epidist_priors(data), | ||
stancode = epidist_stancode(data), fn = brms::brm, | ||
...) { | ||
|
||
fit <- fn( | ||
formula = formula, family = family, stanvars = stancode, | ||
backend = "cmdstanr", data = data, ... | ||
) | ||
|
||
class(fit) <- c(class(fit), "epidist_fit") | ||
|
||
return(fit) | ||
} |
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.
Oops, something went wrong.