Skip to content

Commit

Permalink
merge pr #322: v0.5.3 on CRAN!
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch authored Jul 15, 2020
2 parents 4d05233 + dfaa72c commit 5b57562
Show file tree
Hide file tree
Showing 74 changed files with 6,690 additions and 5,191 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check-standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: '3.6'}
- {os: macOS-latest, r: '3.6'}
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: macOS-latest, r: 'devel'}
- {os: ubuntu-16.04, r: '3.6', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: 'release', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
Expand Down
141 changes: 122 additions & 19 deletions CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,128 @@
# Contributor Code of Conduct
# Contributor Covenant Code of Conduct

As contributors and maintainers of this project, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating documentation,
submitting pull requests or patches, and other activities.
## Our Pledge

We are committed to making participation in this project a harassment-free experience for
everyone, regardless of level of experience, gender, gender identity and expression,
sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

Examples of unacceptable behavior by participants include the use of sexual language or
imagery, derogatory comments or personal attacks, trolling, public or private harassment,
insults, or other unprofessional conduct.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

Project maintainers have the right and responsibility to remove, edit, or reject comments,
commits, code, wiki edits, issues, and other contributions that are not aligned to this
Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
from the project team.
## Our Standards

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
opening an issue or contacting one or more of the project maintainers.
Examples of behavior that contributes to a positive environment for our
community include:

This Code of Conduct is adapted from the Contributor Covenant
(http://contributor-covenant.org), version 1.0.0, available at
http://contributor-covenant.org/version/1/0/0/.
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards
of acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies
when an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement listed as package
authors. All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of
actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the
community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0,
available at https://www.contributor-covenant.org/version/2/0/
code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at https://
www.contributor-covenant.org/translations.
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: infer
Type: Package
Title: Tidy Statistical Inference
Version: 0.5.2
Version: 0.5.3
Authors@R: c(
person("Andrew", "Bray", email = "[email protected]", role = c("aut", "cre")),
person("Chester", "Ismay", email = "[email protected]", role = "aut"),
Expand Down Expand Up @@ -32,7 +32,7 @@ Imports:
grDevices,
purrr
Depends:
R (>= 3.1.2)
R (>= 3.5.0)
Suggests:
broom,
devtools (>= 1.12.0),
Expand All @@ -43,10 +43,11 @@ Suggests:
stringr,
testthat,
covr,
vdiffr
vdiffr,
fs
URL: https://github.com/tidymodels/infer,
https://infer.netlify.com/
BugReports: https://github.com/tidymodels/infer/issues
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.0.9000
RoxygenNote: 7.1.1
VignetteBuilder: knitr
17 changes: 17 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# infer 0.5.3

## Breaking changes

- `get_confidence_interval()` now uses column names ('lower_ci' and 'upper_ci')
in output that are consistent with other infer functionality (#317).

## New functionality

- `get_confidence_interval()` can now produce bias-corrected confidence intervals
by setting `type = "bias-corrected"`. Thanks to @davidbaniadam for the
initial implementation (#237, #318)!

## Other

- Fix CRAN check failures related to long double errors.

# infer 0.5.2

- Warn the user when a p-value of 0 is reported (#257, #273)
Expand Down
115 changes: 75 additions & 40 deletions R/get_confidence_interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
#' Default value is 0.95.
#' @param type A string giving which method should be used for creating the
#' confidence interval. The default is `"percentile"` with `"se"`
#' corresponding to (multiplier * standard error) as the other option.
#' corresponding to (multiplier * standard error) and `"bias-corrected"` for
#' bias-corrected interval as other options.
#' @param point_estimate A numeric value or a 1x1 data frame set to `NULL` by
#' default. Needed to be provided if `type = "se"`.
#' default. Needed to be provided if `type` is `"se"` or `"bias-corrected"`.
#'
#' @return A 1 x 2 tibble with 'lower_ci' and 'upper_ci' columns. Values
#' correspond to lower and upper bounds of the confidence interval.
#'
#' @return A 1 x 2 tibble with values corresponding to lower and upper values in
#' the confidence interval.
#' @section Aliases:
#' `get_ci()` is an alias of `get_confidence_interval()`.
#' `conf_int()` is a deprecated alias of `get_confidence_interval()`.
Expand All @@ -43,11 +45,13 @@
#' # finding the null distribution
#' calculate(stat = "mean") %>%
# # calculate the confidence interval around the point estimate
#' get_confidence_interval(point_estimate = point_estimate,
#' # at the 95% confidence level
#' level = .95,
#' # using the standard error method
#' type = "se")
#' get_confidence_interval(
#' point_estimate = point_estimate,
#' # at the 95% confidence level
#' level = 0.95,
#' # using the standard error method
#' type = "se"
#' )
#'
#' # More in-depth explanation of how to use the infer package
#' \dontrun{
Expand All @@ -57,59 +61,90 @@
#' @name get_confidence_interval
#' @export
get_confidence_interval <- function(x, level = 0.95, type = "percentile",
point_estimate = NULL){

point_estimate = NULL) {
check_ci_args(x, level, type, point_estimate)

if(type == "percentile") {
ci_vec <- stats::quantile(x[["stat"]],
probs = c((1 - level) / 2, level + (1 - level) / 2))

ci <- tibble::tibble(ci_vec[1], ci_vec[2])
names(ci) <- names(ci_vec)
} else {
point_estimate <- check_obs_stat(point_estimate)
multiplier <- stats::qnorm(1 - (1 - level) / 2)
ci <- tibble::tibble(
lower = point_estimate - multiplier * stats::sd(x[["stat"]]),
upper = point_estimate + multiplier * stats::sd(x[["stat"]]))

# Inform if no `level` was explicitly supplied
if (!("level" %in% rlang::call_args_names(match.call()))) {
message_glue("Using `level = {level}` to compute confidence interval.")
}

return(ci)

switch(
type,
percentile = ci_percentile(x, level),
se = ci_se(x, level, point_estimate),
`bias-corrected` = ci_bias_corrected(x, level, point_estimate)
)
}

#' @rdname get_confidence_interval
#' @export
get_ci <- function(x, level = 0.95, type = "percentile",
point_estimate = NULL) {
point_estimate = NULL) {
get_confidence_interval(
x, level = level, type = type, point_estimate = point_estimate
)
}

check_ci_args <- function(x, level, type, point_estimate){
ci_percentile <- function(x, level) {
ci_vec <- stats::quantile(x[["stat"]], probs = (1 + c(-level, level)) / 2)

make_ci_df(ci_vec)
}

if(!is.null(point_estimate)){
if(!is.data.frame(point_estimate))
ci_se <- function(x, level, point_estimate) {
point_estimate <- check_obs_stat(point_estimate)

multiplier <- stats::qnorm((1 + level) / 2)
ci_vec <- point_estimate + c(-multiplier, multiplier) * stats::sd(x[["stat"]])

make_ci_df(ci_vec)
}

ci_bias_corrected <- function(x, level, point_estimate) {
point_estimate <- check_obs_stat(point_estimate)

p <- mean(x[["stat"]] <= point_estimate)
z0 <- stats::qnorm(p)
# z_alpha_2 is z_(alpha/2)
z_alpha_2 <- stats::qnorm((1 + c(-level, level)) / 2)
new_probs <- stats::pnorm(2*z0 + z_alpha_2)

ci_vec <- stats::quantile(x[["stat"]], probs = new_probs)

make_ci_df(ci_vec)
}

check_ci_args <- function(x, level, type, point_estimate){
if (!is.null(point_estimate)) {
if (!is.data.frame(point_estimate)) {
check_type(point_estimate, is.numeric)
else
} else {
check_type(point_estimate, is.data.frame)
check_type(point_estimate[[1]][[1]], is.numeric)
}
}
check_type(x, is.data.frame)
check_type(level, is.numeric)
if(level <= 0 || level >= 1){

if ((level <= 0) || (level >= 1)) {
stop_glue("The value of `level` must be between 0 and 1 non-inclusive.")
}

if(!(type %in% c("percentile", "se"))){
stop_glue('The options for `type` are "percentile" or "se".')
if (!(type %in% c("percentile", "se", "bias-corrected"))) {
stop_glue(
'The options for `type` are "percentile", "se", or "bias-corrected".'
)
}

if(type == "se" && is.null(point_estimate))
stop_glue('A numeric value needs to be given for `point_estimate` ',
'for `type = "se"')

if(type == "se" && is.vector(point_estimate))
check_type(point_estimate, is.numeric)
if ((type %in% c("se", "bias-corrected")) && is.null(point_estimate)) {
stop_glue(
'A numeric value needs to be given for `point_estimate` ',
'for `type` "se" or "bias-corrected".'
)
}
}

make_ci_df <- function(ci_vec) {
tibble::tibble(lower_ci = ci_vec[[1]], upper_ci = ci_vec[[2]])
}
3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ sanitize_hypothesis_params_point <- function(dots, x) {
}

sanitize_hypothesis_params_proportion <- function(p, x) {
eps <- if (capabilities("long.double")) {sqrt(.Machine$double.eps)} else {0.01}
if(anyNA(p)) {
stop_glue('`p` should not contain missing values.')
}
Expand All @@ -359,7 +360,7 @@ sanitize_hypothesis_params_proportion <- function(p, x) {
p <- c(p, 1 - p)
names(p) <- get_success_then_response_levels(x)
} else {
if (sum(p) != 1) {
if (sum(p) < 1 - eps | sum(p) > 1 + eps) {
stop_glue(
"Make sure the hypothesized values for the `p` parameters sum to 1. ",
"Please try again."
Expand Down
Loading

0 comments on commit 5b57562

Please sign in to comment.