[R] Least Squares Fit

Fred J. phddas at yahoo.com
Sun May 2 12:26:41 CEST 2004


Hello

I need to plot the least squares fit and get the slope
of the line that best fit the data. after reading lm
and lsfit, since not being able to understand the use
of the second argument "y" for the lsfit, I am giving
the lm a go, but know not why the code below does not
draw the line on the plot. e.g. well.. why -50
Intercept?
thanks

x <- 1:10; y <- x+50
plot(x,y)
z <- lm(as.data.frame(cbind(x,y))))
abline(z)

> z$coefficients
(Intercept)           y 
        -50           1




More information about the R-help mailing list