From 237772591147a298a0a13e169c0dd832bce6fbe5 Mon Sep 17 00:00:00 2001 From: Stephanie Zimmer Date: Fri, 11 Mar 2022 11:04:28 -0500 Subject: [PATCH 1/5] Change default in survey_prop to be proportion. --- R/survey_statistics.r | 2 +- man/survey_mean.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/survey_statistics.r b/R/survey_statistics.r index 7a7325c..0813328 100644 --- a/R/survey_statistics.r +++ b/R/survey_statistics.r @@ -132,7 +132,7 @@ survey_mean <- function( survey_prop <- function( vartype = c("se", "ci", "var", "cv"), level = 0.95, - proportion = FALSE, + proportion = TRUE, prop_method = c("logit", "likelihood", "asin", "beta", "mean"), deff = FALSE, df = NULL, diff --git a/man/survey_mean.Rd b/man/survey_mean.Rd index 0e13bae..9cfb9e5 100644 --- a/man/survey_mean.Rd +++ b/man/survey_mean.Rd @@ -20,7 +20,7 @@ survey_mean( survey_prop( vartype = c("se", "ci", "var", "cv"), level = 0.95, - proportion = FALSE, + proportion = TRUE, prop_method = c("logit", "likelihood", "asin", "beta", "mean"), deff = FALSE, df = NULL, From 07a8eaaf49fbecee73486991351f7e56acadd143 Mon Sep 17 00:00:00 2001 From: Stephanie Zimmer Date: Fri, 11 Mar 2022 11:18:30 -0500 Subject: [PATCH 2/5] Updating documentation for survey_mean/survey_prop defaults --- R/survey_statistics.r | 12 +++++++----- man/survey_mean.Rd | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/R/survey_statistics.r b/R/survey_statistics.r index 0813328..a4aa3e4 100644 --- a/R/survey_statistics.r +++ b/R/survey_statistics.r @@ -1,12 +1,14 @@ #' Calculate mean/proportion and its variation using survey methods #' -#' Calculate means and proportions from complex survey data. A wrapper -#' around \code{\link[survey]{svymean}}, or if \code{proportion = TRUE}, -#' \code{\link[survey]{svyciprop}}. \code{survey_mean} should always be -#' called from \code{\link{summarise}}. +#' Calculate means and proportions from complex survey data. +#' \code{survey_mean} with \code{proportion = FALSE} (the default) or \code{survey_prop} with \code{proportion = FALSE} +#' is a wrapper around \code{\link[survey]{svymean}}. +#' \code{survey_prop} with \code{proportion = TRUE} (the default) or \code{survey_mean} with \code{proportion = TRUE} +#' is a wrapper around \code{\link[survey]{svyciprop}}. +#' \code{survey_mean} and \code{survey_prop} should always be called from \code{\link{summarise}}. #' #' Using \code{survey_prop} is equivalent to leaving out the \code{x} argument in -#' \code{survey_mean} and this calculates the proportion represented within the +#' \code{survey_mean} and setting \code{proportion = TRUE} and this calculates the proportion represented within the #' data, with the last grouping variable "unpeeled". \code{\link{interact}} #' allows for "unpeeling" multiple variables at once. #' diff --git a/man/survey_mean.Rd b/man/survey_mean.Rd index 9cfb9e5..2c4ddb3 100644 --- a/man/survey_mean.Rd +++ b/man/survey_mean.Rd @@ -56,14 +56,16 @@ but Inf is the usual survey package's default (except in \item{...}{Ignored} } \description{ -Calculate means and proportions from complex survey data. A wrapper -around \code{\link[survey]{svymean}}, or if \code{proportion = TRUE}, -\code{\link[survey]{svyciprop}}. \code{survey_mean} should always be -called from \code{\link{summarise}}. +Calculate means and proportions from complex survey data. +\code{survey_mean} with \code{proportion = FALSE} (the default) or \code{survey_prop} with \code{proportion = FALSE} +is a wrapper around \code{\link[survey]{svymean}}. +\code{survey_prop} with \code{proportion = TRUE} (the default) or \code{survey_mean} with \code{proportion = TRUE} +is a wrapper around \code{\link[survey]{svyciprop}}. +\code{survey_mean} and \code{survey_prop} should always be called from \code{\link{summarise}}. } \details{ Using \code{survey_prop} is equivalent to leaving out the \code{x} argument in -\code{survey_mean} and this calculates the proportion represented within the +\code{survey_mean} and setting \code{proportion = TRUE} and this calculates the proportion represented within the data, with the last grouping variable "unpeeled". \code{\link{interact}} allows for "unpeeling" multiple variables at once. } From f0e024669ef66ea05144bfb70cf2773133dc7e2d Mon Sep 17 00:00:00 2001 From: Stephanie Zimmer Date: Tue, 22 Mar 2022 20:33:14 -0400 Subject: [PATCH 3/5] Update messaging to indicate new default behavior. This will be shown once per session --- R/survey_statistics.r | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/R/survey_statistics.r b/R/survey_statistics.r index a4aa3e4..506fcb3 100644 --- a/R/survey_statistics.r +++ b/R/survey_statistics.r @@ -107,9 +107,15 @@ survey_mean <- function( } prop_method <- match.arg(prop_method) if (is.null(df)) df <- survey::degf(cur_svy_full()) - if (missing(x)) return(survey_prop(vartype = vartype, level = level, - proportion = proportion, prop_method = prop_method, - deff = deff, df = df, .svy = cur_svy())) + if (missing(x)){ + if (missing(proportion) & ("ci" %in% vartype)){ + inform("When `proportion` is unspecified, `survey_mean()` now defaults to `proportion = TRUE` when `x` is left out. This should improve confidence interval coverage.", + .frequency = "once", .frequency_id="sm_pd") + } + return(survey_prop(vartype = vartype, level = level, + proportion = proportion, prop_method = prop_method, + deff = deff, df = df, .svy = cur_svy())) + } stop_for_factor(x) if (!proportion) { if (is.logical(x)) x <- as.integer(x) @@ -143,6 +149,11 @@ survey_prop <- function( .svy <- cur_svy() .full_svy <- cur_svy_full() + if (missing(proportion) & ("ci" %in% vartype)){ + inform("When `proportion` is unspecified, `survey_prop()` now defaults to `proportion = TRUE`. This should improve confidence interval coverage.", + .frequency = "once", .frequency_id="spd") + } + if (!is.null(vartype)) { vartype <- if (missing(vartype)) "se" else match.arg(vartype, several.ok = TRUE) } From 9c4b44cf7b24a0abaa09d52dcbdcc5699370794e Mon Sep 17 00:00:00 2001 From: Stephanie Zimmer Date: Tue, 22 Mar 2022 20:37:46 -0400 Subject: [PATCH 4/5] Add xlogit as method for confidence intervals for proportions --- R/survey_statistics.r | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/survey_statistics.r b/R/survey_statistics.r index 506fcb3..fc1fa89 100644 --- a/R/survey_statistics.r +++ b/R/survey_statistics.r @@ -95,7 +95,7 @@ survey_mean <- function( vartype = c("se", "ci", "var", "cv"), level = 0.95, proportion = FALSE, - prop_method = c("logit", "likelihood", "asin", "beta", "mean"), + prop_method = c("logit", "likelihood", "asin", "beta", "mean", "xlogit"), deff = FALSE, df = NULL, ... @@ -141,7 +141,7 @@ survey_prop <- function( vartype = c("se", "ci", "var", "cv"), level = 0.95, proportion = TRUE, - prop_method = c("logit", "likelihood", "asin", "beta", "mean"), + prop_method = c("logit", "likelihood", "asin", "beta", "mean", "xlogit"), deff = FALSE, df = NULL, ... From dfef5590ea70efdb2af43ed9b6b7b983362801e1 Mon Sep 17 00:00:00 2001 From: Stephanie Zimmer Date: Tue, 22 Mar 2022 20:48:35 -0400 Subject: [PATCH 5/5] Update documentation to match change of arguments --- man/survey_mean.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/survey_mean.Rd b/man/survey_mean.Rd index 2c4ddb3..c189034 100644 --- a/man/survey_mean.Rd +++ b/man/survey_mean.Rd @@ -11,7 +11,7 @@ survey_mean( vartype = c("se", "ci", "var", "cv"), level = 0.95, proportion = FALSE, - prop_method = c("logit", "likelihood", "asin", "beta", "mean"), + prop_method = c("logit", "likelihood", "asin", "beta", "mean", "xlogit"), deff = FALSE, df = NULL, ... @@ -21,7 +21,7 @@ survey_prop( vartype = c("se", "ci", "var", "cv"), level = 0.95, proportion = TRUE, - prop_method = c("logit", "likelihood", "asin", "beta", "mean"), + prop_method = c("logit", "likelihood", "asin", "beta", "mean", "xlogit"), deff = FALSE, df = NULL, ...