[R] lsfit residuals

David Winsemius dwinsemius at comcast.net
Mon Oct 26 12:48:46 CET 2009


On Oct 25, 2009, at 1:20 PM, Tanya Cashorali wrote:

> I'm trying to extract the points above and below a particular lsfit.  
> I can only get the residuals from the original fit though.
>
> x = runif(100, 0, 10)
> plot(x)
> abline(lsfit(1:100, test))

Error in as.matrix(y) : object 'test' not found

I ran the first three lines and was not in the least bit surprised  
that I got an error. I was expecting that lsfit needed to see some  
object (perhaps "x") rather than an integer series, and I didn't see  
"test" anywhere defined.

> abline(lsfit(1:100, test + sd(test))) #I want the points above THIS  
> line.

Did you really have running code that produced a line?

>
> Is there a way to use the coefficients from the fit to do this?
> Thanks for any help.

If you give lsfit a proper input, and assign the result to a fit  
object, say "xfit", then coef(xfit) will give you the coefficients, or  
if you wanted to apply some sort of test on the residuals, you could  
get them with either residuals(xfit) or xfit$residuals.

-- 

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list