Even using "na.rm = TRUE" the error message of Missing values appears

Asked

Viewed 330 times

2

When I use the complex sample average command, a warning appears that there are Missing values in Weights, but I am using the option na.rm = TRUE. Does anyone know what happens?

Follow the passage:

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'

1 answer

1


The argument na.rm of function svymean refers to missing values in the variable under which you are calculating the average (in your 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 will need to find/impute these values in some way. Another alternative if you cannot do this is to remove the cases with missing values in your weighting variable in the function svydesign. I don’t think there’s an 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"])
  • Hello Rafael Nishimura, I tried to use the command and another error message appeared: Mean(bd$Dcoracao , svydesign(id = bd[which(! is.na(bd$test)),"V0024"], Weight = bd[which(! is.na(bd$test)),"test"]) tapply error(1:NROW(x), list(factor(strata)), Function(index) { : Arguments must have same length Also: Missed warning messages: 1: In x * pweights : length of the larger object is not multiple of length of the smaller object 2: In x * pweights : length of the larger object is not multiple of the length of the smaller object >

Browser other questions tagged

You are not signed in. Login or sign up in order to post.