I've already seen this question but it didn't help .
So I'm going over regression models (simple linear regression mainly) in my statistics text book and there's a lot of confusion here about what actually is a random variable and what isn't. Namely, at one point they treat some term as a random variable and then later it's a constant. Or something is initially a constant but then we calculate its expected value somehow.
Anyway we first define regression function as $f(X) = E(Y|X)$, after which we immediately go specifically to simple linear regression.
Let $(X_1, Y_1), ... (X_n, Y_n)$ be our sample. The model that we wish to apply is $$Y_i = \beta_0 + \beta_1X_i + \epsilon_i$$ where the sequence of random variables $\{\epsilon_i\}$ satisfies the following:
- $E(\epsilon_i) = 0 $ for $i=1, 2, ..., n$
- $E(\epsilon_i\epsilon_j) = 0$ for all $i \neq j$
- $D(\epsilon_i)=\sigma^2 < \infty$
The problem with this textbook is that everything is very vague and it's written as if it's supposed to be a reminder for someone who already knows all this stuff rather then a textbook for someone to learn it from scratch from.
Later on we derive the estimated coefficients $\beta_0$ and $\beta_1$ using partial derivatives of the sum of squares, and we obtain:
$$\hat{\beta_1} = \frac{\sum_{i=1}^n(X_i - \bar{X_n})(Y_i-\bar{Y_n})}{\sum_{i=1}^n(X_i-\bar{X_n})^2}$$ $$\hat{\beta_0} = \bar{Y_n} - \hat{\beta_1}\bar{X_n}$$
Now we wish to find the expected value for $\hat{\beta_1}$. We transform it into the following form: $$\hat{\beta_1} = \sum_{i=1}^n{Y_i\frac{(X_i - \bar{X_n})}{nS^2_{X}}}$$ where $S^2_{X}$ is $\frac{1}{n}\sum_{i=1}^n(X_i - \bar{X_n})^2$.
And now when we start finding the expected value it looks something like this:
$$E(\hat{\beta_1}) = \sum_{i=1}^n{E(Y_i)\frac{X_i - \bar{X_n}}{nS^2_{X}}} = \sum_{i=1}^n{(\beta_0 + \beta_iX_i)\frac{X_i-\bar{X_n}}{nS^2_{X}}} = ...$$
Meaning, everything except for $Y_i$ in the sum is treated as a constant. That's one of the parts I don't understand. In some other sources where I've tried finding answers to this question I've seen the following sentence:
Only ${e_i}$'s are random variables
This doesn't sit right with me probably because I got to regression after I'd been studying hypothesis testing and other parts of statistical inference for a while, where we've always treated 'almost everything' as a random variable, meaning the sample (in this case the $X_i, Y_i$ pairs), was also a random variable. How come here, suddenly, the part containing $X_i$ and $\bar{X_n}$ gets just thrown out of the $E()$ as if it is just a constant?
Some sources also mention that $X_i, Y_i$'s are indeed random variables but rather 'fixed', which still doesn't help me understand it because it sounds very informal.
Now I'll try and summarize my question(s) somehow.
- Do we treat $(X_i, Y_i)$'s as random variables?
- Do we treat $\beta_0$ and $\beta_1$ as random variables?
- Do we treat $\hat{\beta_0}$ and $\hat{\beta_1}$ as random variables?
- What can have an expected value and what can't (what gets treated as a constant when finding expected values) and why?