The lasso estimate described in the question is the lagrange multiplier equivalent of the following optimization problem:
$${\text{minimize } f(\beta) \text{ subject to } g(\beta) \leq t}$$
$$\begin{align}
f(\beta) &= \frac{1}{2n} \vert\vert y-X\beta \vert\vert_2^2 \\
g(\beta) &= \vert\vert \beta \vert\vert_1
\end{align}$$
This optimizazion has a geometric representation of finding the point of contact between a multidimensional sphere and a polytope (spanned by the vectors of X). The surface of the polytope represents $g(\beta)$. The square of the radius of the sphere represents the function $f(\beta)$ and is minimized when the surfaces contact.
The images below provides a graphical explanation. The images made use of the following simple problem with vectors of length 3 (for simplicity in order to be able to make a drawing):
$$\begin{bmatrix}
y_1 \\
y_2 \\
y_3\\
\end{bmatrix}
= \begin{bmatrix}
1.4 \\
1.84 \\
0.32\\
\end{bmatrix}
= \beta_1 \begin{bmatrix}
0.8 \\
0.6 \\
0\\
\end{bmatrix}
+\beta_2 \begin{bmatrix}
0 \\
0.6 \\
0.8\\
\end{bmatrix}
+\beta_3 \begin{bmatrix}
0.6 \\
0.64 \\
-0.48\\
\end{bmatrix}
+ \begin{bmatrix}
\epsilon_1 \\
\epsilon_2 \\
\epsilon_3\\
\end{bmatrix}
$$
and we minimize $\epsilon_1^2+\epsilon_2^2+\epsilon_3^2$ with the constraint $abs(\beta_1)+abs(\beta_2)+abs(\beta_3) \leq t$
The images show:
- The red surface depicts the constraint, a polytope spanned by X.
- And the green surface depicts the minimalized surface, a sphere.
- The blue line shows the lasso path, the solutions that we find as we change $t$ or $\lambda$.
- The green vector shows the OLS solution $\hat{y}$ (which was chosen as $\beta_1=\beta_2=\beta_3=1$ or $\hat{y} = x_1 + x_2 + x_3$.
- The three black vectors are $x_1 = (0.8,0.6,0)$, $x_2 = (0,0.6,0.8)$ and $x_3 = (0.6,0.64,-0.48)$.
We show three images:
- In the first image only a point of the polytope is touching the sphere. This image demonstrates very well why the lasso solution is not just a multiple of the OLS solution. The direction of the OLS solution adds stronger to the sum $\vert \beta \vert_1$. In this case only a single $\beta_i$ is non-zero.
- In the second image a ridge of the polytope is touching the sphere (in higher dimensions we get higher dimensional analogues). In this case multiple $\beta_i$ are non-zero.
- In the third image a facet tof the polytope is touching the sphere. In this case all the $\beta_i$ are nonzero.
The range of $t$ or $\lambda$ for which we have the first and third cases can be easily calculated due to their simple geometric representation.
Case 1: Only a single $\beta_i$ non-zero
The non-zero $\beta_i$ is the one for which the associated vector $x_i$ has the highest absolute value of the covariance with $\hat{y}$ (this is the point of the parrallelotope which closest to the OLS solution). We can calculate the Lagrange multiplier $\lambda_{max}$ below which we have at least a non-zero $\beta$ by taking the derivative with $\pm\beta_i$ (the sign depending on whether we increase the $\beta_i$ in negative or positive direction ):
$$\frac{\partial ( \frac{1}{2n} \vert \vert y - X\beta \vert \vert_2^2 - \lambda \vert \vert \beta \vert \vert_1 )}{\pm \partial \beta_i} = 0$$
which leads to
$$\lambda_{max} = \frac{ \left( \frac{1}{2n}\frac{\partial ( \vert \vert y - X\beta \vert \vert_2^2}{\pm \partial \beta_i} \right) }{ \left( \frac{ \vert \vert \beta \vert \vert_1 )}{\pm \partial \beta_i}\right)} = \pm \frac{\partial ( \frac{1}{2n} \vert \vert y - X\beta \vert \vert_2^2}{\partial \beta_i} = \pm \frac{1}{n} x_i \cdot y $$
which equals the $\vert \vert X^Ty \vert \vert_\infty$ mentioned in the comments.
where we should notice that this is only true for the special case in which the tip of the polytope is touching the sphere (so this is not a general solution, although generalization is straightforward).
Case 3: All $\beta_i$ are non-zero.
In this case that a facet of the polytope is touching the sphere. Then the direction of change of the lasso path is normal to the surface of the particular facet.
The polytope has many facets, with positive and negative contributions of the $x_i$. In the case of the last lasso step, when the lasso solution is close to the ols solution, then the contributions of the $x_i$ must be defined by the sign of the OLS solution. The normal of the facet can be defined by taking the gradient of the function $\vert \vert \beta(r) \vert \vert_1 $, the value of the sum of beta at the point $r$, which is:
$$ n = - \nabla_r ( \vert \vert \beta(r) \vert \vert_1) = -\nabla_r ( \text{sign} (\hat{\beta}) \cdot (X^TX)^{-1}X^Tr ) = -\text{sign} (\hat{\beta}) \cdot (X^TX)^{-1}X^T $$
and the equivalent change of beta for this direction is:
$$ \vec{\beta}_{last} = (X^TX)^{-1}X n = -(X^TX)^{-1}X^T [\text{sign} (\hat{\beta}) \cdot (X^TX)^{-1}X^T]$$
which after some algebraic tricks with shifting the transposes ($A^TB^T = [BA]^T$) and distribution of brackets becomes
$$ \vec{\beta}_{last} = - (X^TX)^{-1} \text{sign} (\hat{\beta}) $$
we normalize this direction:
$$ \vec{\beta}_{last,normalized} = \frac{\vec{\beta}_{last}}{\sum \vec{\beta}_{last} \cdot sign(\hat{\beta})} $$
To find the $\lambda_{min}$ below which all coefficients are non-zero. We only have to calculate back from the OLS solution back to the point where one of the coefficients is zero,
$$ d = min \left( \frac{\hat{\beta}}{\vec{\beta}_{last,normalized}} \right)\qquad \text{with the condition that } \frac{\hat{\beta}}{\vec{\beta}_{last,normalized}} >0$$
,and at this point we evaluate the derivative (as before when we calculate $\lambda_{max}$). We use that for a quadratic function we have $q'(x) = 2 q(1) x$:
$$\lambda_{min} = \frac{d}{n} \vert \vert X \vec{\beta}_{last,normalized} \vert \vert_2^2 $$
Images
a point of the polytope is touching the sphere, a single $\beta_i$ is non-zero:
a ridge (or differen in multiple dimensions) of the polytope is touching the sphere, many $\beta_i$ are non-zero:
a facet of the polytope is touching the sphere, all $\beta_i$ are non-zero:
Code example:
library(lars)
data(diabetes)
y <- diabetes$y - mean(diabetes$y)
x <- diabetes$x
# models
lmc <- coef(lm(y~0+x))
modl <- lars(diabetes$x, diabetes$y, type="lasso")
# matrix equation
d_x <- matrix(rep(x[,1],9),length(x[,1])) %*% diag(sign(lmc[-c(1)]/lmc[1]))
x_c = x[,-1]-d_x
y_c = -x[,1]
# solving equation
cof <- coefficients(lm(y_c~0+x_c))
cof <- c(1-sum(cof*sign(lmc[-c(1)]/lmc[1])),cof)
# alternatively the last direction of change in coefficients is found by:
solve(t(x) %*% x) %*% sign(lmc)
# solution by lars package
cof_m <-(coefficients(modl)[13,]-coefficients(modl)[12,])
# last step
dist <- x %*% (cof/sum(cof*sign(lmc[])))
#dist_m <- x %*% (cof_m/sum(cof_m*sign(lmc[]))) #for comparison
# calculate back to zero
shrinking_set <- which(-lmc[]/cof>0) #only the positive values
step_last <- min((-lmc/cof)[shrinking_set])
d_err_d_beta <- step_last*sum(dist^2)
# compare
modl[4] #all computed lambda
d_err_d_beta # lambda last change
max(t(x) %*% y) # lambda first change
enter code here
note: those last three lines are the most important
> modl[4] # all computed lambda by algorithm
$lambda
[1] 949.435260 889.315991 452.900969 316.074053 130.130851 88.782430 68.965221 19.981255 5.477473 5.089179
[11] 2.182250 1.310435
> d_err_d_beta # lambda last change by calculating only last step
xhdl
1.310435
> max(t(x) %*% y) # lambda first change by max(x^T y)
[1] 949.4353