pipeline {bregr} | R Documentation |
Modeling and analysis pipeline
Description
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 |
y |
Character vector specifying dependent variables (response variables).
For GLM models, this is typically a single character (e.g., |
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 |
model_args |
A list of arguments passed to |
run_args |
A list of arguments passed to |
obj |
An object of class |
... |
Additional arguments depending on the called function.
|
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
-
br_pipeline()
: All-in-one end to end wrapper to run the regression analysis in batch. Which could be splitted into the following steps -
br_set_y()
: Set dependent variables for model construction. -
br_set_x()
: Set focal terms for model construction. -
br_set_x2()
: Set control terms for model construction (Optional in pipeline). -
br_set_model()
: Set model configurations. -
br_run()
: Run the regression analysis in batch.
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"
)