# ElasticNet coefficients are different for each cv.glmnet run

Cross Validated Asked by Jonathan on September 4, 2020

I am new to R and cv.glmnet. I have now tried to run my logistic model with ElasticNet instead of stepwise as people in this community suggest. But, I have troubles with the model itself as it keeps giving me different end results. I want to get alpha and lambda by letting cv.glmnet do this through minimization with a k-fold of 10. I learnt to set foldid equal to something in order to leave out the randomness in the coefficients, but I still get this randomness in my coefficients in the end of each run. All other answers to this question deals with a fixed alpha as here and here. This is my code

set.seed(123)
nfolds <- 10
foldid <- sample(1:10, size = length(y), replace=TRUE)
model <- lapply(1:10, function(i){
cv.glmnet(trainX, trainY, type.measure = "deviance", family = "binomial", alpha = i, foldid = foldid, parallel = TRUE)
})


Again, I do not want to fix my alpha and lambda, but surely get consistent coefficients when I run my Elastic model again and again. Can someone please tell me, what I am doing wrong here?

## Related Questions

### What’s wrong in this derivation of back-propagation errors?

1  Asked on December 27, 2021

### How does probability of default evolve over time?

1  Asked on December 27, 2021 by mathella

### Random effects not appearing for some levels in lmer model – Why would that be?

1  Asked on December 25, 2021

### Logistic regression with lasso versus PCA?

2  Asked on December 25, 2021 by manas

### Dealing with singular fit in mixed models

2  Asked on December 25, 2021 by user33268

### groups, levels and denominator dof in mixed effect models

1  Asked on December 25, 2021

### p-value random effect in glmer() in lme4 package

1  Asked on December 25, 2021 by ribelles

### Question about the structures and conditions of validity of the mixed-effect model

1  Asked on December 25, 2021

### Increasing multicollinearity in multilevel/hierarchical modeling?

1  Asked on December 25, 2021

### Specifying model in glmer() – interaction terms

1  Asked on December 25, 2021

### lmer or binomial GLMM

1  Asked on December 25, 2021

### Is my design nested or crossed? Question concerning specifying random effects with lmer in R

1  Asked on December 25, 2021

### Interpretation of binomial GLM (glmer) with interaction and results description

1  Asked on December 25, 2021 by catarina-toscano

### How to compute standard deviation from mean absolute error?

1  Asked on December 25, 2021

### If the joint density $f_{X_1,…,X_n}(x_1,…,x_n)$ is symmetric about the origin, does this imply that each marginal cdf $F_{X_i}(0)=1/2$?

0  Asked on December 25, 2021

### Graphic model factorizing, marginalization

1  Asked on December 25, 2021 by k-k-mcdonald

### Can PCA be applied to a subset of features

1  Asked on December 25, 2021 by mayank-kumar

### $E(f(X_0)f'(X_l)) = E(f'(X_0) f(X_l))$ for a stationary process?

0  Asked on December 25, 2021 by l-d

### Testing linear hypothesis with Wald test: unintuitive results

0  Asked on December 25, 2021 by carsonwhit