Problem with missings in the weight variable in complex sampling

5

The presence of missings in the variable weight of a complex sampling is preventing R to calculate the mean. I initially tried na.rm = TRUE , but it did not work, here is the 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 another way was suggested, which shows another error message, as follows:

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

Additionally: Missed warning messages:

  • In x * pweights: length of the largest object is not multiple of the length of the smaller object
  • In x * pweights: length of the largest object is not multiple of the length of the smaller object
  • asked by anonymous 05.01.2015 / 18:23

    1 answer

    1

    The variable assigned to the weight parameter may not contain missions. In my case in particular the base contained only 12 cases of 62000, so I assigned zero to the missings and the command worked normally.

        
    07.01.2015 / 14:50