How to fix one coefficient and fit others using regression

I would like to manually fix a certain coefficient, say $\beta_1=1.0$, then fit coefficients to all other predictors, while keeping $\beta_1=1.0$ in the model.

How can I achieve this using R? I’d particularly like to work with LASSO (glmnet) if possible.

Alternatively, how can I restrict this coefficient to a specific range, say $0.5\le\beta_1\le1.0$?

Answer

You need to use the offset argument like this:

library(glmnet)
x=matrix(rnorm(100*20),100,20)
x1=matrix(rnorm(100),100,1)
y=rnorm(100)
fit1=glmnet(x,y,offset=x1)
fit1$offset
print(fit1)

About the range … I don’t think that has been implemented in glmnet. If they use some numerical method, you may want to dig into the R code and try to restrict it over there, but you’ll need a good, solid programming background.

Attribution
Source : Link , Question Author : raco , Answer Author : Stat

Leave a Comment