Learn R Programming

lmhelprs (version 0.4.0)

many_lm: Fit Linear Models Defined By Model Syntax

Description

Fit a list of linear models defined by model syntax.

Usage

many_lm(models, data, na_omit_all = TRUE, ...)

Value

A list of the output of lm(). The class is lm_list_lmhelprs.

Arguments

models

Character. Model syntax. See Details.

data

The data frame. Must be supplied if na_omit_all is TRUE. If na_omit_all is FALSE, it can be omitted (though not suggested).

na_omit_all

How missing data is handled across models. If TRUE, the default, then only cases with no missing data on all variables used at least one of the models will be retained (i.e., listwise deletion). If FALSE, then missing data will be handled in each model separately by lm().

...

Additional arguments. To be passed to lm().

Details

This function extracts linear model formulas from a model syntax (a character vector), fits each of them by lm(), and stores the results in a list.

Lines with the first non-whitespace character "#" are treated as comments and ignored.

Each line must be a valid formula for lm().

Listwise deletion

If na_omit_all is TRUE, the default, then cases with missing data on at least one of the variables used in the model will be removed. Each call to lm() will have subset set to an integer vector of cases not removed (i.e., cases retained)

Handling the subset argument

If subset is used when calling this function, it will also be used to select cases.

Note that the subset argument in the call in each model will be replaced by a numeric vector of cases retained, determined by both missing data and the original value of the subset.

See Also

Examples

Run this code

data(data_test1)
mod <- "x3 ~ x2 + x1
        x4 ~ x3
        x5 ~ x4*x1"
out <- many_lm(mod, data_test1)
summary(out)




Run the code above in your browser using DataLab