I am working on network models for political networks. One of the things I am doing is penalized inference. I am using an adaptive lasso approach by setting a penalty factor for glmnet. I have various parameters in my model: alphas
and phis
. The alphas
are fixed effects so I want to keep them in the model while the phis
are being penalized.
I have starting coefficients from the MLE estimation process of glm()
to compute the adaptive weights that are set through the penalty factor of glmnet()
.
This is the code:
# Generate Generalized Linear Model
GenLinMod = glm(y ~ X, family = "poisson")
# Set coefficients
coefficients = coef(GenLinMod)
# Set penalty
penalty = 1/(coefficients[-1])^2
# Protect alphas
penalty[1:(n-1)] = 0
# Generate Generalized Linear Model with adaptive lasso procedure
GenLinModNet = glmnet(XS, y, family = "poisson", penalty.factor = penalty, standardize = FALSE)
For some networks this code executes just fine, however I have certain networks for which I get these errors:
Error: Matrices must have same number of columns in rbind2(.Call(dense_to_Csparse, x), y)
In addition: Warning messages:
1: from glmnet Fortran code (error code -1); Convergence for 1th lambda value not reached after maxit=100000 iterations; solutions for larger lambdas returned
2: In getcoef(fit, nvars, nx, vnames) :
an empty model has been returned; probably a convergence issue
The odd thing is that they all use the same code, so I am wondering if it is a data problem. Additional information:
+In one case I have over 500 alphas
and 21 phis
and these errors appear, in another case that does not work I have 200 alphas
and 28 phis
. But on the other hand I have a case with over 600 alphas
and 28 phis
and it converges nicely.
+I have tried settings for lambda.min.ratio
and nlambda
to no avail.
Additional question: Is the first entry of penalty the one associated with the intercept? Or is it added automatically by glmnet()
? I did not find clarity about this in the glmnet
vignette. My thoughts are that I shouldn't include a term for the intercept, since it's said that the penalty is internally rescaled to sum nvars
and I assume the intercept isn't one of my variables.