[R] Can you get the DEFT from svyratio?
Anthony Damico
ajdamico at gmail.com
Wed Dec 7 23:32:17 CET 2016
hi, your code isn't runnable at
fpc= ~M + Nbar)
On Wed, Dec 7, 2016 at 5:03 PM, Chris Webb <iknowchris at gmail.com> wrote:
> To Dr. Lumley or anyone who may know the answer,
>
> I am trying to obtain ratio estimates from Levy and Lemeshow's Sampling of
> Populations 4th ed. page 281. The results in the book are from STATA.
> According to the STATA output, the DEFT is 0.830749
>
> I can recreate all of the results except for DEFT. For svytotal and svymean
> I can use the option deff="replace" to obtain DEFT results (by taking the
> square root), but I get an error when using this option with svyratio. The
> problem can be my poor understanding of how to calculate DEFT, but perhaps
> it's not implemented for svyratio?
>
>
> R code to that fails:
>
> library(survey)
>
> # Creating the dataset
> df_tbl_10_1 <-
> data.frame(
> center = c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5),
> nurse = c(rep(c(1,2,3),5)),
> seen = c(58,44,18,42,63,10,13,18,37,16,32,10,25,23,23),
> referred = c(5,6,6,3,19,2,12,6,30,5,14,4,17,9,14)
> )
> df_tbl_10_2 <- df_tbl_10_1[c(2,3,4,6,10,11),]
>
> # Defining the cluster sampling design
> svy_tbl_10_2 <-
> svydesign(id=~center + nurse,
> data=df_tbl_10_2,
> fpc= ~M + Nbar)
>
> # Ratio estimates
> svyratio(~referred, ~seen, svy_tbl_10_2)
> confint(svyratio(~referred, ~seen, svy_tbl_10_2), df=degf(svy_tbl_10_2))
>
> # DEFF
> deff(svyratio(~referred, ~seen, svy_tbl_10_2, deff=TRUE))
>
> # DEFT (fails)
> sqrt(deff(svyratio(~referred, ~seen, svy_tbl_10_2, deff="replace")))
>
> Fail message:
> Error in if (deff) deffs <- matrix(ncol = nd, nrow = nn) : argument is not
> interpretable as logical
>
>
> For other individuals, I have included code that will calculate DEFF and
> DEFT for svytotal on page 280, This code doesn't fail.
>
> svytotal(~referred, svy_tbl_10_2)
> confint(svytotal(~referred, svy_tbl_10_2), df=degf(svy_tbl_10_2))
> deff(svytotal(~referred, svy_tbl_10_2, deff=TRUE))
> sqrt(deff(svytotal(~referred, svy_tbl_10_2, deff="replace")))
>
>
>
> To recap: can you get the DEFT from svyratio?
>
> Sincerely,
> Chris Webb
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list