Yes, an intercept is included in a glmnet model, but it is not regularized (cf. Regularization Paths for Generalized Linear Models via Coordinate Descent, p. 13). More details about the implementation could certainly be obtained by carefully looking at the code (for a gaussian family, it is the
elnet() function that is called by
glmnet()), but it is in Fortran.
You could try the penalized package, which allows to remove the intercept by passing
unpenalized = ~0 to
> x <- matrix(rnorm(100*20),100,20)
> y <- rnorm(100)
> fit1 <- penalized(y, penalized=x, unpenalized=~0,
> fit2 <- lm(y ~ 0+x)
> plot((coef(fit1) + coef(fit2))/2, coef(fit2)-coef(fit1))
To get Lasso regularization, you might try something like
> fit1b <- penalized(y, penalized=x, unpenalized=~0,
standardize=TRUE, lambda1=1, steps=20)
As can be seen in the next figure, there is little differences between the regression parameters computed with both methods (left), and you can plot the Lasso path solution very easily (right).