How to do weighted ridge regression in R?

M

mishrasonu1993

Guest
#1
How can we do weighted ridge regression in R?

In MASS package in R, I can do weighted linear regression by passing a weight parameter to `lm`. It can be seen that the model with weights is different from the one without weights.

Code:
    # with weights
    > model = lm( y ~ X - 1, weights = w)
    > model$coeff
    X(Intercept) XSepal.Length  XSepal.Width XPetal.Length  XPetal.Width
    -2.1135159    -0.1890203     1.8198141    -1.1771699     2.2840825 

    # without weights
    > model = lm( y ~ X - 1)
    > model$coeff
    X(Intercept) XSepal.Length  XSepal.Width XPetal.Length  XPetal.Width 
    -5.23869771    0.09802533    2.16742901   -1.07331102    2.40425352
However, when I try to replicate the same with `lm.ridge`, model generated with and without weights are same.

Code:
      # with weights
      > model = lm.ridge(y ~ X - 1, lambda=lmd, weights = w)
      > model
      X(Intercept) XSepal.Length  XSepal.Width XPetal.Length  XPetal.Width 
      -5.17253104    0.08770593    2.15946954   -1.06284572    2.38714738
    
      # without weights
      > model = lm.ridge(y ~ X - 1, lambda=lmd, weights = w)
      > model
      X(Intercept) XSepal.Length  XSepal.Width XPetal.Length  XPetal.Width 
      -5.17253104    0.08770593    2.15946954   -1.06284572    2.38714738