harrelfe/Hmisc

wtd.var() raises error when method='ML', x is all NA, and any arbitrary weights are assigned

mcandocia opened this issue · 0 comments

Example:

wtd.var(c(NA,NA,NA), weights=1:3, method='ML')

Error in stats::cov.wt(cbind(x), weights, method = "ML") : 
  weights must be non-negative and not all zero

raises an error, while

wtd.var(c(NA,NA,NA), method='ML')
# [1] NA

does not.

At worst a warning should be raised.