Reputation: 21
We analyze weighted survey data and we want to report the unweighted frequencies for categorical variables (in addition to the weighted %). But the {n_unweighted} option in the statistic argument does not work for missing values.
Please find below the problem shown when applying code to hdv2003 data from package question r
library(questionr)
library(survey)
library(gtsummary)
data(hdv2003)
dp <- svydesign(ids=~1, weight= ~poids, data=hdv2003)
dp %>%
tbl_svysummary(
include=c("sexe", "nivetud"),
by="sexe",
statistic=all_categorical()~"{n_unweighted} ({p}%)",
missing = "ifany"
)
Upvotes: 2
Views: 570
Reputation: 11680
The unknown row N cannot be modified via the statistics argument (well, cannot be modified at all, just reports the weighted N!). You can, however, add the unweighted missing N via the add_n()
function. Example below!
library(questionr)
library(survey)
library(gtsummary)
data(hdv2003)
dp <- svydesign(ids=~1, weight= ~poids, data=hdv2003)
tbl <-
dp %>%
tbl_svysummary(
include=c("sexe", "nivetud"),
by="sexe",
statistic=all_categorical()~"{n_unweighted} ({p}%)",
missing = "no"
) %>%
add_n("{N_miss_unweighted}") %>%
modify_header(n ~ "**Unweighted N Missing**")
Created on 2021-06-04 by the reprex package (v2.0.0)
Upvotes: 1