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))