How the infer grammar works
mainThe infer package uses an expressive, verb-based grammar to perform statistical inference (both hypothesis testing and confidence interval construction) following tidyverse principles. Instead of calling specific test functions (like a t-test), you build a pipeline using four main verbs that abstract the underlying statistical process.
Hypothesis Testing Workflow
To test if an effect is real or due to chance, follow this pipeline:
specify(): Define the variable or relationship of interest.hypothesize(): Declare the null hypothesis (e.g., that there is no difference).generate(): Create a null distribution by simulating data that reflects the null hypothesis (randomization) or by using bootstrapping.calculate(): Compute summary statistics from both the observed data and the generated null data to form the test statistic and the null distribution.
Confidence Interval Workflow
To construct confidence intervals via bootstrapping, use a similar pipeline but omit the hypothesize() step:
specify()generate()(using bootstrap)calculate()
Visualizing and Extracting Results
Once the pipeline is complete, use these utilities to interpret the output:
- For Hypothesis Testing:
visualize(): Plots the null distribution.shade_p_value(): Shades the region of the distribution as extreme or more extreme than the observed statistic.get_p_value(): Calculates the p-value by comparing the observed statistic to the null distribution.
- For Confidence Intervals:
visualize(): Plots the bootstrap distribution.shade_confidence_interval(): Situates the confidence interval region within the distribution.get_confidence_interval(): Calculates the specific bounds of the interval.