Learn R Programming

infer (version 0.5.2)

generate: Generate resamples, permutations, or simulations

Description

Generation creates a null distribution from specify() and (if needed) hypothesize() inputs.

Learn more in vignette("infer").

Usage

generate(x, reps = 1, type = NULL, ...)

Arguments

x

A data frame that can be coerced into a tibble.

reps

The number of resamples to generate.

type

Currently either bootstrap, permute, or simulate (see below).

...

Currently ignored.

Value

A tibble containing reps generated datasets, indicated by the replicate column.

Generation Types

The type argument determines the method used to create the null distribution.

  • bootstrap: A bootstrap sample will be drawn for each replicate, where a sample of size equal to the input sample size is drawn (with replacement) from the input sample data.

  • permute: For each replicate, each input value will be randomly reassigned (without replacement) to a new output value in the sample.

  • simulate: A value will be sampled from a theoretical distribution with parameters specified in hypothesize() for each replicate. (This option is currently only applicable for testing point estimates.)

Examples

Run this code
# NOT RUN {
# Generate a null distribution by taking 200 bootstrap samples
gss %>%
 specify(response = hours) %>%
 hypothesize(null = "point", mu = 40) %>%
 generate(reps = 200, type = "bootstrap")

# Generate a null distribution for the independence of
# two variables by permuting their values 1000 times
gss %>%
 specify(partyid ~ age) %>%
 hypothesize(null = "independence") %>%
 generate(reps = 200, type = "permute")

# 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