[R] intermediate iterations of stepwise regression
Gabor Grothendieck
ggrothendieck at gmail.com
Mon May 18 16:23:08 CEST 2009
Don't use = to mean assign. Replace all your equal signs
(except the ones intended to refer to argument names)
with <- .
On Mon, May 18, 2009 at 10:10 AM, utkarshsinghal
<utkarsh.singhal at global-analytics.com> wrote:
> Hi Gabor,
>
> Thanks for your input. It is of some help if not all.
>
> fit = lm(y~1, data)
> out = capture.output(new.fit = step(fit, direction="forward",
> scope=y~x1+x2+x3))
>
> Here the assignments made inside the capture.output function are no longer
> valid once I came out of it, i.e. there is no object called 'new.fit' in the
> global environment. I want to have at least the final model as "new.fit",
> which is not very efficient to extract from "out" object (of course I don't
> want to run "step" function again separately to get "new.fit"). Is there any
> way of doing it?
>
> It will be a bonus if, somehow, I can have all the intermediate iterations
> also as R objects.
>
>
> Thanks in advance.
>
>
>
> Gabor Grothendieck wrote:
>
> Try this:
>
> out <- capture.output(example(step))
>
>
> On Mon, May 18, 2009 at 9:11 AM, utkarshsinghal
> <utkarsh.singhal at global-analytics.com> wrote:
>
>
> Hi all,
>
> I am performing a stepwise regression by running the "step" function on an
> "lm" object. Now I want to save the intermediate iterations. I know the
> argument trace=T will print it on the console, but I rather want to assign
> it to some R object or may be output it in a CSV or text file.
>
> Any help will be appreciated.
>
> Regards
> Utkarsh
>
> ______________________________________________
> R-help at 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.
>
>
>
>
>
More information about the R-help
mailing list