[R] Options for viewing / using results from lm
Greg Snow
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)
Or
> mydata <- cbind(mydata, r1=resid(fit1), r2=resid(fit2), ...
To view the data in a spreadsheet like table:
> View(mydata)
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
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----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
>
> Hello,
>
> >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.
>
> I think it might be better for viewing capabilities. If I had columns
> of
> residuals right next to each other I could spot differences amongst
> locations. Right? If I can take the residual values and put them back
> into
> my main data file I can then have the options to use grouping values
> that
> exist there. (Like I asked here:
> http://tolstoy.newcastle.edu.au/R/e5/help/08/09/2186.html)
>
> >> Q2: How can I take the residuals and create an object(s) for further
> <http://tolstoy.newcastle.edu.au/R/e5/help/08/09/2259.html#2265qlink2>*
> 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))
>
>
> When I was thinking further analysis, for example, could I take the
> residuals for all metrics in one extent and compare them to all
> residuals
> 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,
>
> Cheers,
>
> M Just
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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