does the multiple linear regression from glmnet generate a formula?
0
0
Entering edit mode
5.2 years ago

Hello I have been using the package glmnet do multiple linear regression with different regularizations. I am a biologist though, so I don't understand the math behind it deeply. However, being a linear regression, I assume it generates a line to fit the data as best as possible, is that correct? In this case, shouldn't this line have a formula? If so, how could I get it? I intend to use it in a validation set to calculate the sensitivity and specificity.

EDIT

Here is an example of what I mean

In this figure I have table X with my explanatory variables, table y with my response values and, lastly, the coefficients given by multiple linear regression with lasso regularization from the package glmnet.

https://imgbbb.com/image/zgLnt

I assumed the formula y = "A" * 1 + "B" * 2 + "C" * 2 + "D" * 3 + "E" * 9

would give me back the response value, which would be 1. In this case, I get a y which is very closely related to the real value. However, in the models that I'm trying to fit, I am not. Am I doing the calculation right, or is the model I am using just bad?

ridge multiple linear regression lasso glmnet • 4.6k views
ADD COMMENT
1
Entering edit mode

are you looking for some thing like this? demoraesdiogo2017

mtcarsMod <- glmnet(mpg ~ cyl + disp + hp, data=mtcars)

example is furnished here, with glmnetutils package : https://cran.r-project.org/web/packages/glmnetUtils/vignettes/intro.html and author post is here: https://stackoverflow.com/questions/29093868/formula-interface-for-glmnet

ADD REPLY
0
Entering edit mode

Thank you for the links

unfortunately, I believe the formulas and validations he refers to are no the same I am. What I am looking for exactly is a formula that uses explanatory variables so I can predict the response variable, for example like this

yi = B0 + B1xi1 + B2xi2 + ... where y is a response variable x are the explanatory variables B their correlation and B0 the height etc

ADD REPLY
0
Entering edit mode

In the most recent versions of glmnet, you can provide a formula to the function.

ADD REPLY
0
Entering edit mode

amazing! can you share a tutorial on how to do this?

The code I have been using is pretty much like this

Y1 <- as.matrix(Y)
is.matrix(Y1)
X1 <- as.matrix(X)
is.matrix(SurvivalX1)
CV = cv.glmnet(x=X2, y=Y1, family= "gaussian", type.measure = "mae", alpha = 0)
  ##

plot(CV)
  ## 

fit = (glmnet(x=X2, y=Y1, family= "gaussian", alpha=0, lambda=CV$lambda.1se))

##

fit$beta[,1]
ridge <- as.matrix(fit$beta)
write.table(ridge, "C:/Users/Diogo/Documents/masters/Ageing and adipose tissue/Ridge data/ridge.txt", sep="\t")

plot(fit, label = TRUE)
plot(fit)
print(fit)

write.table
ADD REPLY
0
Entering edit mode

amazing! can you share a tutorial on how to do this?

Dude... follow the links provided by cpad0112...

ADD REPLY
1
Entering edit mode

check the times between answers...

ADD REPLY
0
Entering edit mode

Thank you cpad and kevin for the responses, extremely helpful. I wanted to leave a thanks here for the rest of us that are actually thankful for helping the newbies.

ADD REPLY

Login before adding your answer.

Traffic: 2668 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6