Skip to content
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 5 commits into from
Feb 20, 2023
Merged

Conversation

szimmer
Copy link
Contributor

@szimmer szimmer commented Mar 11, 2022

This seems like a more logical default given the context people will expect. Documentation already states:

This addresses issue #141

@szimmer szimmer changed the title Sp default survey_prop should default to proportions Mar 11, 2022
@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2022

Codecov Report

Merging #142 (dfef559) into main (ac3fb35) will decrease coverage by 0.07%.
The diff coverage is 80.00%.

@@            Coverage Diff             @@
##             main     #142      +/-   ##
==========================================
- Coverage   83.27%   83.19%   -0.08%     
==========================================
  Files          22       22              
  Lines        1106     1113       +7     
==========================================
+ Hits          921      926       +5     
- Misses        185      187       +2     
Impacted Files Coverage Δ
R/survey_statistics.r 86.98% <80.00%> (-0.68%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac3fb35...dfef559. Read the comment docs.

@szimmer
Copy link
Contributor Author

szimmer commented Mar 23, 2022

Updated with messaging that default behavior has changed. While I was at it, I added another method to estimate confidence intervals.

Copy link
Owner

@gergness gergness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for taking this on! Two small things

proportion = proportion, prop_method = prop_method,
deff = deff, df = df, .svy = cur_svy()))
if (missing(x)){
if (missing(proportion) & ("ci" %in% vartype)){
Copy link
Owner

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 from survey::svymean and survey_prop's comes from survey::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 it TRUE.

library(srvyr)
#> 
#> Attaching package: 'srvyr'
#> The following object is masked from 'package:stats':
#> 
#>     filter
data(api, package = "survey")

dstrata <- apistrat %>%
  as_survey_design(strata = stype, weights = pw)



dstrata %>%
  group_by(above = api99 > 600) %>%
  summarise(
    prop_default = survey_mean(vartype = "ci"),
    prop_true = survey_mean(proportion = TRUE, vartype = "ci"),
    prop_false = survey_mean(proportion = FALSE, vartype = "ci")
  ) %>% select(ends_with("low"))
#> When `proportion` is unspecified, `survey_mean()` now defaults to `proportion = TRUE` when `x` is left out. This should improve confidence interval coverage.
#> This message is displayed once per session.
#> # A tibble: 2 × 3
#>   prop_default_low prop_true_low prop_false_low
#>              <dbl>         <dbl>          <dbl>
#> 1            0.365         0.367          0.365
#> 2            0.483         0.483          0.483

Copy link
Owner

@gergness gergness Feb 20, 2023

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

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.",
Copy link
Owner

Choose a reason for hiding this comment

The 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:

inform(
    c(
        "When `proportion` is unspecified, `survey_prop()` now defaults to `proportion = TRUE`.",  
        i = "This should improve confidence interval coverage."
    ),
    .frequency = "once", .frequency_id="spd"
)

@gergness gergness merged commit 126bcc8 into gergness:main Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants