4
$\begingroup$

It's my understanding that if I center $y$, the intercept should be 0. However, when using glmnet, I get a non-zero intercept doing this:

lasso_model = glmnet(x=bodyfat$x,y=bodyfat$y-mean(bodyfat$y),intercept=TRUE,alpha = 1,lambda = 1.5)

The intercept is given as $-45.53019$, but shouldn't it be 0 because I've taken the mean from the response?

$\endgroup$

1 Answer 1

11
$\begingroup$

It is not in general the case that centering $y$ produces an intercept of zero. Centering $y$ means that the average value of the centered variable is zero, but the intercept is the predicted value for $y$ when $x=0$.

To illustrate, try plotting bodyfat$y against bodyfat$x, and then plotting bodyfat$y - mean(bodyfat$y) against bodyfat$x, and think about what the axes mean. For example, does it even make sense for $x$ to be zero? If $x$ is height and $y$ is weight, then the intercept is the predicted weight (or difference from the mean in weight) at a height of zero.

$\endgroup$
1
  • 1
    $\begingroup$ I would only add: If you centre both $x$ and $y$, you will get an intercept of exactly $0$. $\endgroup$
    – Eoin
    Commented Oct 18, 2022 at 13:10

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.