From 8b8703489e202970be6f18c9dbda32107a770f8b Mon Sep 17 00:00:00 2001 From: Dr Nathan Green Date: Mon, 2 Dec 2024 17:16:32 +0000 Subject: [PATCH] add family the strategy object to be used later with different types of models --- R/strategy_.R | 28 +++++++++++++++++++++++++--- man/gen_data.Rd | 3 ++- man/strategy.Rd | 18 +++++++++++------- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/R/strategy_.R b/R/strategy_.R index 4707584..9f3fa21 100644 --- a/R/strategy_.R +++ b/R/strategy_.R @@ -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) @@ -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)]) @@ -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)]) @@ -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)]) @@ -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)]) @@ -177,6 +188,7 @@ 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 @@ -184,3 +196,13 @@ strategy_mim <- function(formula = NULL) { 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") + } +} diff --git a/man/gen_data.Rd b/man/gen_data.Rd index 78c7f9a..2e862c8 100644 --- a/man/gen_data.Rd +++ b/man/gen_data.Rd @@ -35,6 +35,7 @@ Generate simulated datasets of IPD covariates and outcome for a trial } \examples{ +\dontrun{ x <- gen_data( N = 100, b_trt = log(0.17), @@ -48,6 +49,6 @@ x <- gen_data( allocation = 2/3) head(x) - +} } \keyword{internal} diff --git a/man/strategy.Rd b/man/strategy.Rd index 1e5c0ed..524a9e8 100644 --- a/man/strategy.Rd +++ b/man/strategy.Rd @@ -10,28 +10,32 @@ \alias{new_strategy} \title{New strategy objects} \usage{ -strategy_maic(formula = NULL, R = 1000) +strategy_maic(formula = NULL, family = gaussian(link = "identity"), R = 1000) -strategy_stc(formula = NULL) +strategy_stc(formula = NULL, family = gaussian(link = "identity")) -strategy_gcomp_ml(formula = NULL, R = 1000) +strategy_gcomp_ml( + formula = NULL, + family = gaussian(link = "identity"), + R = 1000 +) -strategy_gcomp_stan(formula = NULL) +strategy_gcomp_stan(formula = NULL, family = gaussian(link = "identity")) -strategy_mim(formula = NULL) +strategy_mim(formula = NULL, family = gaussian(link = "identity")) new_strategy(strategy, ...) } \arguments{ \item{formula}{Linear regression \code{formula} object} +\item{family}{\code{family} object from the \code{stats} library} + \item{R}{The number of resamples used for the non-parametric bootstrap} \item{strategy}{Class name from \code{strategy_maic}, \code{strategy_stc}, \code{strategy_gcomp_ml}, \code{strategy_gcomp_stan}} \item{...}{Additional arguments} - -\item{ald}{Aggregate-level data} } \value{ \code{maic} class object