Learn R Programming

reghelper (version 0.3.3)

build_model_q: Incremental block modelling.

Description

build_model_q allows you to incrementally add terms to a linear regression model.

Usage

build_model_q(dv, blocks = NULL, data = NULL, opts = NULL, model = "lm")

Arguments

dv

String of the variable name to be used as the dependent variable.

blocks

List of variable names (or interaction terms) to add for each block. Each list element should be a single string with terms for that block. Variables from previous blocks will be included with each subsequent block.

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; only supports 'lm' at this time.

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.

Details

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. Note that in most cases it is easier to use build_model and pass variable names in directly instead of strings of variable names. build_model_q uses standard evaluation in cases where such evaluation is easier.

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.

See Also

build_model

Examples

Run this code
# NOT RUN {
# 2 blocks: Petal.Length; Petal.Length + Petal.Width
model1 <- build_model_q('Sepal.Length', list('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_q('Sepal.Length', list('Species', 'Species + Petal.Length * Petal.Width'),
    data=iris, model='lm')
summary(model2)
coef(model2)
# }

Run the code above in your browser using DataLab