Skip to content
Prev 307136 / 398506 Next

svyhist

On Oct 5, 2012, at 3:33 PM, Muhuri, Pradip (SAMHSA/CBHSQ) wrote:

            
This is the top of the output of str applied to the data argument you offered to svyhist:
List of 9
 $ cluster   :'data.frame':	0 obs. of  1 variable:
  ..$ psu: Factor w/ 47 levels "109.1","115.2",..: 
  ..- attr(*, "terms")=Classes 'terms', 'formula' length 2 ~psu
  .. .. ..- attr(*, "variables")= language list(psu)
  .. .. ..- attr(*, "factors")= int [1, 1] 1
  .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. ..$ : chr "psu"
  .. .. .. .. ..$ : chr "psu"

At least one problem seems pretty clear. No data. That can be corrected by wrapping as.numeric() around the factor on which you are subsetting in two places.

Another problem may arise when you restrict to one class only, namely there won't any "design" to work with. All the clusters .... there would be only one ....  no longer have any multiplicity,  and svyhist apparently isn't built to handle situation, at least with that design argument.

Error in onestrat(x[index, , drop = FALSE], clusters[index], nPSU[index][1],  : 
  Stratum (2) has only one PSU at stage 1

Taking the 'stratum' argument out of the design() spec allows it to proceed, but I do not know if that is introducing invalidity in the analysis.