Skip to content

Commit

Permalink
add family the strategy object to be used later with different types …
Browse files Browse the repository at this point in the history
…of models
  • Loading branch information
n8thangreen committed Dec 2, 2024
1 parent b9008c2 commit 8b87034
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
28 changes: 25 additions & 3 deletions R/strategy_.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
#' @export
#'
strategy_maic <- function(formula = NULL,
family = gaussian(link = "identity"),
R = 1000) {
check_formula(formula)
check_family(family)

default_args <- formals()
args <- c(formula = formula, as.list(match.call())[-c(1,2)])
args <- modifyList(default_args, args)
Expand Down Expand Up @@ -57,8 +60,10 @@ strategy_maic <- function(formula = NULL,
#' @importFrom utils modifyList
#' @export
#
strategy_stc <- function(formula = NULL) {
strategy_stc <- function(formula = NULL,
family = gaussian(link = "identity")) {
check_formula(formula)
check_family(family)

default_args <- formals()
args <- c(formula = formula, as.list(match.call())[-c(1,2)])
Expand Down Expand Up @@ -103,8 +108,10 @@ strategy_stc <- function(formula = NULL) {
#' @export
#'
strategy_gcomp_ml <- function(formula = NULL,
family = gaussian(link = "identity"),
R = 1000) {
check_formula(formula)
check_family(family)

default_args <- formals()
args <- c(formula = formula, as.list(match.call())[-c(1,2)])
Expand Down Expand Up @@ -144,8 +151,10 @@ strategy_gcomp_ml <- function(formula = NULL,
#' @importFrom utils modifyList
#' @export
#'
strategy_gcomp_stan <- function(formula = NULL) {
strategy_gcomp_stan <- function(formula = NULL,
family = gaussian(link = "identity")) {
check_formula(formula)
check_family(family)

default_args <- formals()
args <- c(formula = formula, as.list(match.call())[-c(1,2)])
Expand All @@ -160,8 +169,10 @@ strategy_gcomp_stan <- function(formula = NULL) {
#' @importFrom utils modifyList
#' @export
#
strategy_mim <- function(formula = NULL) {
strategy_mim <- function(formula = NULL,
family = gaussian(link = "identity")) {
check_formula(formula)
check_family(family)

default_args <- formals()
args <- c(formula = formula, as.list(match.call())[-c(1,2)])
Expand All @@ -177,10 +188,21 @@ strategy_mim <- function(formula = NULL) {
#'
#' @param strategy Class name from `strategy_maic`, `strategy_stc`, `strategy_gcomp_ml`, `strategy_gcomp_stan`
#' @param formula Linear regression `formula` object
#' @param family `family` object from the `stats` library
#' @param ... Additional arguments
#'
#' @export
#'
new_strategy <- function(strategy, ...) {
structure(list(...), class = c(strategy, "strategy", "list"))
}

#
is_family <- function(obj) inherits(obj, "family")

#
check_family <- function(obj) {
if (!is_family(obj)) {
stop("family must be a family object")
}
}
3 changes: 2 additions & 1 deletion man/gen_data.Rd

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

18 changes: 11 additions & 7 deletions man/strategy.Rd

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

0 comments on commit 8b87034

Please sign in to comment.