Search code examples
rsurvey

Does svytable exclude NAs in the calculation of weighted N's


library(survey)

Despite scourging the documentation, I cannot figure out how svytable handles missing values.

As Thomas Lumley mentions in this post svytable does not have a na.rm option. My assumption is that svytable removes the NA's from the calculation of the weighted N's, but I cannot be certain.

Any insight?

Here is an example of my data and method:

data_mis <- read_table2("Q50_1   Q50_2   Q38 Q90 pov gender  wgt id
1   3   Yes NA   High    M   1.3 A
NA   4   No  2   Med F   0.4 B
4   2   NA 4   Low F   1.2 C
3   3   No  2   High    M   0.5 D
1   NA   No  NA   High    M   0.7 E
2   2   Yes 3   Low F   0.56 F
4   4   Yes 2   Med F   0.9 G
")


design_mis <- svydesign(id =~id,
                    weights  = ~wgt,
                    nest = FALSE,
                    data = data_in_mis)


svytable(wgt~Q50_1, design_in_mis)

Output:

  Q50_1
         1      2      3      4 
    2.1800 0.3136 0.2500 2.2500

Do these results exclude the NA's or no?


Solution

  • I just noticed this sentence in the documentation:

    enter image description here

    If you add na.action=na.pass to include NA's it would seem logical to assume that syvtable removes the NAs naturally.