This is a test version of Biostars. For the public version, visit https://www.biostars.org.
are my results what they are supposed to look like?

Hello

My question is fairly simple

Here 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 assume variable A should have a coefficient of 1 as it fits perfectly with the response variable, and E should be the exact same value with a negative coefficient instead.

My code is the following:

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


##

plot(CV)
## 

best_lambda = CV$lambda.1se
lasso_coef = CV$glmnet.fit$beta[, CV$glmnet.fit$lambda == best_lambda]

##

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

##

fit$beta[,1]

plot(lasso_coef, xvar = "lambda", label = TRUE)

lasso_coef <- as.matrix(fit$beta)
write.table(lasso_coef, "C:/Users/Diogo/Documents/masters/LIHC/teste de regressao/regressionlasso.txt", sep="\t")

What have I done wrong?

lasso linear regression glmnet

you're using lasso. It will strive to both fit the data and keep the coefficients small. The balance of these two forces is influencing the coefficients that are fitted.

0 answers

No answers yet.

Log in to answer this question.