[R] Options for viewing / using results from lm

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Tue Sep 23 20:47:43 CEST 2008


I haven't seen a response to this yet, so I will give my $0.25US worth (which is not worth that much anymore ).  :-)

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Michael Just
> Sent: Tuesday, September 23, 2008 11:01 AM
> To: r-help at r-project.org
> Subject: [R] Options for viewing / using results from lm
> 
> Hello,
> I would like to state what I am (trying) to do. I have data 
> set. It has 5749
> rows (including the header) and 23 columns.  The data contains values
> related to spatial aspects of the 412 landscapes (over 
> various years). I
> will be making 2 groups from the data based on spatial 
> extent. I will then
> be performing a quadratic lm for each extent by percent 
> forest vs 1 of 8
> other metrics. For a total of 16 (2 extents * 8 metrics) quad 
> lm runs. I
> will be doing this 'manually'. I hope this is the best way to do these
> analyses.
> 
> e.g.
> ed.qlm.s <- lm(data=small, pfor~ED+I(pfor^2))
> pd.qlm.s <- lm(data=small, pfor~PD+I(pfor^2))
> ...
> ed.qlm.l <- lm(data=large, pfor~ED+I(pfor^2))
> pd.qlm.l <- lm(data=large, pfor~PD+I(pfor^2))
> etc.
> 
> I am ultimately intested in the residuals and how they compare amongst
> various delineations fo the data.
> 
> Q1: I would like to view the residuals for each run.  I think 
> this might be
> better done in a another program. I have the read the R import/export
> manual. However, using it and trying to use the cat, list, 
> sink, or write
> functions I am still lost. What is the best way to export the 
> residual (and
> or other available data from lm) data for viewing elsewhere? A table?

Why do you think it is better done in another program?  Keeping it in R saves you from the exporting, which you say you are having trouble with.

> 
> Q2: How can I take the residuals and create an object(s) for further
> analysis.
>

See ?residuals.

Try the following:

x <- sample(1:20, 100, replace=TRUE)
y <- rnorm(100)
fit.lm <- lm(y ~ x)
plot(residuals(fit.lm))
plot(x,residuals(fit.lm))

 
> I'd appreciate any comments or suggestions including 'read 
> the manual' but
> if thats the case perhaps with a little direction.
> 
> Thank you kindly,
> Cheers,
> M Just
> 

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204
 
 



More information about the R-help mailing list