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]]
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]]
No, you can't (at the moment), though it shouldn't be too hard to
extend.
I can't run your example, though. I get:
Error in eval(expr, envir, enclos) : object 'M' not found
-thomas
Thomas Lumley
Professor of Biostatistics
University of Auckland
________________________________
From: Chris Webb <iknowchris at gmail.com>
Sent: Thursday, December 8, 2016 11:03 AM
To: r-help at r-project.org; Thomas Lumley
Subject: Can you get the DEFT from svyratio?
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]]
Whoops. I forgot to add the one line that I included later in the script.
(I extracted the prior code from a longer document). The code should run
now. It uses dplyr although this could have been done with alternative
methods.
How would you extend svyratio to included calculations for DEFT?
library(survey)
library(dplyr)
# 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),]
library(dplyr)
df_tbl_10_2 <-
df_tbl_10_2 %>%
mutate(M=5,
Nbar=3,
w=2.5)
# 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")))
On Wed, Dec 7, 2016 at 4: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]]