Thanks to all for their help. I am busy today but tomorrow I will have
time to digest all the feedback and follow up if necessary
Cheers, Murray
--
Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Thanks to all who helped me with this problem, especially Bill Venables
and Gabor Grothendieck. I hope one day to learn more about the advanced
features of the language used by Bill.
From a practical standpoint I think I will just avoid doing things like
this in my teaching. It is hard enough
] On Behalf Of
[EMAIL PROTECTED]
Sent: 01 August 2006 06:16
To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch
Subject: Re: [R] Fitting models in a loop
Murray,
Here is a general paradigm I tend to use for such problems. It extends
to fairly general model sequences, including different responses, c
Gesmann, Markus [EMAIL PROTECTED] writes:
Murray,
How about creating an empty list and filling it during your loop:
mod - list()
for (i in 1:6) {
mod[[i]] - lm(y ~ poly(x,i))
print(summary(mod[[i]]))
}
All your models are than stored in one object and you can use
PROTECTED]; r-help@stat.math.ethz.ch
Subject: Re: [R] Fitting models in a loop
Murray,
Here is a general paradigm I tend to use for such problems. It
extends
to fairly general model sequences, including different responses, c
First a couple of tiny, tricky but useful functions:
subst
August 2006 06:16
To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch
Subject: Re: [R] Fitting models in a loop
Murray,
Here is a general paradigm I tend to use for such problems. It
extends
to fairly general model sequences, including different responses, c
First a couple of tiny
]; r-help@stat.math.ethz.ch
Subject: Re: [R] Fitting models in a loop
Murray,
Here is a general paradigm I tend to use for such problems. It
extends
to fairly general model sequences, including different responses, c
First a couple of tiny, tricky but useful functions
: Re: [R] Fitting models in a loop
A simple way around this is to pass it as a data frame.
In the code below the only change we made was to change
the formula from y ~ poly(x, i) to y ~ . and pass poly(x,i)
in a data frame as argument 2 of lm:
# test data
set.seed(1)
x - 1:10
y - x^3 + rnorm(10
-help@stat.math.ethz.ch
Subject: Re: [R] Fitting models in a loop
Murray,
Here is a general paradigm I tend to use for such problems. It
extends
to fairly general model sequences, including different responses, c
First a couple of tiny, tricky but useful
If I want to display a few polynomial regression fits I can do something
like
for (i in 1:6) {
mod - lm(y ~ poly(x,i))
print(summary(mod))
}
Suppose that I don't want to over-write the fitted model objects,
though. How do I create a list of blank fitted model objects
, plotted, c, because the information on their construction
is all embedded in the call.
Bill.
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Murray Jorgensen
Sent: Tuesday, 1 August 2006 2:09 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Fitting models in a loop
11 matches
Mail list logo