I'm a bit confused regarding how intercept restrictions impact slope estimators in a simple linear regression. An example:
$$H_0:\beta_0=0$$ $$H_A:\beta_0\neq 0$$
I simulated a variable $y_i$ as:
$$y_i= \beta_0 + \beta x_i +\epsilon_i \quad \cdots(1)\quad\quad \beta_0\neq0$$
$$y_i= 0 + \beta x_i +\epsilon_i \quad \quad \cdots(2)$$
fitting a simple linear regression on each of the simulations yields the exact same estimators for $\beta$ under both least squares and maximum likelihood.
Now if I fit simple linear regressions while including the restriction on the intercept I get two different estimators for each of the possible simulated variables. Can someone help me understand what's going on?
What confuses me the most is the fact that the restricted and unrestricted slope estimators are not the same even when the true model for $y_i$ has no intercept.
I'm attaching my R code for reference:
x<-rnorm(100)
err<-5*rnorm(100)
y1 <- 5*x+err
y2 <- 5+5*x+err
summary(lm(y1~x))
summary(lm(y2~x))
summary(lm(y1~x+0))
summary(lm(y2~x+0))
+0
suppresses the intercept, as does-1
. I think the first makes more sense in regression applications, while the second makes more sense in anova. Both work the same; just try it:lm(dist~speed-1,cars);lm(dist~speed+0,cars)
. Also see?formula
which says (in discussing the-
operator in the formula interface): It can also used to remove the intercept term: when fitting a linear modely ~ x - 1
specifies a line through the origin. A model with no intercept can be also specified asy ~ x + 0
ory ~ 0 + x
. $\endgroup$