build_model: Incremental block modelling.

View source: R/build_model.R

build_modelR Documentation

Incremental block modelling.

Description

build_model allows you to incrementally add terms to a linear regression model. Given a list of names of variables at each step, this function will run a series of models, adding the terms for each block incrementally to "build up" to a final model including all the terms.

Usage

build_model(dv, ..., data = NULL, opts = NULL, model = "lm")

Arguments

dv

The variable name to be used as the dependent variable.

...

Pass through variable names (or interaction terms) to add for each block. To add one term to a block, just pass it through directly; to add multiple terms, pass it through in a vector or list. Blocks will be added in the order they are passed to the function, and variables from previous blocks will be included with each subsequent block, so they do not need to be repeated.

data

An optional data frame containing the variables in the model. If not found in data, the variables are taken from the environment from which the function is called.

opts

List of arguments to be passed to the model function.

model

The type of model to use; supports 'lm', 'aov', and 'glm'.

Details

Note: Cases with missing data are dropped based on the final model that includes all the relevant terms. This ensures that all the models are tested on the same number of cases.

Value

A named list with the following elements:

formulas A list of the regression formulas used for each block.
models A list of all regression models.

Examples

# 2 blocks: Petal.Length; Petal.Length + Petal.Width
model1 <- build_model(Sepal.Length, Petal.Length, Petal.Width, data=iris, model='lm')
summary(model1)
coef(model1)

# 2 blocks: Species; Species + Petal.Length + Petal.Width + Petal.Length:Petal.Width
model2 <- build_model(Sepal.Length, Species, c(Petal.Length * Petal.Width), data=iris, model='lm')
summary(model2)
coef(model2)

reghelper documentation built on Sept. 3, 2023, 1:07 a.m.