collapse icon indicating copy to clipboard operation
collapse copied to clipboard

[BUG] qsu() inconsistent results when passed NA weights

Open ummel opened this issue 7 months ago • 0 comments

When qsu() is passed all NA weights, it (correctly) returns NA -- but only if no groups are used. If groups are used, it (incorrectly) returns zeros for Mean, Min, and Max instead of NA. This is inconsistent with the behavior of fsum() in the same situation.

data <- num_vars(wlddev)

# Vector of all NA weights
# This can happen for individual groups in a large-scale analysis
wgt <- rep(NA, nrow(wlddev))

# Correct: Returns NA values in presence of NA weights if 'by = NULL'
qsu(data, by = NULL, w = wgt)

# Incorrect: When groups are used, returns zero values for Mean, Min, and Max instead of NA/dash
qsu(data, by = wlddev$region, w = wgt)

# Note that fsum() correctly returns NA in both cases
fsum(data, g = NULL, w = wgt)
fsum(data, g = wlddev$region, w = wgt)

ummel avatar May 26 '25 21:05 ummel