Learn R Programming

infer (version 0.5.2)

calculate: Calculate summary statistics

Description

Calculates summary statistics from outputs of generate() or hypothesize().

Learn more in vignette("infer").

Usage

calculate(
  x,
  stat = c("mean", "median", "sum", "sd", "prop", "count", "diff in means",
    "diff in medians", "diff in props", "Chisq", "F", "slope", "correlation", "t", "z",
    "ratio of props", "odds ratio"),
  order = NULL,
  ...
)

Arguments

x

The output from generate() for computation-based inference or the output from hypothesize() piped in to here for theory-based inference.

stat

A string giving the type of the statistic to calculate. Current options include "mean", "median", "sum", "sd", "prop", "count", "diff in means", "diff in medians", "diff in props", "Chisq", "F", "t", "z", "ratio of props", "slope", and "correlation".

order

A string vector of specifying the order in which the levels of the explanatory variable should be ordered for subtraction, where order = c("first", "second") means ("first" - "second") Needed for inference on difference in means, medians, or proportions and t and z statistics.

...

To pass options like na.rm = TRUE into functions like mean(), sd(), etc.

Value

A tibble containing a stat column of calculated statistics.

Missing levels in small samples

In some cases, when bootstrapping with small samples, some generated bootstrap samples will have only one level of the explanatory variable present. For some test statistics, the calculated statistic in these cases will be NaN. The package will omit non-finite values from visualizations (with a warning) and raise an error in p-value calculations.

Examples

Run this code
# NOT RUN {
# calculate a null distribution of hours worked per week under
# the null hypothesis that the mean is 40
gss %>%
 specify(response = hours) %>%
 hypothesize(null = "point", mu = 40) %>%
 generate(reps = 200, type = "bootstrap") %>%
 calculate(stat = "mean")

# calculate a null distribution assuming independence between age
# of respondent and whether they have a college degree
gss %>%
 specify(age ~ college) %>%
 hypothesize(null = "independence") %>%
 generate(reps = 200, type = "permute") %>%
 calculate("diff in means", order = c("degree", "no degree"))

# More in-depth explanation of how to use the infer package
# }
# NOT RUN {
vignette("infer")
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab