# $X^T r = 0$ means residual is uncorrelated with $X$?

In OLS, we have the following

$$X^Tr = 0$$ where $$X \in \mathbb{R}^{n \times p}$$ data matrix and $$r \in \mathbb{R}^{n}$$ is the vector of residuals.

The above equal shows that the column of samples corresponding to the j-th independent variable, where $j \in {1, \ldots, p}$$, is orthogonal to the residual vector. But does this necessarily imply that the 2 are uncorrelated. Covariance is essentially a centered inner product, but in this case $$X$$ is not necessarily centered. If it is was centered, then the above result can be used to conclude uncorrelatedness, but if it is not known whether $$X$$ is centered, then can we still make the assertion of uncorrelatedness? • I don't think$X^Tr=0in itself implies they're uncorrelated. But since you also know that the mean of the residuals is zero, you can show that the covariance is zero. \begin{align} cov(X_i, r) = E[(X_i - \mu_{X_i})(r)] \\ = E[X_ir] - \mu_{X_i}E[r] \\ = \frac{1}{n}\langle X_i, r\rangle - \mu_{X_i}*0 = 0\\ \end{align} – 24n8 Commented Jul 16, 2020 at 5:52 • This derivation chooses a single variable, but there's no loss of generality. Also note thatr$lies in the nullspace of$X^T\$
– 24n8
Commented Jul 16, 2020 at 5:54
• @lamanon why don't you write it as an answer? Commented Jul 16, 2020 at 12:08

I don't think $$X^Tr = 0$$ itself is sufficient to show that all the regressors are uncorrelated with the residuals. However, for OLS with an intercept, you know that
$$\sum_i^n r_i = 0 \\ \therefore E[r_i] = 0 \\$$
You can then use this information to derive that the covariance is zero between any regressor and the residual, hence correlation is zero, as follows: \begin{align} \text{cov}(X_j, r) = E[X_jr] - E[X_j]E[r] && \forall X_j \in \{X_1, \ldots, X_p\}\\ =\frac{1}{n}\langle X_j, r \rangle - E[X_j]*0 \\ = 0 - 0 = 0 \end{align}