While using tbl_svysummary, an error is thrown if the source data has missing values, whereas in tbl_summary, a simple warning is thrown (and the filtering of the missing data done in background)
Simple reprex:
database = data.frame(
INDIV_AGE = rnorm(100, mean = 50, sd = 4),
INDIV_GENDER = rbinom(n = 100, size=1, prob = 0.6),
PAIN_SCALE = factor(sample(c("Low", "Elevated"), size = 100, replace = T)),
FLOWER_COLOR = factor(sample(c("Blue", "Red"), size = 100, replace = T)),
poids = rnorm(100, mean = 2, sd = 0.8)
)
database[1, "INDIV_GENDER"] = NA #if you remove this line it works fine
design = survey::svydesign(
id = ~1,
weights = ~poids,
data = database
)
design |>
gtsummary::tbl_svysummary(
by = "INDIV_GENDER"
)
Interestingly, the package does throw the usual warning, but also issues an error:
1 missing rows in the "INDIV_GENDER" column have been removed.
Error in model.frame.default(formula = weights ~ ..ard_total_n.., data = model.frame(design), :
variable lengths differ (found for '..ard_total_n..')
I'm not sure this is the expected behaviour, should I file an issue on github?
poidsvector is still 100 units long. I think that's why the analysis can't be done.