-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
adding proportion CIs #9
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
b9b940d
adding proportion CIs
ddsjoberg 8659a56
spelling
ddsjoberg 0e8e72c
style
ddsjoberg 5a87753
styling
ddsjoberg 8d3400f
Update .lintr
ddsjoberg 779b7ac
style
ddsjoberg 55b675c
Create ard_proportion_ci.md
ddsjoberg c3db199
Update test-ard_proportion_ci.R
ddsjoberg cb94568
Update test-ard_proportion_ci.R
ddsjoberg 6e57aa3
snap updates
ddsjoberg abb2e1c
Update .lintr
ddsjoberg 0c00842
Update test-ard_proportion_ci.R
ddsjoberg ac3ab98
prop updates
ddsjoberg d6daa55
style
ddsjoberg ec46e4b
Update .lintr
ddsjoberg 2b12f64
Update .lintr
ddsjoberg 2a34ab7
Update .lintr
ddsjoberg 7f1be1b
Merge commit '0d67567c7957153935258b20a52f27b289e116ac'
ddsjoberg 0aa88ca
Update ard_proportion_ci.R
ddsjoberg dfa9db2
Update DESCRIPTION
ddsjoberg 9601d38
updates
ddsjoberg 1cb0d83
doc updates
ddsjoberg 733acdf
docs
ddsjoberg 1a6789f
Update reexports.R
ddsjoberg df66aba
Merge branch 'main' into ard_proportion_ci
ddsjoberg e29bf18
Merge branch 'main' into ard_proportion_ci
ddsjoberg f6796e9
Merge commit 'd5458db56a033d468d8070ff9b4a8a30db095256'
ddsjoberg 27ccfd2
Merge branch 'main' into ard_proportion_ci
ddsjoberg e07ac0c
Merge commit '7978fbd94631089352318c07a05398888e6beefa'
ddsjoberg a707f58
updates
ddsjoberg 1a046fd
Merge branch 'main' into ard_proportion_ci
ddsjoberg 78f986a
Merge branch 'main' into ard_proportion_ci
ddsjoberg 369294e
Merge branch 'main' into ard_proportion_ci
ddsjoberg 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
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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#' ARD Proportion Confidence Intervals | ||
#' | ||
#' `r lifecycle::badge('experimental')`\cr | ||
#' Calculate confidence intervals for proportions. | ||
#' | ||
#' @inheritParams cards::ard_categorical | ||
ddsjoberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr | ||
#' columns to include in summaries. Columns must be class `<logical>` | ||
#' or `<numeric>` values coded as `c(0, 1)`. | ||
#' @param by ([`tidy-select`][dplyr::dplyr_tidy_select])\cr | ||
#' columns to stratify calculations by | ||
#' @param conf.level (`numeric`)\cr | ||
#' a scalar in `(0, 1)` indicating the confidence level. | ||
#' Default is `0.95` | ||
#' @param method (`string`)\cr | ||
#' string indicating the type of confidence interval to calculate. | ||
#' Must be one of `r formals(ard_proportion_ci)[["method"]] |> eval() |> shQuote()`. | ||
#' See `?proportion_ci` for details. | ||
#' @param strata,weights,max.iterations arguments passed to `proportion_ci_strat_wilson()`, | ||
#' when `method='strat_wilson'` | ||
#' | ||
#' @return an ARD data frame | ||
#' @export | ||
#' | ||
#' @examples | ||
#' ard_proportion_ci(mtcars, variables = c(vs, am), method = "wilson") | ||
ard_proportion_ci <- function(data, variables, by = dplyr::group_vars(data), | ||
conf.level = 0.95, | ||
strata, | ||
weights = NULL, | ||
max.iterations = 10, | ||
method = c( | ||
"waldcc", "wald", "clopper-pearson", | ||
"wilson", "wilsoncc", | ||
"strat_wilson", "strat_wilsoncc", | ||
"agresti-coull", "jeffreys" | ||
)) { | ||
# process inputs ------------------------------------------------------------- | ||
cards::process_selectors(data, variables = {{ variables }}, by = {{ by }}) | ||
method <- arg_match(method) | ||
if (method %in% c("strat_wilson", "strat_wilsoncc")) { | ||
cards::process_selectors(data, strata = strata) | ||
check_scalar(strata) | ||
} | ||
|
||
# calculate confidence intervals --------------------------------------------- | ||
cards::ard_complex( | ||
data = data, | ||
variables = {{ variables }}, | ||
by = {{ by }}, | ||
statistics = | ||
~ list( | ||
prop_ci = | ||
switch(method, | ||
"waldcc" = \(x, ...) proportion_ci_wald(x, conf.level = conf.level, correct = TRUE), | ||
"wald" = \(x, ...) proportion_ci_wald(x, conf.level = conf.level, correct = FALSE), | ||
"wilsoncc" = \(x, ...) proportion_ci_wilson(x, conf.level = conf.level, correct = TRUE), | ||
"wilson" = \(x, ...) proportion_ci_wilson(x, conf.level = conf.level, correct = FALSE), | ||
"clopper-pearson" = \(x, ...) proportion_ci_clopper_pearson(x, conf.level = conf.level), | ||
"agresti-coull" = \(x, ...) proportion_ci_agresti_coull(x, conf.level = conf.level), | ||
"jeffreys" = \(x, ...) proportion_ci_jeffreys(x, conf.level = conf.level), | ||
"strat_wilsoncc" = \(x, data, ...) { | ||
proportion_ci_strat_wilson(x, | ||
strata = data[[strata]], weights = weights, | ||
max.iterations = max.iterations, | ||
conf.level = conf.level, correct = TRUE | ||
) | ||
}, | ||
"strat_wilson" = \(x, data, ...) { | ||
proportion_ci_strat_wilson(x, | ||
strata = data[[strata]], weights = weights, | ||
max.iterations = max.iterations, | ||
conf.level = conf.level, correct = FALSE | ||
) | ||
} | ||
) | ||
) | ||
) |> | ||
dplyr::mutate( | ||
context = "proportion_ci" | ||
) | ||
} |
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.
What is determining whether or not any of these are "experimental" ?
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.
Haha, good question. I don't know! 🤷🏼 I think I marked it this way because I migrated these utilities from tern without full documentation of the methods, so wanted to hedge a bit.