Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

getData

Get Model Data


Description

Extract the data used to fit a model.

Usage

getData(mod, subset = FALSE, merge = FALSE, env = parent.frame())

Arguments

mod

A fitted model object, or a list or nested list of such objects.

subset

Logical. If TRUE, only observations used to fit the model(s) are returned (i.e. missing observations (NA) or those with zero weight are removed).

merge

Logical. If TRUE, and mod is a list or nested list, a single dataset containing all variables used to fit models is returned.

env

Environment in which to look for data (passed to eval).

Details

This is a simple convenience function to return the data used to fit a model, by evaluating the 'data' slot of the model call object. If the 'data' argument of the model call was not specified, or is not a data frame (or coercible to such) containing all variables referenced in the model formula, an error will be thrown - this restriction is largely to ensure that a single coherent dataset of all model variables can be made available for resampling purposes.

If mod is a list of models and merge = TRUE, all (unique) variables used to fit models are merged into a single data frame. This will return an error if subset = TRUE results in datasets with different numbers of observations (rows).

Value

A data frame of the variables used to fit the model(s), or a list or nested list of same.

See Also

Examples

# Get data used to fit SEM from Shipley (2009)
getData(Shipley.SEM[[1]])  # from single model
getData(Shipley.SEM)  # from SEM (list)
getData(Shipley.SEM, merge = TRUE)  # from SEM (single dataset)

semEff

Automatic Calculation of Effects for Piecewise Structural Equation Models

v0.5.0
GPL-3
Authors
Mark Murphy [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.