How to use the svymean () function if I have missings in the comments?

2

I'm using the svymean () function of the Survey package, but when the data has missings ("NA"), calculated.

Please, does anyone know how to solve this?

    
asked by anonymous 20.10.2014 / 14:00

2 answers

1

The svymean function has a na.rm argument that by default is FALSE , ie if you do not quote the argument in the function call, it will use the FALSE value. If you do

svymean(..., na.rm = T)

She should do the calculation by deleting missing observations, which should solve your problem.

    
20.10.2014 / 14:48
1

Daniel's answer is correct: just add the parameter na.rm = TRUE . I only add that care should be taken when using this parameter when we analyze more than 1 variable at the same time (I do not know if that is the case), since survey removes the observation that has NA in at least 1 of the analyzed variables , even if in another variable it is not missing. For example:

require(survey)
exemplo <- data.frame(ID = 1:10, var = rnorm(10), var2 = rnorm(10, 5), peso = rchisq(10, 5))
exemplo[10, 2] <- NA # Acrescento um missing na variável var
amostra <- svydesign(ids = ~ ID, data = exemplo, weights = ~ peso)
svymean(~ var + var2, design = amostra, na.rm = TRUE)
svymean(~ var2, design = amostra, na.rm = TRUE)

At first svymean we get:

        mean     SE
var  0.56224 0.3166
var2 5.07549 0.4867

Already in the second (only for var2):

       mean     SE
var2 5.0833 0.4393
    
28.10.2014 / 20:13