This is not a question of how to do Elastic Net Regression in R, but understanding the objective function of Elastic Net Regression from the glmnet package.
From the package itself the objective function is as follows found here: $$\min_{B_0,B}\frac{1}{N}\sum{w_il(y_i,B_0+B^Tx_i)+\lambda[\frac{(1-\alpha)}{2}||B||_2^2+\alpha||B||_1]}$$.
So the summation is the sum of the squared residuals and the $\lambda$ is penalization from Lasso and Ridge.
Then it states for the Gaussian case, for $l(y,n)$, it becomes $\frac{1}{2}(y-n)^2$. This simplifies the summation such that instead of multiplying by $\frac{1}{N}$ it becomes $\frac{1}{2N}$ as suggested link1 and link 2. However, in this link, there is no division by N to begin with in the objective function of elastic net regression.
My questions are
- Why is there a difference such that one divides by the number of observations and the other does not?
- What is $w_i$ in the objective function?