Skip to content

svytable and na's

4 messages · Thomas Lumley, Manderscheid Katharina

#
On Thu, May 19, 2011 at 11:41 PM, Manderscheid Katharina
<Katharina.Manderscheid at unilu.ch> wrote:
Could you give more details? There isn't an na.rm= argument to
svytable, so it's not surprising it has no effect, but I don't know
what you mean when you say the table "contains all missings." Perhaps
you could show us the output and say how it differs from what you
expected.

     -thomas
#
hi thomas

thanks for your reply.
in the documentation of svytable, the argument na.rm=T is mentioned.

however, last night i figured out what went wrong in my tabulation: i had a dataset which i attached and then defined the missing values - of course they were not stored in the data set. 

attach(data)
vote[vote=="Don't know"|vote=="Refusal"]<-NA
detach(data)

so they disappeared when i created a svydesign-object with weighted data and my table looked like this:
vote
gndr             Yes       No Not eligible to vote  Refusal Don't know
  Male      453.8726 226.7600             154.1651   0.0000    10.8572
  Female    507.6368 302.3634             145.4426   0.0000    17.9157
  No answer   0.0000   0.0000               0.0000   0.0000     0.0000
           vote
gndr        No answer
  Male         0.0000
  Female       0.0000
  No answer    0.0000

thus the solution is to define the missings in the original data set by using data$variable before creating the svydesign-object. 

data$vote[data$vote=="Don't know"|data$vote=="Refusal"]<-NA

then the svytable looks correctly:
vote[drop = T]
gndr[drop = T]      Yes       No Not eligible to vote
        Male   453.8726 226.7600             154.1651
        Female 507.6368 302.3634             145.4426

or is there a way to define factor levels as na directly in an svydesign-object?

best and thanks
katharina

dr. katharina manderscheid

soziologisches seminar
universit?t luzern

kasernenplatz 3
6000 luzern 7

tel. ++41 41 228 4657
#
On Fri, May 20, 2011 at 7:54 PM, Manderscheid Katharina
<Katharina.Manderscheid at unilu.ch> wrote:
No, it isn't.  The page says

Usage

## S3 method for class 'survey.design':
svytable(formula, design, Ntotal = NULL, round = FALSE,...)
## S3 method for class 'svyrep.design':
svytable(formula, design, Ntotal = sum(weights(design, "sampling")),
round = FALSE,...)

There *is* an na.rm= argument to svychisq(), which is documented on
the same help page.
Yes, that's why attach() is usually a bad idea -- it's very easy to
get confused that way.
You can use update()

design <- update(design, vote=ifelse( vote %in% c("Don't
Know","Refusal"), NA, vote))


    -thomas