ngreifer / WeightIt

WeightIt: an R package for propensity score weighting
https://ngreifer.github.io/WeightIt/
102 stars 12 forks source link

SL.ridge leads to no weights estimated #26

Open mleipzig opened 3 years ago

mleipzig commented 3 years ago

I tried to use SuperLearner with WeightIt using this code and everything worked just fine with Sl.glm, but ridge led to some errors.

W.out <- weightit(treat ~ age + educ + race + married + nodegree + re74 + re75, data = lalonde, estimand = "ATE", method = "super", SL.method = "method.balance", SL.library = c("SL.glm", "SL.ridge" ))

and got this

Error in (function (Y, X, newX, family, lambda = seq(1, 20, 0.1), ...)  : 
  Currently only works with gaussian data
Error in (function (Y, X, newX, family, lambda = seq(1, 20, 0.1), ...)  : 
  Currently only works with gaussian data
In addition: Warning message:
In FUN(X[[i]], ...) : Error in algorithm SL.ridge 
  The Algorithm will be removed from the Super Learner (i.e. given weight 0) 

Error in (function (Y, X, newX, family, lambda = seq(1, 20, 0.1), ...)  : 
  Currently only works with gaussian data
In addition: Warning message:
In FUN(X[[i]], ...) : Error in algorithm SL.ridge 
  The Algorithm will be removed from the Super Learner (i.e. given weight 0) 

Error in (function (Y, X, newX, family, lambda = seq(1, 20, 0.1), ...)  : 
  Currently only works with gaussian data
In addition: Warning messages:
1: In FUN(X[[i]], ...) : Error in algorithm SL.ridge 
  The Algorithm will be removed from the Super Learner (i.e. given weight 0) 

2: In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  :
  prediction from a rank-deficient fit may be misleading
Error in (function (Y, X, newX, family, lambda = seq(1, 20, 0.1), ...)  : 
  Currently only works with gaussian data
In addition: Warning message:
In FUN(X[[i]], ...) : Error in algorithm SL.ridge 
  The Algorithm will be removed from the Super Learner (i.e. given weight 0) 

Error in (function (Y, X, newX, family, lambda = seq(1, 20, 0.1), ...)  : 
  Currently only works with gaussian data
In addition: Warning message:
In FUN(X[[i]], ...) : Error in algorithm SL.ridge 
  The Algorithm will be removed from the Super Learner (i.e. given weight 0) 

Error in (function (Y, X, newX, family, lambda = seq(1, 20, 0.1), ...)  : 
  Currently only works with gaussian data
In addition: Warning message:
In FUN(X[[i]], ...) : Error in algorithm SL.ridge 
  The Algorithm will be removed from the Super Learner (i.e. given weight 0) 

Error in (function (Y, X, newX, family, lambda = seq(1, 20, 0.1), ...)  : 
  Currently only works with gaussian data
In addition: Warning message:
In FUN(X[[i]], ...) : Error in algorithm SL.ridge 
  The Algorithm will be removed from the Super Learner (i.e. given weight 0) 

Error in (function (Y, X, newX, family, lambda = seq(1, 20, 0.1), ...)  : 
  Currently only works with gaussian data
In addition: Warning message:
In FUN(X[[i]], ...) : Error in algorithm SL.ridge 
  The Algorithm will be removed from the Super Learner (i.e. given weight 0) 

Error in (function (Y, X, newX, family, lambda = seq(1, 20, 0.1), ...)  : 
  Currently only works with gaussian data
In addition: Warning message:
In FUN(X[[i]], ...) : Error in algorithm SL.ridge 
  The Algorithm will be removed from the Super Learner (i.e. given weight 0) 

Error in (function (Y, X, newX, family, lambda = seq(1, 20, 0.1), ...)  : 
  Currently only works with gaussian data
In addition: Warning message:
In FUN(X[[i]], ...) : Error in algorithm SL.ridge 
  The Algorithm will be removed from the Super Learner (i.e. given weight 0) 

Warning messages:
1: In FUN(X[[i]], ...) : Error in algorithm SL.ridge  on full data 
  The Algorithm will be removed from the Super Learner (i.e. given weight 0) 

2: In (function (Y, X, newX = NULL, family = gaussian(), SL.library,  :
  Re-running estimation of coefficients removing failed algorithm(s)
Original coefficients are: 
0.00934546386419807, 0.990654536135802

3: No weights were estimated. This is probably a bug,
     and you should report it at https://github.com/ngreifer/WeightIt/issues. 
4: Some weights were estimated as NA, which means a value was impossible to compute (e.g., Inf). Check for extreme values of the treatment or covariates and try removing them. Non-finite weights will be set to 0. 
5: All weights are 0, possibly indicating an estimation failure. 
ngreifer commented 3 years ago

The error from SuperLearner says "Currently only works with gaussian data". This means you cannot use SL.ridge with a binary treatment; it can only be used with a continuous treatment. I'll look into making the WeightIt warnings better in this scenario and see if I can make it fail more gracefully.