I wrote a macro in SAS that did what I am wanting, but now I want to get a function in R that does the same thing.
I want a function, that can transform a specific predictor variable any number of ways, and then build a separate regression model using each transformation, and then compare the results.
For example, consider the following linear regression model:
lm(y ~ x1 x2,data=df)
I want to transform x1 three different ways, by taking the log, taking the square, and taking it to the power of .5, and then build the regression equation three times, once with each transformation and then compare the results.
Is there a function that could be built, or other functionality that would do this for me?
Thanks.
lapply(c(log,sqrt), function(f) lm(y ~ f(x), data=df) )should do it. If anyone wants to expand on this, go for it.