glmnet

Why calculating MSE in lasso regression gives different outputs?

寵の児 提交于 2019-12-22 09:09:13
问题 I am trying to run different regression models on the Prostate cancer data from the lasso2 package. When I use Lasso, I saw two different methods to calculate the mean square error. But they do give me quite different results, so I would want to know if I'm doing anything wrong or if it just means that one method is better than the other ? # Needs the following R packages. library(lasso2) library(glmnet) # Gets the prostate cancer dataset data(Prostate) # Defines the Mean Square Error

R vector size limit: “long vectors (argument 5) are not supported in .C”

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 10:23:57
问题 I have a very large matrix I'm trying to run through glmnet on a server with plenty of memory. It works fine even on very large data sets up to a certain point, after which I get the following error: Error in elnet(x, ...) : long vectors (argument 5) are not supported in .C If I understand correctly this is caused by a limitation in R which cannot have any vector with length longer than INT_MAX. Is that correct? Are there any available solutions to this that don't require a complete rewrite

How can I force cv.glmnet not to drop one specific variable?

蓝咒 提交于 2019-12-20 09:53:57
问题 I am running a regression with 67 observasions and 32 variables. I am doing variable selection using cv.glmnet function from the glmnet package. There is one variable I want to force into the model. (It is dropped during normal procedure.) How can I specify this condition in cv.glmnet? Thank you! My code looks like the following: glmntfit <- cv.glmnet(mydata[,-1], mydata[,1]) coef(glmntfit, s=glmntfit$lambda.1se) And the variable I want is mydata[,2]. 回答1: This can be achieved by providing a

glmnet: How do I know which factor level of my response is coded as 1 in logistic regression

倾然丶 夕夏残阳落幕 提交于 2019-12-19 18:29:27
问题 I have a logistic regression model that I made using the glmnet package. My response variable was coded as a factor, the levels of which I will refer to as "a" and "b". The mathematics of logistic regression label one of the two classes as "0" and the other as "1". The feature coefficients of a logistic regression model are either positive, negative, or zero. If a feature "f"'s coefficient is positive, then increasing the value of "f" for a test observation x increases the probability that

How to solve 'protection stack overflow' issue in R Studio

落爺英雄遲暮 提交于 2019-12-18 04:03:56
问题 I'm trying to build a model with the glmnet package, but I'm getting the following error when I run the following line: #library('glmnet') x = model.matrix(response ~ ., data = acgh_frame[,c(3:ncol(acgh_frame))]) Error: protect(): protection stack overflow I know this is due to my large number of variables (26k+) in the dataframe. When I use fewer variables the error doesn't show. I know how to solve this in command line R, but I require to stay in R studio, so I want to fix it from R Studio.

R glmnet : “(list) object cannot be coerced to type 'double' ”

送分小仙女□ 提交于 2019-12-17 22:44:59
问题 I'm trying to use the glmnet package on a dataset. I'm using cv.glmnet() to get a lambda value for glmnet() . Here's the dataset and error message: > head(t2) X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 1 1 1 0.7661266 45 2 0.80298213 9120 13 0 6 0 2 2 2 0 0.9571510 40 0 0.12187620 2600 4 0 0 0 1 3 3 0 0.6581801 38 1 0.08511338 3042 2 1 0 0 0 4 4 0 0.2338098 30 0 0.03604968 3300 5 0 0 0 0 5 5 0 0.9072394 49 1 0.02492570 63588 7 0 1 0 0 6 6 0 0.2131787 74 0 0.37560697 3500 3 0 1 0 1 > str(t2) 'data

Invalid glmnet Mex file in matlab

非 Y 不嫁゛ 提交于 2019-12-14 02:27:15
问题 I am running glmnet package on MATLAB 2019a in macOS 10.14.5. I have also installed Xcode in my laptop. I got the error like the following: Invalid MEX-file '/Users/Desktop/Research/Paper Code/glmnet/glmnetMex.mexmaci64' : dlopen(/Users/Desktop/Research/Paper Code/glmnet/glmnetMex.mexmaci64, 6): Library not loaded: @loader_path/libmex.dylib Referenced from: /Users/Desktop/Research/Paper Code/glmnet/glmnetMex.mexmaci64 I have tried the code mex -setup and got MEX configured to use 'Xcode with

“get_int_parms” not available for .Fortran() for package “glmnet”

自闭症网瘾萝莉.ら 提交于 2019-12-13 14:34:34
问题 I am trying to fit a simple lasso model with the latest glmnet package. I have read in a csv-file and have all my data stored as a "list" or matrix. I tried to follow this guide for the implementation: https://www.r-bloggers.com/ridge-regression-and-the-lasso/ But when I run: lasso.mod <- glmnet(b[,2:22], b$power, alpha=1) I get the following error: Error in .Fortran("get_int_parms", fdev = double(1), eps = double(1), : "get_int_parms" not available for .Fortran() for package "glmnet" In my

predict.glmnet: Some Factors Have Only One Level in New Data

白昼怎懂夜的黑 提交于 2019-12-13 04:25:17
问题 I've trained an elastic net model in R using glmnet and would like to use it to make predictions off of a new data set. But I'm having trouble producing the matrix to use as an argument in the predict() method because some of my factor variables (dummy variables indicating the presence of comorbidities) in the new data set only have one level (the comorbidities were never observed), which means I can't use model.matrix(RESPONSE ~ ., new_data) because it gives me the (expected) Error in

How to regularize the intercept with glmnet

南楼画角 提交于 2019-12-13 03:44:52
问题 I know that glmnet does not regularize the intercept by default, but I would like to do it anyway. I was taking a look at this question and tried to do what whuber suggested (adding a constant variable and turning the parameter intercept to FALSE ) , but as a result glmnet is not fitting the added constant as well. library(dplyr) library(glmnet) X <- mtcars %>% mutate(intercept = 1) %>% select(-c(mpg)) %>% as.matrix() y <- mtcars %>% select(mpg) %>% as.matrix() model <- glmnet(X, y, intercept