Recover data from the data from the model
recoverdata.Rd
Reconstructs data from the fitted model or the environment.
Usage
recoverdata(mod, extras = NULL, envir = environment(formula(mod)), ...)
Arguments
- mod
fitted model
- extras
character vector or formula specifying the predictors. Important when the transformation are applied in the formula.
- envir
data environment
- ...
for future implementations
Details
It uses the fitted model and the global environment to reconstruct the data used in the model. If data
option is specified in the model formula, a dataframe with columns corresponding to the variable in the formula is returned. Any transformation, e.g. log
specified in the formula terms is not evaluated on the returned data frame. However, if none is provided as model input, the dataframe is constructed from the formula terms with all transformations evaluated.
Examples
set.seed(4567)
x <- rnorm(100, 3, 5)
y <- 0.4 + 0.7*x + rnorm(100)
df <- data.frame(y = y, x = x)
m1 <- lm(y ~ x, df)
d1 <- recoverdata(m1)
head(d1)
#> y x
#> 1 0.2230063 -0.6791249
#> 2 -1.9167764 -1.5127303
#> 3 1.6205969 4.2620757
#> 4 3.7020609 6.0751293
#> 5 8.4265286 9.7726720
#> 6 8.4632857 11.0115927
m2 <- lm(y ~ x)
d2 <- recoverdata(m2)
head(d2)
#> y x
#> 1 0.2230063 -0.6791249
#> 2 -1.9167764 -1.5127303
#> 3 1.6205969 4.2620757
#> 4 3.7020609 6.0751293
#> 5 8.4265286 9.7726720
#> 6 8.4632857 11.0115927