pipeline {bregr}R Documentation

Modeling and analysis pipeline

Description

[Stable]

Provides a set of functions for running batch regression analysis. Combines data setup, model configuration, and execution steps into a single workflow. Supports both GLM and Cox-PH models with options for focal/control terms and parallel processing.

Usage

br_pipeline(
  data,
  y,
  x,
  method,
  x2 = NULL,
  group_by = NULL,
  run_parallel = 1L,
  model_args = list(),
  run_args = list()
)

br_set_y(obj, y)

br_set_x(obj, ...)

br_set_x2(obj, ...)

br_set_model(obj, method, ...)

br_run(obj, ..., group_by = NULL, run_parallel = 1L)

Arguments

data

A data.frame containing all necessary variables for analysis. Column names should follow R's naming conventions.

y

Character vector specifying dependent variables (response variables). For GLM models, this is typically a single character (e.g., "outcome"). For Cox-PH models, it should be a length-2 vector in the format c("time", "status").

x

Character vector specifying focal independent terms (predictors).

method

Method for model construction. A string representing a complex method setting is acceptable, e.g., 'quasi(variance = "mu", link = "log")'.

x2

Character vector specifying control independent terms (predictor, optional).

group_by

A string specifying the group by column.

run_parallel

Integer, indicating cores to run the task, default is 1.

model_args

A list of arguments passed to br_set_model().

run_args

A list of arguments passed to br_run().

obj

An object of class breg.

...

Additional arguments depending on the called function.

  • br_set_x() for passing focal terms as characters.

  • br_set_x2() for passing control terms as characters.

  • br_set_model() for passing other configurations for modeling.

  • br_run() for passing other configurations for obtaining modeling results with broom.helpers::tidy_plus_plus(). e.g., The default value for exponentiate is FALSE (coefficients are not exponentiated). For logistic, and Cox-PH regressions models, exponentiate is set to TRUE at default.

Details

Please note the difference between variables and terms, e.g., x + poly(x, 2) has one variable x, but two terms x and poly(x, 2).

Value

An object of class breg with input values added to corresponding slot(s). For br_run(), the returned object is a breg object with results added to the slots ⁠@results⁠ and ⁠@results_tidy⁠, note that ⁠@models⁠ is updated to a list of constructed model object (See accessors).

Functions

See Also

accessors for accessing breg object properties.

Examples

library(bregr)
# 1. Pipeline -------------------------
# 1.1. A single linear model ----------
m <- breg(mtcars) |> # set model data
  br_set_y("mpg") |> # set dependent variable
  br_set_x("qsec") |> # set focal variables
  br_set_model("gaussian") |> # set model
  br_run() # run analysis

# get model tidy result
br_get_results(m, tidy = TRUE)
# or m@results_tidy

# compare with R's built-in function
lm(mpg ~ qsec, data = mtcars) |> summary()
# 1.2. Batch linear model -------------
# control variables are injected in all constructed models
# focal variables are injected in constructed models one by one
m2 <- breg(mtcars) |>
  br_set_y("mpg") |>
  br_set_x(colnames(mtcars)[2:4]) |> # set focal variables
  br_set_x2("vs") |> # set control variables
  br_set_model("gaussian") |>
  br_run()
# 1.3. Group by model -------------
m3 <- breg(mtcars) |>
  br_set_y("mpg") |>
  br_set_x("cyl") |>
  br_set_x2("wt") |> # set control variables
  br_set_model("gaussian") |>
  br_run(group_by = "am")

# 2. All-in-one pipeline wrapper ---
m4 <- br_pipeline(mtcars,
  y = "mpg",
  x = colnames(mtcars)[2:4],
  x2 = "vs",
  method = "gaussian"
)


[Package bregr version 1.0.0 Index]