are my results what they are supposed to look like?
0
0
Entering edit mode
5.8 years ago

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 • 991 views
ADD COMMENT
2
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 2567 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