[R] Error when using step
Dieter Menne
dieter.menne at menne-biomed.de
Mon Jun 22 10:08:34 CEST 2009
Chris Friedl <cfriedalek <at> gmail.com> writes:
> I have two questions about the built-in function step. Ultimately I want to
> apply a lm fitting and subsequent step procedure to thousands of data sets
> groups by a factor defined as a unique ID.
>
> Q1. The code below creates a data.frame comprising three marginally noisy
> surfaces. The code below fails when I use step in a function but summary
> seems to show the model fits are legitimate. Any ideas on what I'm doing
> wrong?
... Well designed example code omitted
> function(x){lm(model, data = x)})
> lapply(fits, function(x){summary(x)})
>
> # FAIL
> lapply(fits, function(x){step(x)})
....
> Error in as.data.frame.default(data) :
> cannot coerce class "lm" into a data.frame
Looks like an environment problem. I could not find a workaround quickly,
but you might have a look at
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/16599.html
We call it "Ripley's Game" here, because variants of it can help you quite often.
Dieter
More information about the R-help
mailing list