Questions tagged [glmnet]

glmnet is an R package for Lasso and elastic-net regularized generalized linear models.

Overview

glmnet is an R package which provides Lasso and elastic-net regularized generalized linear models. It features extremely efficient procedures for fitting the entire Lasso or elastic-net regularization path for linear regression, logistic and multinomial regression models, Poisson regression and the Cox model.

Resources

Tag usage

Questions on should be about implementation and programming problems, not about the statistical or theoretical properties of the technique.
Consider whether your question might be better suited to Cross Validated, the Stack Exchange site for statistics, machine learning and data analysis.

598 questions
0
votes
1 answer

How to load a csv file into R as a factor for use with glmnet and logistic regression

I have a csv file (single column, numeric values) called "y" that consists of zeros and ones where the rows with the value 1 indicate the target variable for logistic regression, and another file called "x" with the same number of rows and with…
babelproofreader
  • 530
  • 1
  • 6
  • 20
0
votes
0 answers

significant change in predicted score distribution when scaling using glmnet

I'm struggling to understand the predict function, or perhaps the effects of scaling. Below i show my coding procedure to train a logistic regression model using GLMNET with: 1)no scaling, and 2) with scaling. I make no change to anything else, yet…
nerdlyfe
  • 487
  • 7
  • 21
0
votes
1 answer

Error: number of observations in y not equal to the number of rows of x

Here is my code: ames_train_x <- model.matrix(Value ~ ., train)[, -1] ames_train_y <- log(train$Value) ames_test_x <- model.matrix(Value ~ ., test)[, -1] ames_test_y <- log(test$Value) # Applying LASSO REGRESSION to data ames_lasso <- glmnet( x…
gvncore
  • 33
  • 1
  • 6
0
votes
0 answers

glmnet for R under windows

stats experts, I want to install glmnet to learn from the examples of Jared Lander's R for everyone (2nd ed). I am running R version 3.5.1 (2018-07-02) under Rstudio on a Windows machine. When I try to install glmnet I receive the message 'glmnet’…
0
votes
2 answers

Specifying type of measure with lasso regression

I'm trying to do variable selection with glmnet and lasso poisson regression. It runs if I use: model.lasso <- glmnet(X,ED.visits, family="poisson", alpha=1, nlambda=1000) But I've been asked to use "deviance" as a measure. I get an error when I…
wayneeusa
  • 194
  • 1
  • 10
0
votes
0 answers

Having a problem with glmnet and making a matrix?

How do I fix this? This is the code I wrote before. Do the number of observations have to be equal? Would appreciate any help! DATA4=policeexcel2[,c("age", "gender", "raceethnicity", "month", "city","state", "latitude", "longitude", "tract_ce",…
Vkara
  • 7
  • 2
0
votes
2 answers

Error extracting non-zero glmnet coefficients with "which"

I fitted a cox model with glmnet like: fitL <- glmnet( X, Y, family = "cox", alpha = 1, lambda = cvL$lambda.min, #cvL obteined with cv.glmnet standardize = FALSE, thresh = thresh ) I obtained: str(coef(fitL) != 0) Formal class…
Ph.D.Student
  • 704
  • 6
  • 27
0
votes
1 answer

Getting different results for LASSO using cv.glmnet and caret package in R

I saw few posts here regarding my issue. I went through with those but still i couldnt figure out what i did wrong. Any help will be highly appreciated. I fitted a LASSO logistic regression model using glmnet package and caret package (which is a…
student_R123
  • 962
  • 11
  • 30
0
votes
1 answer

different results based on type.measure argument in cv.glmnet

I have a training matrix 30660 x 1612 consisting of 3 dense continuous features and the remaining sparse binary features. #cases (1): 6132, #controls (0): 24528. model.glmnet <- cv.glmnet(matrix.glmnet, factor(obs.dt[,iscase]), family='binomial',…
ironv
  • 978
  • 10
  • 25
0
votes
0 answers

Which model does the cv.glment uses to fit and why is it different? Using R

I am working with R to build a predictive model using Binary Logistic with the Lasso penalty. Originally that data set consisted of 63147 observations and 22 variables, with 3% of the observations coming from $G_1$ and 97% coming from $G_2$. As can…
Lise
  • 51
  • 1
  • 6
0
votes
1 answer

What's wrong with my Logistic Regression parameters in MATLAB glmnet?

I am using glmnet in MATLAB 2019a on my Macbook to do logistic regression. Algorithm: log(pi/(1-pi))=b0+X*b pi=P(Y=2|X_i)=1-P(Y=1|X_i) Code: Y = [2;1;2;1;2;1;2;1;1;2]; X = [0.1451 0.1176 0.0872 0.0544 0.0197 -0.0164 -0.0533 …
Dianafreedom
  • 391
  • 1
  • 13
0
votes
0 answers

Error in y * weights : non-numeric argument to binary operator

I am trying to build a continuation ratio model on a large dataset that has many categorical variables using glmnetcr package. I'm trying to fit this model: fit3=glmnetcr(x=trainElective2[,1:26],y=trainElective2[,27],method="forward") This got me…
Connor
  • 3
  • 4
0
votes
0 answers

How to get X & Y rows to match?

I'm working on a new type of code and need a little help with the ridge regularized regression. trying to build a predictive model but first i need x and y matrix rows to match. I found something similar with a google search but their data is…
0
votes
1 answer

How do I superimpose lasso and ridge regression fits (Glmnet) onto data?

I have data (below), and have carried out linear, ridge, and lasso regression. For lasso and ridge regression I have found the optimal lambda using cross validation. I now want to superimpose the fitted models onto a y vs x plot of my original data.…
Mark D
  • 17
  • 6
0
votes
0 answers

How to calculate the survival function in R for a glmnet cox family?

I have a sample data of 583 type 2 diabetes patients and want to calculate the 5 year incidence probability of an event for every patient. Variables which were collected are time to an event variable censored at 5 years, event status and 38…