harrelfe / Hmisc

Harrell Miscellaneous
Other
205 stars 81 forks source link

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

Open mcandocia opened 4 years ago

mcandocia commented 4 years ago

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.