user16116359
user16116359

Reputation: 21

How to report the unweighted number of missing values when using gtsummary :: tbl_svy_summary?

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"
)    

table of result

Upvotes: 2

Views: 570

Answers (1)

Daniel D. Sjoberg
Daniel D. Sjoberg

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**")

enter image description here Created on 2021-06-04 by the reprex package (v2.0.0)

Upvotes: 1

Related Questions