Even if you use "na.rm = TRUE", the error message for the missing values

2

When I use the command for complex sample mean, a warning appears that there are missing values in weights, however I am using the na.rm = TRUE option. Does anyone know what's going on?

Here's the snippet:

svymean(basedados$variavel , svydesign( id = basedados$estrato , weight =     
        basedados$peso ),na.rm=TRUE)
> Erro em na.weight(data.frame(weights)) : missing values in 'weights'

I also tested this version and nothing:

 svymean(dp$Dcoracao , svydesign( id = dp$V0024 , weight = dp$teste , na.rm = TRUE   
 ),na.rm=TRUE)
 > Erro em na.weight(data.frame(weights)) : missing values in 'weights'
    
asked by anonymous 30.12.2014 / 16:25

1 answer

1

The argument na.rm of the svymean function refers to missing values in the variable under which you are averaging (in this case, the variable basedados$variavel in the first example and dp$Dcoracao in the second example).

On the other hand, the error is indicated that you have missing values in the weighting variable (variable basedados$peso in the first example and dp$teste in the second example). To solve the problem, you need to find / impute these values in some way. Another alternative if you can not do this is to remove cases with missing values in your weight variable in the svydesign function. I think there is no argument na.rm for function svydesign , but you can try the following:

svymean(dp$Dcoracao , svydesign(id = dp[which(!is.na(dp$teste)),"V0024"], 
        weight = dp[which(!is.na(dp$teste)),"teste"])
    
30.12.2014 / 17:02