Details of the lm function in R

If in R I use the line:

linear <- lm(y~x-1)

R will find the regression line at the origin.

My question is: is the origin x = 0 or the lowest of the x values?

Example, if my values ​​of x are from 1998 to 2011, will the established line run by 1998 or by year 0?

+5
source share
2 answers

With "-1" in the equation, the slope will go through the origin. You can see this by predicting the value at x = 0:

x <- 1998:2011
y <- 3*x+rnorm(length(x))
fit <- lm(y~x-1)
summary(fit)
newdata <- data.frame(x=0:10)
predict(fit,newdata)
+10
source

As @Marcinthebox points out, it will go through the source. To see it graphically:

x <- seq(-5,5)
y <- 3*x+rnorm(length(x))
fit.int <- lm(y~x)
fit <- lm(y~x-1)
summary(fit)

plot(y~x,xlim=c(-.1,.1),ylim=c(-.1,.1))
abline(fit,col="red")
abline(fit.int,col="blue")
abline(h=0)
abline(v=0)

plot of origin

+4
source

All Articles