geom_lmboot: Do a balanced bootstrap on a linear model.

View source: R/ggplot_functions.R

geom_lmbootR Documentation

Do a balanced bootstrap on a linear model.

Description

This function calculates a linear regression of y versus x. The data are bootstrapped to generate confidence intervals around the slope and intercept. Optionally, the r2 value may also be calculated. By default, the geom prints the text of the results in the upper-left corner of the plot and also plots the fit line. The bootstrapped prediction interval around the fit may also be plotted.

Usage

geom_lmboot(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  show.legend = NA,
  position = "identity",
  ...,
  n = 10000,
  show.fit = T,
  show.label = T,
  linesize = 1,
  location = "tl",
  method = "ols",
  m = T,
  m.95 = T,
  int = T,
  int.95 = T,
  r2 = T,
  r2.95 = F,
  p = T,
  fontfamily = "serif",
  ci.width = 95,
  show.pred.band = F,
  fill = "blue",
  pred.alpha = 0.25,
  pred.limits = c(NA, NA),
  pred.steps = 25,
  fontsize = 6,
  coef.digits = 2,
  nudge_x = 0,
  nudge_y = 0,
  inherit.aes = T
)

Arguments

mapping

Set of aesthetic mappings created by aes or aes_.

data

The data to be displayed in this layer.

stat

The statistical transformation to use on the data for this layer, as a string.

n

Bootstrap N, defaults to 10000

show.fit

Should the regression fit line be shown? Boolean, defaults to TRUE.

show.label

Should the regression fit summary be shown? Boolean, defaults to TRUE.

linesize

The size of the fit line (in points).

location

Location to print fit results. Defaults to 'tl' (top-left), but may be 'tr', 'bl', or 'br'.

method

Regression model of the slope. Defaults to 'ols' for Ordinary Least Squares, but may also be 'rma' to perform a Reduced Major Axis (i.e., Standard Major Axis - not Ranged)

m

Should the slope coefficient be shown? Boolean, defaults to TRUE.

m.95

Should the slope's confidence interval be shown? Boolean, defaults to TRUE.

int

Should the intercept be shown? Boolean, defaults to TRUE.

int.95

Should the intercept's confidence interval be shown? Boolean, defaults to TRUE.

r2

Should Pearson's r-squared be shown? Boolean, defaults to TRUE.

r2.95

Should the r-squared confidence interval be shown? Boolean, defaults to FALSE. This can be misleading for poor fits because the calculated r value may be either negative or positive and is then squared. Use with caution.

p

Should the slope's p-value be printed? This only prints if the hypothetical 'p' is above or below the significance level chosen. I.e., does the slope's confidence interval overlap with zero?

fontfamily

Font family as a string to use for label plotting.

ci.width

The width of the confidence interval to use (in percents).

show.pred.band

Should the prediction interval be calculated and shown? Boolean. This is computationally intensive because it is also bootstrapped.

fill

Color of the prediction interval.

pred.alpha

Alpha of the prediction interval.

pred.steps

Number of steps to calculate the prediction interval at. Increase for higher resolution at cost of computation time.

fontsize

Font size as an integer (in pointS). Used for lable plotting.

coef.digits

Number of digits to round to in the fit label.

nudge_x

Manual X-axis adjustment of the text. In plotting units (where plotting area ranges from 0 to 1).

nudge_y

Manual Y-axis adjustment of the text. In plotting units (where plotting area ranges from 0 to 1).

Aesthetics

The geom understands the following aesthetics (required are in bold):

  • x

  • y

  • xsd (Vector with length 1 or equal to X. If present, used as the SD term of an rnorm call for each X value during bootstrapping)

  • ysd (Vector with length 1 or equal to Y. If present, used as the SD term of an rnorm call for each Y value during bootstrapping)


JackAHutchings/jahrfun documentation built on June 8, 2025, 3:09 a.m.