An other option is something like this:
Frml <- as.formula(paste('F ~',paste('x', 1:1000, sep="" , collapse = "
+ "))
lm(formula = Frml, data = MyDataFrame)
Cheers,
Thierry
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx@inbo.be
www.inbo.be
-----Oorspronkelijk bericht-----
Van: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] Namens Douglas Bates
Verzonden: maandag 31 juli 2006 14:25
Aan: Kamil Toth
CC: s-news@lists.biostat.wustl.edu
Onderwerp: Re: [S] automate writing formulas
On 7/29/06, Kamil Toth <kamiltoth@yahoo.com> wrote:
>
> Folks:
> I have encountered a really funny problem. I am trying to apply the
"lm" to
> the regression problem with hundreds (possibly even thousands)
exploratory
> variables. Putting aside for the time being the question of
computational
> feasibility and/or accuracy, let me ask how to make even the first
step in
> modeling, i.e. to write a formula. I need to have something like this:
> F~x1+x2+x3+....+x1000. I do not want of course to write all the "x"s
by
> hands. But how to automate writing the formula?
One way to do this is to create a data frame tha contains only the
response and the explanatory variables and use a formula of the form
lm(y ~ ., myDataFrame)
That formula is interpretted to mean "fit y to all the other variables
in myDataFrame".
I don't think this answer will be terribly useful to you because
questions of computational feasibility and accuracy and even
interpretability will begin to dominate long before you get to 1000
explanatory variables.
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|