[R] Options for viewing / using results from lm
Greg.Snow at imail.org
Tue Sep 23 22:26:18 CEST 2008
You can do things like this pseudocode:
> fit1 <- lm( y ~ x1, data=mydata )
> fit2 <- lm( y ~ x2, data=mydata )
> fit3 <- lm( y ~ x1*x2, data=mydata )
> mydata$r1 <- resid(fit1)
> mydata$r2 <- resid(fit2)
> mydata$r3 <- resid(fit3)
> mydata <- cbind(mydata, r1=resid(fit1), r2=resid(fit2), ...
To view the data in a spreadsheet like table:
And scroll over to the r columns, using indexing or the subset function can reorder the columns to make this easier.
A simple plot:
> pairs( mydata[ , paste('r',1:10, sep='')], col=c('red','green','blue')[ mydata$g1 ],
+ panel=panel.smooth )
Or there are various other ways to explore the data within R. If you really feel the need to use another tool, do like the above, then use write.table to export it to a csv file or paste it to a spreadsheet. There is also the rggobi package which will automate the exporting to the ggobi program which allows a lot more visualization options.
Hope this helps,
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
greg.snow at imail.org
> -----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 2:06 PM
> To: r-help at r-project.org
> Cc: NordlDJ at dshs.wa.gov
> Subject: Re: [R] Options for viewing / using results from lm
> >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
> I think it might be better for viewing capabilities. If I had columns
> residuals right next to each other I could spot differences amongst
> locations. Right? If I can take the residual values and put them back
> my main data file I can then have the options to use grouping values
> exist there. (Like I asked here:
> >> Q2: How can I take the residuals and create an object(s) for further
> >See ?residuals.
> >Try the following:
> >x <- sample(1:20, 100, replace=TRUE)
> >y <- rnorm(100)
> >fit.lm <- lm(y ~ x)
> When I was thinking further analysis, for example, could I take the
> residuals for all metrics in one extent and compare them to all
> for all metrics in another extent? Even though the were created with 16
> different models?
> In 'plot(residuals(fit.lm))' what is the index 'counting'?
> Thank you kindly for you $0.25,
> M Just
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help