简体   繁体   中英

Details of lm function in R

If in RI use the line:

linear <- lm(y~x-1)

R will find a regression line passing by the origin.

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

FOr example if my x values are 1998 to 2011, the fitted line will pass by 1998 or the year 0?

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)

As @Marcinthebox points out, it will go through the origin. 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)

原点情节

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM