# What happens to the coefficients of Ridge and Lasso when you have perfect multicollinnearity?

So let's say we ran a Ridge or Lasso regression on $$Y \sim X$$, and get coefficient $$\beta_X$$. Now if we duplicate the $$X$$, and call it $$Z$$, and then run the same regression on: $$Y \sim X + Z$$. How will the coefficients change in both the Ridge case and the Lasso case?

So it's clear that Lasso will push one towards zero, but which one? Is it just dependent on how you initialize your random weights when doing gradient descent? What about for ridge? This was mentioned in a lecture once where the instructor said "clearly the two new coefficients: $$\beta'_X + \beta'_Z = \beta_X$$ but I don't see why? Also can we tell anything about the values of the individual beta's?

Can someone provide some clearer guidance on how to tackle this problem and what the answer will be? I've tried looking this up online but couldn't get anywhere

Suppose we have $$X\in\mathbb R^{n\times (p+k)}$$ as our feature matrix where $$X = (\underbrace{\x \mid \x \mid \dots \mid \x}_{k\text{ times}} \mid Z)$$ with $$Z\in\mathbb R^{n\times p}$$ containing whatever other columns we may have. Note that $$X\beta = XP^TP\beta$$ where $$P$$ is a permutation matrix so this shows how it's safe to assume a particular ordering of the columns of $$X$$ so long as we correspondingly permute the elements of $$\beta$$. I'll use $$\X = (\x\mid \dots\mid \x) \in \mathbb R^{n\times k}$$.
We have $$\hat\beta_R = (X^TX + \lambda I_{p+k})^{-1}X^Ty \\ = \left[\begin{array}{c|c} \x^T\x \one_k\one_k^T + \lambda I_k & \X^TZ \\ \hline Z^T\X & Z^TZ + \lambda I_p \end{array}\right]^{-1} \left[\begin{array}{c}\X^Ty \\ \hline Z^Ty\end{array}\right].$$ I'll invert that matrix as a 2x2 block matrix (and we know it's always invertible). Letting $$\left[\begin{array}{c|c} \x^T\x \one_k\one_k^T + \lambda I_k & \X^TZ \\ \hline Z^T\X & Z^TZ + \lambda I_p \end{array}\right] = \begin{bmatrix} A & B \\ C & D\end{bmatrix}$$ we have $$\left[\begin{array}{cc} A & B \\ C & D\end{array}\right]^{-1} = \left[\begin{array}{c|c} (A-BD^{-1}C)^{-1} & -(A-BD^{-1}C)^{-1}BD^{-1} \\\hline \cdot & \cdot\end{array}\right]$$ where I've marked the lower row of blocks with $$\cdot$$ since we don't need those for the $$k$$ coefficients of $$\x$$. Letting $$H_Z = Z(Z^TZ + \lambda I)^{-1}Z^T$$ be the hat matrix for a ridge regression just on $$Z$$, we can show that $$BD^{-1}C = \X^TH_Z \X = \x^T H_Z \x \one\one^T$$ and $$A = \x^T\x\one\one^T + \lambda I_k$$ so $$A - BD^{-1}C = \x^T(I-H_Z)\x\one\one^T + \lambda I_k.$$ Then $$BD^{-1} = \X^T Z(Z^TZ + \lambda I_p)^{-1}$$ so all together we get $$\hat\beta_{R;k} = \left(\x^T(I-H_Z)\x\one\one^T + \lambda I_k\right)^{-1}\x^T (I-H_Z) y \one.$$ Factoring out the scalar $$\x^T(I-H_Z)\x$$ this can be written as $$\hat\beta_{R;k} = \frac{\x^T(I-H_Z)y}{\x^T(I-H_Z)\x}\left(\one\one^T + \nu I_k\right)^{-1}\one$$ where for convenience I'm letting $$\nu = \frac{\lambda}{\x^T(I-H_Z)\x}.$$ This inverse can be done explicitly via Sherman-Morrison so $$\left(\one\one^T + \nu I\right)^{-1}\one = \nu^{-1}(I - (\nu + k)^{-1}\one\one^T)\one\\ = \frac{1}{\nu + k}\one.$$
This means $$\hat\beta_{R;k} = (\nu + k)^{-1}\frac{\x^T(I-H_Z)y}{\x^T(I-H_Z)\x}\one \\ = \frac{\x^T(I-H_Z)y}{k\x^T(I-H_Z)\x + \lambda}\one$$ where I've substituted back in what $$\nu$$ is equal to. This shows that each coefficient of $$\x$$ is the same thing, and that it is a shrunken form of what we'd get if $$\x$$ wasn't copied (if there was just one $$\x$$, like in the standard setting, the $$k$$ would disappear but the rest would be the same).
This also shows what the sum of these coefficients is: $$\hat\beta_{R;k} ^T\one = \frac{\x^T(I-H_Z)y}{k\x^T(I-H_Z)\x + \lambda}\one^T\one \\ = \frac{\x^T(I-H_Z)y}{\x^T(I-H_Z)\x + \lambda/k}$$ so the coefficients don't quite sum to what we'd have if $$\x$$ wasn't copied, but rather their sum is what we'd get if we just had one $$\x$$ but divided the regularization parameter by $$k$$.