2
$\begingroup$

So, if we have $RSS(\beta) = (\mathbf{y}-\mathbf{X}\beta)^T(\mathbf{y}-\mathbf{X}\beta)$ and differentiatiate with respect to $\beta$, and set it to zero in order to minimize it, how do we get $\mathbf{X}^T(\mathbf{y}-\mathbf{X}\beta)=0$?

What I got is $\mathbf{X}^T(\mathbf{y}-\mathbf{X}\beta)+(\mathbf{X}^T(\mathbf{y}-\mathbf{X}\beta))^T=0$

And that is the same only if the transpose of $\mathbf{X}^T(\mathbf{y}-\mathbf{X}\beta)$ is the same as itself... that means that $\mathbf{X}^T(\mathbf{y}-\mathbf{X}\beta)$ must be symmetric.

But, why is that so? I know this is a basic question that have come up a lot here, but i think there is a sort of a leap between calculus based statistics and using linear algebra. I've had some linear algebra, but still I cannot solve this... that focused more on spaces and projections and orthogonality, not differentiating matrices...

But, how can it even be symmetric? Because it's a p x 1 vector and not even square... my result doesn't make any sense.

$\endgroup$
4

1 Answer 1

4
$\begingroup$

Let's clarify the process of minimizing the Residual Sum of Squares (RSS) function, step by step. The function we want to minimize is given by $RSS(\beta) = (\mathbf{y} - \mathbf{X}\beta)^T(\mathbf{y} - \mathbf{X}\beta)$. This is a scalar function where $\mathbf{y}$ is an $n \times 1$ vector, $\mathbf{X}$ is an $n \times p$ matrix, and $\beta$ is a $p \times 1$ vector. Our goal is to find $\frac{\partial RSS(\beta)}{\partial \beta}$ and set it to zero to find the minimizing value of $\beta$. We start by expanding the RSS function: $$RSS(\beta) = (\mathbf{y} - \mathbf{X}\beta)^T(\mathbf{y} - \mathbf{X}\beta).$$ This can be rewritten as $$RSS(\beta) = (\mathbf{y}^T - \beta^T \mathbf{X}^T)(\mathbf{y} - \mathbf{X}\beta).$$ Distributing the multiplication, we obtain $$RSS(\beta) = \mathbf{y}^T\mathbf{y} - \mathbf{y}^T\mathbf{X}\beta - \beta^T\mathbf{X}^T \mathbf{y} + \beta^T \mathbf{X}^T \mathbf{X} \beta.$$ Notice that $\mathbf{y}^T\mathbf{X}\beta$ is a scalar, and its transpose $(\mathbf{y}^T\mathbf{X}\beta)^T = \beta^T \mathbf{X}^T \mathbf{y}$ is the same scalar. Therefore, $\mathbf{y}^T\mathbf{X}\beta = \beta^T \mathbf{X}^T \mathbf{y}$, and we can simplify the RSS function to $$RSS(\beta) = \mathbf{y}^T\mathbf{y} - 2\beta^T \mathbf{X}^T \mathbf{y} + \beta^T \mathbf{X}^T \mathbf{X} \beta.$$ Next, we differentiate with respect to $\beta$. When differentiating a scalar with respect to a vector, we use standard matrix calculus results. Specifically, we use the results that $\frac{\partial}{\partial \beta}(\beta^T A \beta) = (A + A^T)\beta$ (which simplifies to $2A\beta$ when $A$ is symmetric) and $\frac{\partial}{\partial \beta}(\beta^T b) = b$. In our case, $A = \mathbf{X}^T\mathbf{X}$, which is symmetric. So, differentiating term-by-term, we have $\frac{\partial}{\partial \beta}(\mathbf{y}^T\mathbf{y}) = 0$, $\frac{\partial}{\partial \beta}(- 2\beta^T \mathbf{X}^T \mathbf{y}) = -2 \mathbf{X}^T\mathbf{y}$, and $\frac{\partial}{\partial \beta}(\beta^T \mathbf{X}^T \mathbf{X} \beta) = 2\mathbf{X}^T \mathbf{X}\beta$. Combining these gives us the derivative: $$\frac{\partial RSS(\beta)}{\partial \beta} = -2 \mathbf{X}^T\mathbf{y} + 2\mathbf{X}^T \mathbf{X}\beta$$ or equivalently, $$\frac{\partial RSS(\beta)}{\partial \beta} = 2 \mathbf{X}^T (\mathbf{X}\beta - \mathbf{y}).$$ To find the minimizing $\beta$, we set the derivative to zero: $$2 \mathbf{X}^T (\mathbf{X}\beta - \mathbf{y}) = 0.$$ Dividing by 2 yields $$\mathbf{X}^T (\mathbf{X}\beta - \mathbf{y}) = 0,$$ which can be rewritten as $$\mathbf{X}^T(\mathbf{y} - \mathbf{X}\beta) = 0.$$ The equation you mentioned, such as $$\mathbf{X}^T(\mathbf{y}-\mathbf{X}\beta) + (\mathbf{X}^T(\mathbf{y}-\mathbf{X}\beta))^T = 0,$$ is not necessary and introduces confusion. The gradient is a vector, derived directly from matrix calculus rules. There's no need to add its transpose or apply a symmetry argument because the gradient is a $p \times 1$ vector, not a matrix that needs to be symmetric. We are setting the gradient vector equal to the zero vector. The confusion can arise from attempting to derive the gradient by manual product rule applications instead of utilizing known matrix calculus results. The result, $\mathbf{X}^T(\mathbf{y}-\mathbf{X}\beta)=0$, follows directly from setting the gradient to zero, and no extra symmetry condition is required.

New contributor
Luigi M is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
7
  • $\begingroup$ What I didn't knew is that $\frac{\partial}{\partial \beta}(\beta^T A \beta) = (A + A^T)\beta$... can you derive this result? Thanks a lot, by the way, very good and thorough answer! $\endgroup$ Commented 18 hours ago
  • 2
    $\begingroup$ @GeekGuy that's the product rule $\endgroup$
    – Firebug
    Commented 18 hours ago
  • $\begingroup$ @Firebug how do you get $A^T$? I know the product rule... what I got is $A\beta+\beta^T A$... $\endgroup$ Commented 18 hours ago
  • $\begingroup$ Fyi, I prefer the geometric projection approach as this is more intuitive and appealing ... and easier. $\endgroup$ Commented 17 hours ago
  • $\begingroup$ @GeekGuy you are applying it incorrectly (a hint: your result has incompatible dimensions) $\endgroup$
    – Firebug
    Commented 8 hours ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.