Home > Net >  How to add coeficient to linear model
How to add coeficient to linear model

Time:09-26

I want to manually set a coefficient for a variable that is not input in my linear model so that I can perform a spatial prediction.

I'm going to try to expose my question in the most simple and clear way. What I have:

  • a raster stack with 4 binary variables for soil cover: agro, open, tran and urb
  • a linear model lm(formula = no2 ~ open tran urb, data = df)

The reason why I only used 3 of the variables in my linear ways to prevent multicollinearity in the model, because they are proportions of land coverage that add up to 100%.

So, my goal is to add a coefficient to my model for the agro variable, so that all of the 4 variables are used correctly in raster::predict()

CodePudding user response:

You can use the offset term in the formula and include the desired coefficient and variable therein:

lm(formula = no2 ~ open   tran   urb   offset(agro*400), data = df)

So this is regressing formula on open, tran and urb plus the fixed term agro * 400. For more than one given coefficient, add the appropriate additional offset() terms.

CodePudding user response:

You can avoid the collinearity by leaving the intercept out of your model. Use

lm(formula = no2 ~ open   tran   urb   agro - 1, data = df)

and you'll be able to estimate coefficients for all of the predictors (but no intercept term).

  • Related