-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
survey_prop should default to proportions #142
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2377725
Change default in survey_prop to be proportion.
szimmer 07a8eaa
Updating documentation for survey_mean/survey_prop defaults
szimmer f0e0246
Update messaging to indicate new default behavior. This will be shown…
szimmer 9c4b44c
Add xlogit as method for confidence intervals for proportions
szimmer dfef559
Update documentation to match change of arguments
szimmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
#' | ||
|
@@ -93,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, | ||
... | ||
|
@@ -105,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) | ||
|
@@ -132,15 +140,20 @@ survey_mean <- function( | |
survey_prop <- function( | ||
vartype = c("se", "ci", "var", "cv"), | ||
level = 0.95, | ||
proportion = FALSE, | ||
prop_method = c("logit", "likelihood", "asin", "beta", "mean"), | ||
proportion = TRUE, | ||
prop_method = c("logit", "likelihood", "asin", "beta", "mean", "xlogit"), | ||
deff = FALSE, | ||
df = NULL, | ||
... | ||
) { | ||
.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.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After seeing how long the message is, let's break it up by doing the following:
|
||
.frequency = "once", .frequency_id="spd") | ||
} | ||
|
||
if (!is.null(vartype)) { | ||
vartype <- if (missing(vartype)) "se" else match.arg(vartype, several.ok = TRUE) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message is not actually true because of how missing args works (even though (
missing(proportion)
is TRUE, the default value comes from line 97 not line 143 in this branch of code).I actually kind of prefer this behavior - my argument would be that this way we're better adhering to the mental model that
survey_mean
's behavior comes fromsurvey::svymean
andsurvey_prop
's comes fromsurvey::svyciprop
. But wanted to check if you disagreed.My preference is to fix by removing this
inform
, but the other option is to change line 97 so that itTRUE
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just noticed this as I was getting ready to submit. I need to submit in the next few days, so plan to go with my gut when I get back to this later tonight, unless I hear from you