Take the following example:
fit <- lm(Sepal.Length ~ log(Sepal.Width), data = iris)
I would like a copy of iris
that only includes the variables that were involved in making fit
. I think model.matrix()
or model.frame()
don't quite do it because of the log
; they will include log(Sepal.Width)
but not Sepal.Width
. I want basically a minimal version of iris
that only includes variables that were used in making fit
. How can I do that? This of course is an example and I would like a more general solution (say you had a number of variables used in making a fit, many passed through transformations that are not necessarily invertible).