Question: does the multiple linear regression from glmnet generate a formula?
0
gravatar for demoraesdiogo2017
21 months ago by
demoraesdiogo201740 wrote:

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?

ADD COMMENTlink modified 21 months ago • written 21 months ago by demoraesdiogo201740
1

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 REPLYlink modified 21 months ago • written 21 months ago by cpad011214k

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 REPLYlink written 21 months ago by demoraesdiogo201740

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

ADD REPLYlink written 21 months ago by Kevin Blighe67k

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 REPLYlink written 21 months ago by demoraesdiogo201740

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

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

ADD REPLYlink written 21 months ago by Kevin Blighe67k
1

check the times between answers...

ADD REPLYlink written 21 months ago by demoraesdiogo201740

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 REPLYlink written 18 months ago by csugai0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1301 users visited in the last hour