On Jun 22, 2009, at 4:08 AM, Dieter Menne wrote:
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,
Perhaps:
by(data2, data2$grp, function(x) step(lm(model, data=x)))
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
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.