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

success argument for prop_test #343

Closed
AmeliaMN opened this issue Dec 3, 2020 · 5 comments
Closed

success argument for prop_test #343

AmeliaMN opened this issue Dec 3, 2020 · 5 comments

Comments

@AmeliaMN
Copy link

AmeliaMN commented Dec 3, 2020

It would be nice to have a success argument for prop_test, analogous to the one from mosaic::prop.test. Here's how it could be used:

gss %>%
    prop_test(response = college, p = 0.6, success = "no degree")
@mine-cetinkaya-rundel
Copy link
Collaborator

I agree, especially since specify() also has that argument

@simonpcouch
Copy link
Collaborator

Ah, agreed! Giving this a go right now. :-)

@rpruim
Copy link

rpruim commented Dec 3, 2020

Note about how mosaic processes this: If you specify success, all other values are collectively "failure":

prop.test( ~ resample(LETTERS[1:4], size = 100), success = "A", p = 0.25)
## 
## 	1-sample proportions test with continuity correction
## 
## data:  $resample(LETTERS[1:4], size = 100)  [with success = A]
## X-squared = 0.12, df = 1, p-value = 0.729
## alternative hypothesis: true p is not equal to 0.25
## 95 percent confidence interval:
##  0.1883648 0.3696071
## sample estimates:
##    p 
## 0.27 

Is that how specify() works as well?

@simonpcouch
Copy link
Collaborator

In specify(), the success argument is only used for binary response variables. It works similarly in that the "not success" doesn't have to be explicitly stated, but "all other values" in that case would only be one value regarded as failure. :-)

I usually think of these wrappers as just providing a tidy interface to the analogous function from stats, in which case success would be ignored (as the factor levels are in stats::prop.test, I think) in the case that the response has more than 2 levels.

Just put in a PR (linked above)! A demo of how this could look:

library(infer)

# one-sample (note that p != .5)
prop_test(gss,
          college ~ NULL,
          p = .2,
          success = "degree")
#> # A tibble: 1 x 4
#>   statistic chisq_df  p_value alternative
#>       <dbl>    <int>    <dbl> <chr>      
#> 1      67.5        1 2.08e-16 two.sided

prop_test(gss,
          college ~ NULL,
          p = .2,
          success = "no degree")
#> # A tibble: 1 x 4
#>   statistic chisq_df   p_value alternative
#>       <dbl>    <int>     <dbl> <chr>      
#> 1      636.        1 2.98e-140 two.sided

prop_test(gss,
          college ~ NULL,
          p = .8,
          success = "degree")
#> # A tibble: 1 x 4
#>   statistic chisq_df   p_value alternative
#>       <dbl>    <int>     <dbl> <chr>      
#> 1      636.        1 2.98e-140 two.sided

# two-sample
prop_test(gss, 
          college ~ sex,  
          order = c("female", "male"),
          success = "degree")
#> # A tibble: 1 x 6
#>   statistic chisq_df p_value alternative lower_ci upper_ci
#>       <dbl>    <dbl>   <dbl> <chr>          <dbl>    <dbl>
#> 1 0.0000204        1   0.996 two.sided    -0.0917    0.101

prop_test(gss, 
          college ~ sex,  
          order = c("female", "male"),
          success = "no degree")
#> # A tibble: 1 x 6
#>   statistic chisq_df p_value alternative lower_ci upper_ci
#>       <dbl>    <dbl>   <dbl> <chr>          <dbl>    <dbl>
#> 1 0.0000204        1   0.996 two.sided     -0.101   0.0917

prop_test(gss, 
          college ~ sex,  
          order = c("male", "female"),
          success = "degree")
#> # A tibble: 1 x 6
#>   statistic chisq_df p_value alternative lower_ci upper_ci
#>       <dbl>    <dbl>   <dbl> <chr>          <dbl>    <dbl>
#> 1 0.0000204        1   0.996 two.sided     -0.101   0.0917

Created on 2020-12-03 by the reprex package (v0.3.0.9001)

@github-actions
Copy link

github-actions bot commented Mar 8, 2021

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants