Skip to content

Commit 5b57562

Browse files
authored
merge pr #322: v0.5.3 on CRAN!
2 parents 4d05233 + dfaa72c commit 5b57562

File tree

74 files changed

+6690
-5191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+6690
-5191
lines changed

.github/workflows/check-standard.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
config:
23-
- {os: windows-latest, r: '3.6'}
24-
- {os: macOS-latest, r: '3.6'}
23+
- {os: windows-latest, r: 'release'}
24+
- {os: macOS-latest, r: 'release'}
2525
- {os: macOS-latest, r: 'devel'}
26-
- {os: ubuntu-16.04, r: '3.6', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
26+
- {os: ubuntu-16.04, r: 'release', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
2727

2828
env:
2929
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true

CONDUCT.md

Lines changed: 122 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,128 @@
1-
# Contributor Code of Conduct
1+
# Contributor Covenant Code of Conduct
22

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

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

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

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

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

23-
This Code of Conduct is adapted from the Contributor Covenant
24-
(http://contributor-covenant.org), version 1.0.0, available at
25-
http://contributor-covenant.org/version/1/0/0/.
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the overall
26+
community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or
31+
advances of any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email
35+
address, without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards
42+
of acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject
47+
comments, commits, code, wiki edits, issues, and other contributions that are
48+
not aligned to this Code of Conduct, and will communicate reasons for moderation
49+
decisions when appropriate.
50+
51+
## Scope
52+
53+
This Code of Conduct applies within all community spaces, and also applies
54+
when an individual is officially representing the community in public spaces.
55+
Examples of representing our community include using an official e-mail
56+
address, posting via an official social media account, or acting as an appointed
57+
representative at an online or offline event.
58+
59+
## Enforcement
60+
61+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62+
reported to the community leaders responsible for enforcement listed as package
63+
authors. All complaints will be reviewed and investigated promptly and fairly.
64+
65+
All community leaders are obligated to respect the privacy and security of the
66+
reporter of any incident.
67+
68+
## Enforcement Guidelines
69+
70+
Community leaders will follow these Community Impact Guidelines in determining
71+
the consequences for any action they deem in violation of this Code of Conduct:
72+
73+
### 1. Correction
74+
75+
**Community Impact**: Use of inappropriate language or other behavior deemed
76+
unprofessional or unwelcome in the community.
77+
78+
**Consequence**: A private, written warning from community leaders, providing
79+
clarity around the nature of the violation and an explanation of why the
80+
behavior was inappropriate. A public apology may be requested.
81+
82+
### 2. Warning
83+
84+
**Community Impact**: A violation through a single incident or series of
85+
actions.
86+
87+
**Consequence**: A warning with consequences for continued behavior. No
88+
interaction with the people involved, including unsolicited interaction with
89+
those enforcing the Code of Conduct, for a specified period of time. This
90+
includes avoiding interactions in community spaces as well as external channels
91+
like social media. Violating these terms may lead to a temporary or permanent
92+
ban.
93+
94+
### 3. Temporary Ban
95+
96+
**Community Impact**: A serious violation of community standards, including
97+
sustained inappropriate behavior.
98+
99+
**Consequence**: A temporary ban from any sort of interaction or public
100+
communication with the community for a specified period of time. No public or
101+
private interaction with the people involved, including unsolicited interaction
102+
with those enforcing the Code of Conduct, is allowed during this period.
103+
Violating these terms may lead to a permanent ban.
104+
105+
### 4. Permanent Ban
106+
107+
**Community Impact**: Demonstrating a pattern of violation of community
108+
standards, including sustained inappropriate behavior, harassment of an
109+
individual, or aggression toward or disparagement of classes of individuals.
110+
111+
**Consequence**: A permanent ban from any sort of public interaction within the
112+
community.
113+
114+
## Attribution
115+
116+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
117+
version 2.0,
118+
available at https://www.contributor-covenant.org/version/2/0/
119+
code_of_conduct.html.
120+
121+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
122+
enforcement ladder](https://github.com/mozilla/diversity).
123+
124+
[homepage]: https://www.contributor-covenant.org
125+
126+
For answers to common questions about this code of conduct, see the FAQ at
127+
https://www.contributor-covenant.org/faq. Translations are available at https://
128+
www.contributor-covenant.org/translations.

DESCRIPTION

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: infer
22
Type: Package
33
Title: Tidy Statistical Inference
4-
Version: 0.5.2
4+
Version: 0.5.3
55
Authors@R: c(
66
person("Andrew", "Bray", email = "[email protected]", role = c("aut", "cre")),
77
person("Chester", "Ismay", email = "[email protected]", role = "aut"),
@@ -32,7 +32,7 @@ Imports:
3232
grDevices,
3333
purrr
3434
Depends:
35-
R (>= 3.1.2)
35+
R (>= 3.5.0)
3636
Suggests:
3737
broom,
3838
devtools (>= 1.12.0),
@@ -43,10 +43,11 @@ Suggests:
4343
stringr,
4444
testthat,
4545
covr,
46-
vdiffr
46+
vdiffr,
47+
fs
4748
URL: https://github.com/tidymodels/infer,
4849
https://infer.netlify.com/
4950
BugReports: https://github.com/tidymodels/infer/issues
5051
Roxygen: list(markdown = TRUE)
51-
RoxygenNote: 7.1.0.9000
52+
RoxygenNote: 7.1.1
5253
VignetteBuilder: knitr

NEWS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# infer 0.5.3
2+
3+
## Breaking changes
4+
5+
- `get_confidence_interval()` now uses column names ('lower_ci' and 'upper_ci')
6+
in output that are consistent with other infer functionality (#317).
7+
8+
## New functionality
9+
10+
- `get_confidence_interval()` can now produce bias-corrected confidence intervals
11+
by setting `type = "bias-corrected"`. Thanks to @davidbaniadam for the
12+
initial implementation (#237, #318)!
13+
14+
## Other
15+
16+
- Fix CRAN check failures related to long double errors.
17+
118
# infer 0.5.2
219

320
- Warn the user when a p-value of 0 is reported (#257, #273)

R/get_confidence_interval.R

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
#' Default value is 0.95.
1515
#' @param type A string giving which method should be used for creating the
1616
#' confidence interval. The default is `"percentile"` with `"se"`
17-
#' corresponding to (multiplier * standard error) as the other option.
17+
#' corresponding to (multiplier * standard error) and `"bias-corrected"` for
18+
#' bias-corrected interval as other options.
1819
#' @param point_estimate A numeric value or a 1x1 data frame set to `NULL` by
19-
#' default. Needed to be provided if `type = "se"`.
20+
#' default. Needed to be provided if `type` is `"se"` or `"bias-corrected"`.
21+
#'
22+
#' @return A 1 x 2 tibble with 'lower_ci' and 'upper_ci' columns. Values
23+
#' correspond to lower and upper bounds of the confidence interval.
2024
#'
21-
#' @return A 1 x 2 tibble with values corresponding to lower and upper values in
22-
#' the confidence interval.
2325
#' @section Aliases:
2426
#' `get_ci()` is an alias of `get_confidence_interval()`.
2527
#' `conf_int()` is a deprecated alias of `get_confidence_interval()`.
@@ -43,11 +45,13 @@
4345
#' # finding the null distribution
4446
#' calculate(stat = "mean") %>%
4547
# # calculate the confidence interval around the point estimate
46-
#' get_confidence_interval(point_estimate = point_estimate,
47-
#' # at the 95% confidence level
48-
#' level = .95,
49-
#' # using the standard error method
50-
#' type = "se")
48+
#' get_confidence_interval(
49+
#' point_estimate = point_estimate,
50+
#' # at the 95% confidence level
51+
#' level = 0.95,
52+
#' # using the standard error method
53+
#' type = "se"
54+
#' )
5155
#'
5256
#' # More in-depth explanation of how to use the infer package
5357
#' \dontrun{
@@ -57,59 +61,90 @@
5761
#' @name get_confidence_interval
5862
#' @export
5963
get_confidence_interval <- function(x, level = 0.95, type = "percentile",
60-
point_estimate = NULL){
61-
64+
point_estimate = NULL) {
6265
check_ci_args(x, level, type, point_estimate)
63-
64-
if(type == "percentile") {
65-
ci_vec <- stats::quantile(x[["stat"]],
66-
probs = c((1 - level) / 2, level + (1 - level) / 2))
67-
68-
ci <- tibble::tibble(ci_vec[1], ci_vec[2])
69-
names(ci) <- names(ci_vec)
70-
} else {
71-
point_estimate <- check_obs_stat(point_estimate)
72-
multiplier <- stats::qnorm(1 - (1 - level) / 2)
73-
ci <- tibble::tibble(
74-
lower = point_estimate - multiplier * stats::sd(x[["stat"]]),
75-
upper = point_estimate + multiplier * stats::sd(x[["stat"]]))
66+
67+
# Inform if no `level` was explicitly supplied
68+
if (!("level" %in% rlang::call_args_names(match.call()))) {
69+
message_glue("Using `level = {level}` to compute confidence interval.")
7670
}
77-
78-
return(ci)
71+
72+
switch(
73+
type,
74+
percentile = ci_percentile(x, level),
75+
se = ci_se(x, level, point_estimate),
76+
`bias-corrected` = ci_bias_corrected(x, level, point_estimate)
77+
)
7978
}
8079

8180
#' @rdname get_confidence_interval
8281
#' @export
8382
get_ci <- function(x, level = 0.95, type = "percentile",
84-
point_estimate = NULL) {
83+
point_estimate = NULL) {
8584
get_confidence_interval(
8685
x, level = level, type = type, point_estimate = point_estimate
8786
)
8887
}
8988

90-
check_ci_args <- function(x, level, type, point_estimate){
89+
ci_percentile <- function(x, level) {
90+
ci_vec <- stats::quantile(x[["stat"]], probs = (1 + c(-level, level)) / 2)
91+
92+
make_ci_df(ci_vec)
93+
}
9194

92-
if(!is.null(point_estimate)){
93-
if(!is.data.frame(point_estimate))
95+
ci_se <- function(x, level, point_estimate) {
96+
point_estimate <- check_obs_stat(point_estimate)
97+
98+
multiplier <- stats::qnorm((1 + level) / 2)
99+
ci_vec <- point_estimate + c(-multiplier, multiplier) * stats::sd(x[["stat"]])
100+
101+
make_ci_df(ci_vec)
102+
}
103+
104+
ci_bias_corrected <- function(x, level, point_estimate) {
105+
point_estimate <- check_obs_stat(point_estimate)
106+
107+
p <- mean(x[["stat"]] <= point_estimate)
108+
z0 <- stats::qnorm(p)
109+
# z_alpha_2 is z_(alpha/2)
110+
z_alpha_2 <- stats::qnorm((1 + c(-level, level)) / 2)
111+
new_probs <- stats::pnorm(2*z0 + z_alpha_2)
112+
113+
ci_vec <- stats::quantile(x[["stat"]], probs = new_probs)
114+
115+
make_ci_df(ci_vec)
116+
}
117+
118+
check_ci_args <- function(x, level, type, point_estimate){
119+
if (!is.null(point_estimate)) {
120+
if (!is.data.frame(point_estimate)) {
94121
check_type(point_estimate, is.numeric)
95-
else
122+
} else {
96123
check_type(point_estimate, is.data.frame)
124+
check_type(point_estimate[[1]][[1]], is.numeric)
125+
}
97126
}
98127
check_type(x, is.data.frame)
99128
check_type(level, is.numeric)
100-
if(level <= 0 || level >= 1){
129+
130+
if ((level <= 0) || (level >= 1)) {
101131
stop_glue("The value of `level` must be between 0 and 1 non-inclusive.")
102132
}
103133

104-
if(!(type %in% c("percentile", "se"))){
105-
stop_glue('The options for `type` are "percentile" or "se".')
134+
if (!(type %in% c("percentile", "se", "bias-corrected"))) {
135+
stop_glue(
136+
'The options for `type` are "percentile", "se", or "bias-corrected".'
137+
)
106138
}
107139

108-
if(type == "se" && is.null(point_estimate))
109-
stop_glue('A numeric value needs to be given for `point_estimate` ',
110-
'for `type = "se"')
111-
112-
if(type == "se" && is.vector(point_estimate))
113-
check_type(point_estimate, is.numeric)
140+
if ((type %in% c("se", "bias-corrected")) && is.null(point_estimate)) {
141+
stop_glue(
142+
'A numeric value needs to be given for `point_estimate` ',
143+
'for `type` "se" or "bias-corrected".'
144+
)
145+
}
114146
}
115147

148+
make_ci_df <- function(ci_vec) {
149+
tibble::tibble(lower_ci = ci_vec[[1]], upper_ci = ci_vec[[2]])
150+
}

R/utils.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ sanitize_hypothesis_params_point <- function(dots, x) {
343343
}
344344

345345
sanitize_hypothesis_params_proportion <- function(p, x) {
346+
eps <- if (capabilities("long.double")) {sqrt(.Machine$double.eps)} else {0.01}
346347
if(anyNA(p)) {
347348
stop_glue('`p` should not contain missing values.')
348349
}
@@ -359,7 +360,7 @@ sanitize_hypothesis_params_proportion <- function(p, x) {
359360
p <- c(p, 1 - p)
360361
names(p) <- get_success_then_response_levels(x)
361362
} else {
362-
if (sum(p) != 1) {
363+
if (sum(p) < 1 - eps | sum(p) > 1 + eps) {
363364
stop_glue(
364365
"Make sure the hypothesized values for the `p` parameters sum to 1. ",
365366
"Please try again."

0 commit comments

Comments
 (0)