Skip to content

Commit b969b8e

Browse files
committed
use consistent end-of-line sequence
1 parent 755b2c6 commit b969b8e

35 files changed

+670
-671
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Type: Package
22
Package: infer
33
Title: Tidy Statistical Inference
44
Version: 1.0.4.9000
5-
Authors@R:c(
5+
Authors@R: c(
66
person("Andrew", "Bray", , "abray@reed.edu", role = "aut"),
77
person("Chester", "Ismay", , "chester.ismay@gmail.com", role = "aut",
88
comment = c(ORCID = "0000-0003-2820-2547")),
@@ -65,5 +65,5 @@ Config/Needs/website: tidyverse/tidytemplate
6565
Encoding: UTF-8
6666
LazyData: true
6767
Roxygen: list(markdown = TRUE)
68-
RoxygenNote: 7.2.1
68+
RoxygenNote: 7.2.3
6969
Config/testthat/edition: 3

R/assume.R

+85-85
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
11
#' Define a theoretical distribution
2-
#'
3-
#' @description
4-
#'
2+
#'
3+
#' @description
4+
#'
55
#' This function allows the user to define a null distribution based on
66
#' theoretical methods. In many infer pipelines, `assume()` can be
77
#' used in place of [generate()] and [calculate()] to create a null
8-
#' distribution. Rather than outputting a data frame containing a
9-
#' distribution of test statistics calculated from resamples of the observed
8+
#' distribution. Rather than outputting a data frame containing a
9+
#' distribution of test statistics calculated from resamples of the observed
1010
#' data, `assume()` outputs a more abstract type of object just containing
1111
#' the distributional details supplied in the `distribution` and `df` arguments.
1212
#' However, `assume()` output can be passed to [visualize()], [get_p_value()],
1313
#' and [get_confidence_interval()] in the same way that simulation-based
1414
#' distributions can.
15-
#'
15+
#'
1616
#' To define a theoretical null distribution (for use in hypothesis testing),
1717
#' be sure to provide a null hypothesis via [hypothesize()]. To define a
18-
#' theoretical sampling distribution (for use in confidence intervals),
18+
#' theoretical sampling distribution (for use in confidence intervals),
1919
#' provide the output of [specify()]. Sampling distributions (only
2020
#' implemented for `t` and `z`) lie on the scale of the data, and will be
2121
#' recentered and rescaled to match the corresponding `stat` given in
2222
#' [calculate()] to calculate the observed statistic.
23-
#'
23+
#'
2424
#' @param x The output of [specify()] or [hypothesize()], giving the
2525
#' observed data, variable(s) of interest, and (optionally) null hypothesis.
2626
#' @param distribution The distribution in question, as a string. One of
2727
#' `"F"`, `"Chisq"`, `"t"`, or `"z"`.
2828
#' @param df Optional. The degrees of freedom parameter(s) for the `distribution`
2929
#' supplied, as a numeric vector. For `distribution = "F"`, this should have
30-
#' length two (e.g. `c(10, 3)`). For `distribution = "Chisq"` or
31-
#' `distribution = "t"`, this should have length one. For
32-
#' `distribution = "z"`, this argument is not required. The package
33-
#' will supply a message if the supplied `df` argument is different from
30+
#' length two (e.g. `c(10, 3)`). For `distribution = "Chisq"` or
31+
#' `distribution = "t"`, this should have length one. For
32+
#' `distribution = "z"`, this argument is not required. The package
33+
#' will supply a message if the supplied `df` argument is different from
3434
#' recognized values. See the Details section below for more information.
3535
#' @param ... Currently ignored.
36-
#'
36+
#'
3737
#' @return An infer theoretical distribution that can be passed to helpers
38-
#' like [visualize()], [get_p_value()], and [get_confidence_interval()].
39-
#'
40-
#' @details
41-
#'
38+
#' like [visualize()], [get_p_value()], and [get_confidence_interval()].
39+
#'
40+
#' @details
41+
#'
4242
#' Note that the assumption being expressed here, for use in theory-based
43-
#' inference, only extends to _distributional_ assumptions: the null
44-
#' distribution in question and its parameters. Statistical inference with
45-
#' infer, whether carried out via simulation (i.e. based on pipelines
46-
#' using [generate()] and [calculate()]) or theory (i.e. with `assume()`),
43+
#' inference, only extends to _distributional_ assumptions: the null
44+
#' distribution in question and its parameters. Statistical inference with
45+
#' infer, whether carried out via simulation (i.e. based on pipelines
46+
#' using [generate()] and [calculate()]) or theory (i.e. with `assume()`),
4747
#' always involves the condition that observations are independent of
4848
#' each other.
49-
#'
50-
#' `infer` only supports theoretical tests on one or two means via the
49+
#'
50+
#' `infer` only supports theoretical tests on one or two means via the
5151
#' `t` distribution and one or two proportions via the `z`.
52-
#'
53-
#' For tests comparing two means, if `n1` is the group size for one level of
52+
#'
53+
#' For tests comparing two means, if `n1` is the group size for one level of
5454
#' the explanatory variable, and `n2` is that for the other level, `infer`
55-
#' will recognize the following degrees of freedom (`df`) arguments:
56-
#'
55+
#' will recognize the following degrees of freedom (`df`) arguments:
56+
#'
5757
#' * `min(n1 - 1, n2 - 1)`
5858
#' * `n1 + n2 - 2`
5959
#' * The `"parameter"` entry of the analogous `stats::t.test()` call
6060
#' * The `"parameter"` entry of the analogous `stats::t.test()` call with `var.equal = TRUE`
61-
#'
62-
#' By default, the package will use the `"parameter"` entry of the analogous
61+
#'
62+
#' By default, the package will use the `"parameter"` entry of the analogous
6363
#' `stats::t.test()` call with `var.equal = FALSE` (the default).
64-
#'
65-
#' @examples
64+
#'
65+
#' @examples
6666
#' # construct theoretical distributions ---------------------------------
67-
#'
67+
#'
6868
#' # F distribution
6969
#' # with the `partyid` explanatory variable
70-
#' gss %>%
71-
#' specify(age ~ partyid) %>%
70+
#' gss %>%
71+
#' specify(age ~ partyid) %>%
7272
#' assume(distribution = "F")
73-
#'
73+
#'
7474
#' # Chi-squared goodness of fit distribution
7575
#' # on the `finrela` variable
7676
#' gss %>%
@@ -83,68 +83,68 @@
8383
#' "far above average" = 1/6,
8484
#' "DK" = 1/6)) %>%
8585
#' assume("Chisq")
86-
#'
86+
#'
8787
#' # Chi-squared test of independence
8888
#' # on the `finrela` and `sex` variables
8989
#' gss %>%
9090
#' specify(formula = finrela ~ sex) %>%
9191
#' assume(distribution = "Chisq")
92-
#'
92+
#'
9393
#' # T distribution
94-
#' gss %>%
94+
#' gss %>%
9595
#' specify(age ~ college) %>%
9696
#' assume("t")
97-
#'
97+
#'
9898
#' # Z distribution
9999
#' gss %>%
100100
#' specify(response = sex, success = "female") %>%
101101
#' assume("z")
102-
#'
102+
#'
103103
#' \dontrun{
104104
#' # each of these distributions can be passed to infer helper
105105
#' # functions alongside observed statistics!
106-
#'
106+
#'
107107
#' # for example, a 1-sample t-test -------------------------------------
108-
#'
109-
#' # calculate the observed statistic
108+
#'
109+
#' # calculate the observed statistic
110110
#' obs_stat <- gss %>%
111111
#' specify(response = hours) %>%
112112
#' hypothesize(null = "point", mu = 40) %>%
113113
#' calculate(stat = "t")
114-
#'
114+
#'
115115
#' # construct a null distribution
116116
#' null_dist <- gss %>%
117117
#' specify(response = hours) %>%
118118
#' assume("t")
119-
#'
119+
#'
120120
#' # juxtapose them visually
121-
#' visualize(null_dist) +
121+
#' visualize(null_dist) +
122122
#' shade_p_value(obs_stat, direction = "both")
123-
#'
123+
#'
124124
#' # calculate a p-value
125125
#' get_p_value(null_dist, obs_stat, direction = "both")
126-
#'
126+
#'
127127
#' # or, an F test ------------------------------------------------------
128-
#'
129-
#' # calculate the observed statistic
130-
#' obs_stat <- gss %>%
128+
#'
129+
#' # calculate the observed statistic
130+
#' obs_stat <- gss %>%
131131
#' specify(age ~ partyid) %>%
132132
#' hypothesize(null = "independence") %>%
133133
#' calculate(stat = "F")
134-
#'
134+
#'
135135
#' # construct a null distribution
136-
#' null_dist <- gss %>%
136+
#' null_dist <- gss %>%
137137
#' specify(age ~ partyid) %>%
138138
#' assume(distribution = "F")
139-
#'
139+
#'
140140
#' # juxtapose them visually
141-
#' visualize(null_dist) +
141+
#' visualize(null_dist) +
142142
#' shade_p_value(obs_stat, direction = "both")
143-
#'
143+
#'
144144
#' # calculate a p-value
145145
#' get_p_value(null_dist, obs_stat, direction = "both")
146146
#' }
147-
#'
147+
#'
148148
#' @export
149149
assume <- function(x, distribution, df = NULL, ...) {
150150
if (!inherits(x, "infer")) {
@@ -153,11 +153,11 @@ assume <- function(x, distribution, df = NULL, ...) {
153153
"likely `specify()` or `hypothesize()`."
154154
)
155155
}
156-
156+
157157
# check that `distribution` aligns with what is expected from
158158
# `x` and that `distribution` and `df` are consistent with each other
159159
df <- check_distribution(x, distribution, df, ...)
160-
160+
161161
structure(
162162
glue_null(
163163
"{distribution_desc(distribution)} distribution{df_desc(df)}.",
@@ -184,19 +184,19 @@ assume <- function(x, distribution, df = NULL, ...) {
184184
# check that the distribution is well-specified
185185
check_distribution <- function(x, distribution, df, ...) {
186186
dist <- tolower(distribution)
187-
187+
188188
if (!dist %in% c("f", "chisq", "t", "z")) {
189189
stop_glue(
190190
'The distribution argument must be one of "Chisq", "F", "t", or "z".'
191191
)
192192
}
193-
193+
194194
if ((dist == "f" && attr(x, "theory_type") != "ANOVA") ||
195-
(dist == "chisq" && !attr(x, "theory_type") %in% c("Chi-square test of indep",
195+
(dist == "chisq" && !attr(x, "theory_type") %in% c("Chi-square test of indep",
196196
"Chi-square Goodness of Fit")) ||
197-
(dist == "t" && !attr(x, "theory_type") %in% c("One sample t",
197+
(dist == "t" && !attr(x, "theory_type") %in% c("One sample t",
198198
"Two sample t")) ||
199-
(dist == "z" && !attr(x, "theory_type") %in% c("One sample prop z",
199+
(dist == "z" && !attr(x, "theory_type") %in% c("One sample prop z",
200200
"Two sample props z"))) {
201201
if (has_explanatory(x)) {
202202
msg_tail <- glue_null(
@@ -206,33 +206,33 @@ check_distribution <- function(x, distribution, df, ...) {
206206
} else {
207207
msg_tail <- "no explanatory variable."
208208
}
209-
209+
210210
stop_glue(
211211
'The supplied distribution "{distribution}" is not well-defined for a ',
212212
"{get_stat_type_desc(attr(x, 'type_desc_response'))} response ",
213213
"variable ({response_name(x)}) and ", msg_tail
214214
)
215215
}
216-
216+
217217
if (!is.numeric(df) && !is.null(df)) {
218218
stop_glue(
219219
"`assume()` expects the `df` argument to be a numeric vector, ",
220220
"but you supplied a {list(class(df))} object."
221221
)
222222
}
223-
223+
224224
if (length(list(...)) != 0) {
225225
plural <- length(list(...)) != 1
226226
dots <- list(...)
227-
227+
228228
stop_glue(
229229
"`assume()` ignores the dots `...` argument, though the ",
230230
"argument{if (plural) 's' else ''} `{list(dots)}` ",
231231
"{if (plural) 'were' else 'was'} supplied. Did you forget to ",
232232
"concatenate the `df` argument with `c()`?"
233233
)
234234
}
235-
235+
236236
if (dist_df_length(distribution) != length(df) && !is.null(df)) {
237237
plural <- length(df) != 1
238238
stop_glue(
@@ -242,9 +242,9 @@ check_distribution <- function(x, distribution, df, ...) {
242242
'{if (plural) "were" else "was"} supplied.'
243243
)
244244
}
245-
245+
246246
df <- determine_df(x, dist, df)
247-
247+
248248
return(df)
249249
}
250250

@@ -286,12 +286,12 @@ df_desc <- function(df) {
286286
""
287287
} else {
288288
plural <- length(df) != 1
289-
289+
290290
paste0(
291-
' with ',
292-
if (plural) {paste0(round(df), collapse = " and ")} else {round(df)},
293-
' degree',
294-
if (!plural && df == 1) {''} else {'s'},
291+
' with ',
292+
if (plural) {paste0(round(df), collapse = " and ")} else {round(df)},
293+
' degree',
294+
if (!plural && df == 1) {''} else {'s'},
295295
' of freedom')
296296
}
297297
}
@@ -317,18 +317,18 @@ determine_df <- function(x, dist, df) {
317317
"for `df` is correct (see `?assume` for recognized values) or ",
318318
"supply `df = NULL` to `assume()`."
319319
)
320-
320+
321321
return(df)
322322
}
323-
323+
324324
if (is.null(df)) {
325325
df <- acceptable_dfs(x)
326326
}
327-
327+
328328
if (attr(x, "theory_type") == "Two sample t") {
329329
df <- df[1]
330330
}
331-
331+
332332
df
333333
}
334334

@@ -339,16 +339,16 @@ acceptable_dfs <- function(x) {
339339
# t.test param with var.equal = FALSE
340340
unname(
341341
unlist(
342-
attr(x, "distr_param") <-
343-
stats::t.test(response_variable(x) ~
342+
attr(x, "distr_param") <-
343+
stats::t.test(response_variable(x) ~
344344
explanatory_variable(x))[["parameter"]]
345345
)
346346
),
347347
# t.test param with var.equal = TRUE
348348
unname(
349349
unlist(
350-
attr(x, "distr_param") <-
351-
stats::t.test(response_variable(x) ~
350+
attr(x, "distr_param") <-
351+
stats::t.test(response_variable(x) ~
352352
explanatory_variable(x),
353353
var.equal = TRUE)[["parameter"]]
354354
)
@@ -368,7 +368,7 @@ acceptable_dfs <- function(x) {
368368
)
369369
} else {
370370
c(
371-
unname(unlist(attr(x, "distr_param"))),
371+
unname(unlist(attr(x, "distr_param"))),
372372
unname(unlist(attr(x, "distr_param2")))
373373
)
374374
}

R/deprecated.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Deprecated functions and objects
22
#'
3-
#' These functions and objects should no longer be used. They will be removed
3+
#' These functions and objects should no longer be used. They will be removed
44
#' in a future release of \code{infer}.
55
#' @param x See the non-deprecated function.
66
#' @param level See the non-deprecated function.

0 commit comments

Comments
 (0)