Skip to content

Commit b776e76

Browse files
author
Chester Ismay
authored
Merge branch 'develop' into master
2 parents 405458b + 5bdf656 commit b776e76

Some content is hidden

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

65 files changed

+930
-816
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ deploy:
3333
keep-history: true
3434
local-dir: docs
3535
github_token: $GITHUBTRAVIS
36+
target-branch: gh-pages-dev
37+
# target-branch: gh-pages
3638
on:
37-
branch: master
39+
branch: develop
40+
# branch: master
3841

3942
after_success:
4043
- Rscript -e 'covr::codecov()'

DESCRIPTION

Lines changed: 3 additions & 2 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.3.1
4+
Version: 0.3.1.9000
55
Authors@R: c(
66
person("Andrew", "Bray", email = "[email protected]", role = c("aut", "cre")),
77
person("Chester", "Ismay", email = "[email protected]", role = "aut"),
@@ -40,5 +40,6 @@ Suggests:
4040
covr
4141
URL: https://github.com/tidymodels/infer
4242
BugReports: https://github.com/tidymodels/infer/issues
43-
RoxygenNote: 6.0.1.9000
43+
Roxygen: list(markdown = TRUE)
44+
RoxygenNote: 6.1.0
4445
VignetteBuilder: knitr

NAMESPACE

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ export(specify)
1717
export(t_stat)
1818
export(t_test)
1919
export(visualize)
20-
importFrom(dplyr,as.tbl)
21-
importFrom(dplyr,as_tibble)
2220
importFrom(dplyr,bind_rows)
23-
importFrom(dplyr,data_frame)
2421
importFrom(dplyr,group_by)
2522
importFrom(dplyr,inner_join)
2623
importFrom(dplyr,mutate_if)

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# infer 0.3.1.9000
2+
3+
- Account for `NULL` value in left hand side of formula in `specify()` (#156) and `type` in `generate()` (#157).
4+
- Update documentation code to follow tidyverse style guide (#159).
5+
- Remove help page for internal `set_params()` (#165).
6+
- Fully use {tibble} (#166).
7+
18
# infer 0.3.1
29

310
- Stop using package {assertive} in favor of custom type checks (#149)

R/calculate.R

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
#' Calculate summary statistics
2-
#' @param x the output from \code{\link{generate}} for computation-based
3-
#' inference or the output from \code{\link{hypothesize}}
4-
#' piped in to here for theory-based inference.
5-
#' @param stat a string giving the type of the statistic to calculate. Current
6-
#' options include "mean", "median", "sd", "prop", "diff in means",
7-
#' "diff in medians", "diff in props", "Chisq", "F", "t", "z", "slope",
8-
#' and "correlation".
9-
#' @param order a string vector of specifying the order in which the levels of
10-
#' the explanatory variable should be ordered for subtraction, where
11-
#' \code{order = c("first", "second")} means \code{("first" - "second")}
12-
#' Needed for inference on difference in means, medians, or proportions and
13-
#' t and z statistics.
14-
#' @param ... to pass options like \code{na.rm = TRUE} into functions like
15-
#'mean, sd, etc.
16-
#' @return A tibble containing a \code{stat} column of calculated statistics
2+
#'
3+
#' @param x The output from [generate()] for computation-based inference or the
4+
#' output from [hypothesize()] piped in to here for theory-based inference.
5+
#' @param stat A string giving the type of the statistic to calculate. Current
6+
#' options include `"mean"`, `"median"`, `"sd"`, `"prop"`, `"diff in means"`,
7+
#' `"diff in medians"`, `"diff in props"`, `"Chisq"`, `"F"`, `"t"`, `"z"`,
8+
#' `"slope"`, and `"correlation"`.
9+
#' @param order A string vector of specifying the order in which the levels of
10+
#' the explanatory variable should be ordered for subtraction, where `order =
11+
#' c("first", "second")` means `("first" - "second")` Needed for inference on
12+
#' difference in means, medians, or proportions and t and z statistics.
13+
#' @param ... To pass options like `na.rm = TRUE` into functions like
14+
#' [mean()][base::mean()], [sd()][stats::sd()], etc.
15+
#'
16+
#' @return A tibble containing a `stat` column of calculated statistics.
17+
#'
18+
#' @examples
19+
#' # Permutation test for two binary variables
20+
#' mtcars %>%
21+
#' dplyr::mutate(am = factor(am), vs = factor(vs)) %>%
22+
#' specify(am ~ vs, success = "1") %>%
23+
#' hypothesize(null = "independence") %>%
24+
#' generate(reps = 100, type = "permute") %>%
25+
#' calculate(stat = "diff in props", order = c("1", "0"))
26+
#'
1727
#' @importFrom dplyr group_by summarize n
1828
#' @importFrom rlang !! sym quo enquo eval_tidy
1929
#' @export
20-
#' @examples
21-
#' # Permutation test for two binary variables
22-
#' mtcars %>%
23-
#' dplyr::mutate(am = factor(am), vs = factor(vs)) %>%
24-
#' specify(am ~ vs, success = "1") %>%
25-
#' hypothesize(null = "independence") %>%
26-
#' generate(reps = 100, type = "permute") %>%
27-
#' calculate(stat = "diff in props", order = c("1", "0"))
28-
2930
calculate <- function(x,
3031
stat = c(
3132
"mean",

R/conf_int.R

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
1-
#' Compute the confidence interval for (currently only) simulation-based methods
1+
#' Compute confidence interval
22
#'
3-
#' \code{get_confidence_interval()} and \code{get_ci()} are both aliases of \code{conf_int()}
4-
#' @param x data frame of calculated statistics or containing attributes
5-
#' of theoretical distribution values. Currently, dependent on statistics being stored in \code{stat} column as created in \code{calculate()} function.
6-
#' @param level a numerical value between 0 and 1 giving the confidence level. Default value is 0.95.
7-
#' @param type a string giving which method should be used for creating the confidence interval. The default is \code{"percentile"} with \code{"se"} corresponding to (multiplier * standard error) as the other option.
8-
#' @param point_estimate a numeric value or a 1x1 data frame set to NULL by default. Needed to be provided if \code{type = "se"}.
3+
#' Only simulation-based methods are (currently only) supported.
4+
#' `get_confidence_interval()` and `get_ci()` are both aliases of `conf_int()`.
5+
#'
6+
#' @param x Data frame of calculated statistics or containing attributes of
7+
#' theoretical distribution values. Currently, dependent on statistics being
8+
#' stored in `stat` column as created in [calculate()] function.
9+
#' @param level A numerical value between 0 and 1 giving the confidence level.
10+
#' Default value is 0.95.
11+
#' @param type A string giving which method should be used for creating the
12+
#' confidence interval. The default is `"percentile"` with `"se"`
13+
#' corresponding to (multiplier * standard error) as the other option.
14+
#' @param point_estimate A numeric value or a 1x1 data frame set to `NULL` by
15+
#' default. Needed to be provided if `type = "se"`.
916
#'
10-
#' @return a 2 x 1 tibble with values corresponding to lower and upper values in the confidence interval
11-
#' @export
12-
#' @rdname get_ci
17+
#' @return A 1 x 2 tibble with values corresponding to lower and upper values in
18+
#' the confidence interval.
19+
#'
1320
#' @examples
1421
#' mtcars_df <- mtcars %>%
15-
#' dplyr::mutate(am = factor(am))
22+
#' dplyr::mutate(am = factor(am))
1623
#' d_hat <- mtcars_df %>%
17-
#' specify(mpg ~ am) %>%
18-
#' calculate(stat = "diff in means", order = c("1", "0"))
24+
#' specify(mpg ~ am) %>%
25+
#' calculate(stat = "diff in means", order = c("1", "0"))
1926
#' bootstrap_distn <- mtcars_df %>%
20-
#' specify(mpg ~ am) %>%
21-
#' generate(reps = 100) %>%
22-
#' calculate(stat = "diff in means", order = c("1", "0"))
27+
#' specify(mpg ~ am) %>%
28+
#' generate(reps = 100) %>%
29+
#' calculate(stat = "diff in means", order = c("1", "0"))
2330
#' bootstrap_distn %>% conf_int(level = 0.9)
2431
#' bootstrap_distn %>% conf_int(type = "se", point_estimate = d_hat)
32+
#'
33+
#' @name get_ci
34+
NULL
2535

36+
#' @rdname get_ci
37+
#' @export
2638
conf_int <- function(x, level = 0.95, type = "percentile",
2739
point_estimate = NULL){
2840

@@ -72,12 +84,10 @@ check_ci_args <- function(x, level, type, point_estimate){
7284
}
7385

7486

75-
#' @export
7687
#' @rdname get_ci
77-
88+
#' @export
7889
get_ci <- conf_int
7990

80-
#' @export
8191
#' @rdname get_ci
82-
92+
#' @export
8393
get_confidence_interval <- conf_int

R/generate.R

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
1-
#' Generate resamples, permutations, or simulations based on
2-
#' `specify` and (if needed) `hypothesize` inputs
3-
#' @param x a data frame that can be coerced into a \code{\link[dplyr]{tbl_df}}
4-
#' @param reps the number of resamples to generate
5-
#' @param type currently either \code{bootstrap}, \code{permute},
6-
#' or \code{simulate}
7-
#' @param ... currently ignored
8-
#' @return A tibble containing \code{rep} generated datasets, indicated by the
9-
#' \code{replicate} column.
10-
#' @importFrom dplyr group_by
11-
#' @export
1+
#' Generate resamples, permutations, or simulations
2+
#'
3+
#' Generation is done based on [specify()] and (if needed) [hypothesize()]
4+
#' inputs.
5+
#'
6+
#' @param x A data frame that can be coerced into a [tibble][tibble::tibble].
7+
#' @param reps The number of resamples to generate.
8+
#' @param type Currently either `bootstrap`, `permute`, or `simulate`.
9+
#' @param ... Currently ignored.
10+
#'
11+
#' @return A tibble containing `rep` generated datasets, indicated by the
12+
#' `replicate` column.
13+
#'
1214
#' @examples
1315
#' # Permutation test for two binary variables
14-
#' mtcars %>%
15-
#' dplyr::mutate(am = factor(am), vs = factor(vs)) %>%
16-
#' specify(am ~ vs, success = "1") %>%
17-
#' hypothesize(null = "independence") %>%
18-
#' generate(reps = 100, type = "permute")
19-
16+
#' mtcars %>%
17+
#' dplyr::mutate(am = factor(am), vs = factor(vs)) %>%
18+
#' specify(am ~ vs, success = "1") %>%
19+
#' hypothesize(null = "independence") %>%
20+
#' generate(reps = 100, type = "permute")
21+
#'
22+
#' @importFrom dplyr group_by
23+
#' @export
2024
generate <- function(x, reps = 1, type = attr(x, "type"), ...) {
2125

2226
auto_type <- attr(x, "type")
2327

2428
if(!is.null(auto_type)){
29+
if (is.null(type)) {
30+
stop_glue("Supply not `NULL` value of `type`.")
31+
}
32+
2533
if(auto_type != type)
2634
stop_glue(
2735
"You have specified `type = \"{type}\"`, but `type` is expected to be ",
@@ -148,7 +156,6 @@ permute_once <- function(x, ...) {
148156
#' @importFrom dplyr pull
149157
#' @importFrom tibble tibble
150158
#' @importFrom rlang :=
151-
152159
simulate <- function(x, reps = 1, ...) {
153160
fct_levels <- as.character(unique(dplyr::pull(x, !! attr(x, "response"))))
154161

@@ -158,8 +165,10 @@ simulate <- function(x, reps = 1, ...) {
158165
prob = format_params(x)),
159166
simplify = FALSE))
160167

161-
rep_tbl <- tibble(!! attr(x, "response") := as.factor(col_simmed),
162-
replicate = as.factor(rep(1:reps, rep(nrow(x), reps))))
168+
rep_tbl <- tibble::tibble(
169+
!! attr(x, "response") := as.factor(col_simmed),
170+
replicate = as.factor(rep(1:reps, rep(nrow(x), reps)))
171+
)
163172

164173
rep_tbl <- set_attributes(to = rep_tbl, from = x)
165174

R/hypothesize.R

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
#' Declare a null hypothesis
2-
#' @param x a data frame that can be coerced into a \code{\link[dplyr]{tbl_df}}
3-
#' @param null the null hypothesis. Options include "independence" and "point"
4-
#' @param ... arguments passed to downstream functions
5-
#' @return A tibble containing the response (and explanatory, if specified)
6-
#' variable data with parameter information stored as well
7-
#' @importFrom dplyr as.tbl
8-
#' @return a data frame with attributes set
9-
#' @export
2+
#'
3+
#' @param x A data frame that can be coerced into a [tibble][tibble::tibble].
4+
#' @param null The null hypothesis. Options include `"independence"` and
5+
#' `"point"`.
6+
#' @param ... Arguments passed to downstream functions.
7+
#'
8+
#' @return A tibble containing the response (and explanatory, if specified)
9+
#' variable data with parameter information stored as well.
10+
#'
1011
#' @examples
1112
#' # Permutation test similar to ANOVA
12-
#' mtcars %>%
13-
#' dplyr::mutate(cyl = factor(cyl)) %>%
14-
#' specify(mpg ~ cyl) %>%
15-
#' hypothesize(null = "independence") %>%
16-
#' generate(reps = 100, type = "permute") %>%
17-
#' calculate(stat = "F")
18-
13+
#' mtcars %>%
14+
#' dplyr::mutate(cyl = factor(cyl)) %>%
15+
#' specify(mpg ~ cyl) %>%
16+
#' hypothesize(null = "independence") %>%
17+
#' generate(reps = 100, type = "permute") %>%
18+
#' calculate(stat = "F")
19+
#'
20+
#' @export
1921
hypothesize <- function(x, null, ...) {
2022

2123
hypothesize_checks(x, null)
@@ -69,6 +71,6 @@ hypothesize <- function(x, null, ...) {
6971
# '`mu`, `med`, or `sd` to be used as a parameter.')
7072
# }
7173

72-
return(as.tbl(x))
74+
return(tibble::as_tibble(x))
7375
}
7476

R/infer.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#' infer: a grammar for statistical inference
22
#'
3-
#' The objective of this package is to perform statistical inference
4-
#' using a grammar that illustrates the underlying
5-
#' concepts and a format that coheres with the tidyverse.
3+
#' The objective of this package is to perform statistical inference using a
4+
#' grammar that illustrates the underlying concepts and a format that coheres
5+
#' with the tidyverse.
66
#'
7-
#' @docType package
8-
#' @name infer
97
#' @examples
108
#' # Example usage:
119
#' library(infer)
10+
#'
11+
#' @docType package
12+
#' @name infer
1213
NULL
1314

1415
## quiets concerns of R CMD check re: the .'s that appear in pipelines

R/p_value.R

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
1-
#' Compute the p-value for (currently only) simulation-based methods
2-
#' \code{get_pvalue()} is an alias of \code{p_value}
3-
#' @param x data frame of calculated statistics or containing attributes
4-
#' of theoretical distribution values
5-
#' @param obs_stat a numeric value or a 1x1 data frame (as extreme or more extreme than this)
6-
#' @param direction a character string. Options are "less", "greater", or "two_sided".
7-
#' Can also specify "left", "right", or "both".
1+
#' Compute p-value
2+
#'
3+
#' Only simulation-based methods are (currently only) supported. `get_pvalue()`
4+
#' is an alias of `p_value`.
5+
#'
6+
#' @param x Data frame of calculated statistics or containing attributes of
7+
#' theoretical distribution values.
8+
#' @param obs_stat A numeric value or a 1x1 data frame (as extreme or more
9+
#' extreme than this).
10+
#' @param direction A character string. Options are `"less"`, `"greater"`, or
11+
#' `"two_sided"`. Can also specify `"left"`, `"right"`, or `"both"`.
812
#'
9-
#' @return a 1x1 data frame with value between 0 and 1
10-
#' @export
11-
#' @rdname get_pvalue
13+
#' @return A 1x1 data frame with value between 0 and 1.
14+
#'
1215
#' @examples
1316
#' mtcars_df <- mtcars %>%
14-
#' dplyr::mutate(am = factor(am))
17+
#' dplyr::mutate(am = factor(am))
1518
#' d_hat <- mtcars_df %>%
16-
#' specify(mpg ~ am) %>%
17-
#' calculate(stat = "diff in means", order = c("1", "0"))
19+
#' specify(mpg ~ am) %>%
20+
#' calculate(stat = "diff in means", order = c("1", "0"))
1821
#' null_distn <- mtcars_df %>%
19-
#' specify(mpg ~ am) %>%
20-
#' hypothesize(null = "independence") %>%
21-
#' generate(reps = 100) %>%
22-
#' calculate(stat = "diff in means", order = c("1", "0"))
22+
#' specify(mpg ~ am) %>%
23+
#' hypothesize(null = "independence") %>%
24+
#' generate(reps = 100) %>%
25+
#' calculate(stat = "diff in means", order = c("1", "0"))
2326
#' null_distn %>%
24-
#' p_value(obs_stat = d_hat, direction = "right")
27+
#' p_value(obs_stat = d_hat, direction = "right")
28+
#'
29+
#' @name get_pvalue
30+
NULL
2531

32+
#' @rdname get_pvalue
33+
#' @export
2634
p_value <- function(x, obs_stat, direction){
2735

2836
check_type(x, is.data.frame)
@@ -91,8 +99,8 @@ two_sided_p_value <- function(x, obs_stat){
9199
return(tibble::tibble(p_value = basic_p_value))
92100
}
93101

94-
#' @export
95102
#' @rdname get_pvalue
103+
#' @export
96104
get_pvalue <- p_value
97105

98106
# which_distribution <- function(x, theory_type, obs_stat, direction){

0 commit comments

Comments
 (0)