Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

shade_confidence_interval

Add information about confidence interval


Description

shade_confidence_interval() plots confidence interval region on top of the visualize() output. It should be used as \ggplot2\ layer function (see examples). shade_ci() is its alias.

Learn more in vignette("infer").

Usage

shade_confidence_interval(
  endpoints,
  color = "mediumaquamarine",
  fill = "turquoise",
  ...
)

shade_ci(endpoints, color = "mediumaquamarine", fill = "turquoise", ...)

Arguments

endpoints

A 2 element vector or a 1 x 2 data frame containing the lower and upper values to be plotted. Most useful for visualizing conference intervals.

color

A character or hex string specifying the color of the end points as a vertical lines on the plot.

fill

A character or hex string specifying the color to shade the confidence interval. If NULL then no shading is actually done.

...

Other arguments passed along to \ggplot2\ functions.

Value

A list of \ggplot2\ objects to be added to the visualize() output.

See Also

shade_p_value() to add information about p-value region.

Examples

# find the point estimate---mean number of hours worked per week
point_estimate <- gss %>%
  specify(response = hours) %>%
  calculate(stat = "mean") %>%
  dplyr::pull()
  
# ...and a null distribution
null_dist <- gss %>%
  # ...we're interested in the number of hours worked per week
  specify(response = hours) %>%
  # hypothesizing that the mean is 40
  hypothesize(null = "point", mu = 40) %>%
  # generating data points for a null distribution
  generate(reps = 1000, type = "bootstrap") %>%
  # finding the null distribution
  calculate(stat = "mean")
  
# find a confidence interval around the point estimate
ci <- null_dist %>%
  get_confidence_interval(point_estimate = point_estimate,
                          # at the 95% confidence level
                          level = .95,
                          # using the standard error method
                          type = "se")   
  
  
# and plot it!
null_dist %>%
  visualize() +
  shade_confidence_interval(ci)
  
# or just plot the bounds
null_dist %>%
  visualize() +
  shade_confidence_interval(ci, fill = NULL)

# More in-depth explanation of how to use the infer package
## Not run: 
vignette("infer")

## End(Not run)

infer

Tidy Statistical Inference

v0.5.4
CC0
Authors
Andrew Bray [aut, cre], Chester Ismay [aut] (<https://orcid.org/0000-0003-2820-2547>), Evgeni Chasnovski [aut] (<https://orcid.org/0000-0002-1617-4019>), Ben Baumer [aut] (<https://orcid.org/0000-0002-3279-0516>), Mine Cetinkaya-Rundel [aut] (<https://orcid.org/0000-0001-6452-2420>), Simon Couch [ctb], Ted Laderas [ctb] (<https://orcid.org/0000-0002-6207-7068>), Nick Solomon [ctb], Johanna Hardin [ctb], Albert Y. Kim [ctb] (<https://orcid.org/0000-0001-7824-306X>), Neal Fultz [ctb], Doug Friedman [ctb], Richie Cotton [ctb] (<https://orcid.org/0000-0003-2504-802X>), Brian Fannin [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.