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

Learn more in vignette("infer").

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

# Generate a null distribution by taking 200 bootstrap samples gss %>% specify(response = hours) %>% hypothesize(null = "point", mu = 40) %>% generate(reps = 200, type = "bootstrap")
#> Response: hours (numeric) #> Null Hypothesis: point #> # A tibble: 100,000 x 2 #> # Groups: replicate [200] #> replicate hours #> <int> <dbl> #> 1 1 38.6 #> 2 1 38.6 #> 3 1 13.6 #> 4 1 87.6 #> 5 1 8.62 #> 6 1 54.6 #> 7 1 30.6 #> 8 1 23.6 #> 9 1 38.6 #> 10 1 38.6 #> # … with 99,990 more rows
# 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")
#> Response: partyid (factor) #> Explanatory: age (numeric) #> Null Hypothesis: independence #> # A tibble: 100,000 x 3 #> # Groups: replicate [200] #> partyid age replicate #> <fct> <dbl> <int> #> 1 rep 36 1 #> 2 dem 34 1 #> 3 dem 24 1 #> 4 ind 42 1 #> 5 dem 31 1 #> 6 dem 32 1 #> 7 dem 48 1 #> 8 rep 36 1 #> 9 rep 30 1 #> 10 dem 33 1 #> # … with 99,990 more rows
# More in-depth explanation of how to use the infer package if (FALSE) { vignette("infer") }