[R] svyquantile w/ svyby is returning an error

Thomas Lumley tlumley at u.washington.edu
Wed Aug 18 17:43:52 CEST 2010


On Tue, 17 Aug 2010, Marc Zodet wrote:

> svymean w/ svyby is working for me...
>
>> svyby(~visitcnt, ~agegrp3.f, svymean, design=svydes)
>      agegrp3.f  visitcnt se.visitcnt
> 18-44     18-44  8.755552   0.4953235
> 45-64     45-64 10.131555   0.5347806
> 65+         65+  9.588802   0.4323629
>
> svyquantile is working for me...
>
>> svyquantile(~visitcnt, quantiles=c(.25, .5, .75), ties="rounded", design=svydes)
>             0.25      0.5     0.75
> visitcnt 3.021468 6.039823 11.49518
>
> svyquantile w/ svyby is bombing on me...
>
>> svyby(~visitcnt, ~agegrp3.f, svyquantile, quantiles=c(.25, .5, .75), ties="rounded", design=svydes)
> Error in object$coefficients : $ operator is invalid for atomic vectors
>
> i'm not sure what i'm missing/not understanding.
>

svyquantile() doesn't produce standard errors by default. So you either need to ask for standard errors from svyquantile() or tell svyby() not to expect them

> svyby(~api99, ~stype, dclus1, svyquantile, quantiles=c(0.25,0.5), ci=TRUE)
   stype 0.25 0.5  se.0.25   se.0.5
E     E  512 615 22.80167 37.89113
H     H  482 593 42.68682 69.52309
M     M  518 611 54.22614 37.66903
> svyby(~api99, ~stype, dclus1, svyquantile, quantiles=c(0.25,0.5), keep.var=FALSE)
   stype statistic1 statistic2
E     E        512        615
H     H        482        593
M     M        518        611


The help page does say "svyquantile needs ci=TRUE or keep.var=FALSE."

    -thomas


Thomas Lumley
Professor of Biostatistics
University of Washington, Seattle



More information about the R-help mailing list