Problem with missings in variable weight in complex sampling

Asked

Viewed 189 times

5

The presence of missings in the variable weight of a complex sampling is preventing the R from calculating the mean. Initially I tried the na.rm = TRUE, but it did not work, follows excerpt:

svymean(basedados$variavel , svydesign( id = basedados$estrato , weight =     
    basedados$peso ),na.rm=TRUE)

Error in 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)

Error in na.Weight(data.frame(Weights)) : Missing values in `Weights'

Then it was suggested another way, which shows another error message, follows excerpt:

svymean(bd$Dcoracao , svydesign(id = bd[which(!is.na(bd$teste)),"V0024"], weight =   
   bd[which(!is.na(bd$teste)),"teste"]))

Error in tapply(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 the shorter object length
  2. In x * pweights : length of the larger object is not multiple of the shorter object length
  • 1

    Have you tried to clear the base before using it on svymean and svydesign? Declare a variable temp = bd[!is.na(bd$peso),]? and then run the search on top of those values.

  • 1

    Henry, would it be possible to put the results of summary(bd), str(bd) in your question?

  • @Carloscinelli, the problem was even presenting missings in the variable assigned as Weight, since I had only 12 missings out of 62000, I turned them to zero and continued. Thank you for your attention

  • @Henriquepizarro answer your question with solution you found, not to leave unanswered.

  • @Carloscinelli, thank you for the warning, I’m new to this community.

1 answer

1

Apparently the variable assigned to the Weight parameter cannot contain missings. In my particular case the base contained only 12 cases of 62000, so I assigned zero to the missings and the command worked normally.

Browser other questions tagged

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