Learn R Programming

ggpmisc (version 0.6.3)

quant_helper_fun: Helper function for fitting quantile regression

Description

Factored out code used in both stat_quant_line(), stat_quant_band() and stat_quant_eq().

Usage

quant_helper_fun(
  data,
  formula = y ~ x,
  quantiles = c(0.25, 0.5, 0.75),
  fit.by.quantile = FALSE,
  method,
  method.name,
  method.args = list(),
  n.min = 3L,
  fit.seed = NA,
  weight = 1,
  na.rm = FALSE,
  orientation = "x"
)

Value

A list, with members fm1, fm2, ... one for each fitted model and fun.args1, fun.args2, ... with arguments passed in each call to the model fit function.

Arguments

data

A layer specific dataset, only needed if you want to override the plot defaults.

formula

a formula object. Using aesthetic names x and y instead of original variable names.

quantiles

numeric vector Values in 0..1 indicating the quantiles.

fit.by.quantile

logical If TRUE return a separate fitted model object for each quantile as needed for predictions with confidence bands.

method

function or character If character, "rq", "rqss" or the name of a model fit function are accepted, possibly followed by the fit function's method argument separated by a colon (e.g. "rq:br"). If a function different to rq(), it must accept arguments named formula, data, weights, tau and method and return a model fit object of class rq, rqs or rqss.

method.args

named list with additional arguments passed to rq(), rqss() or to another function passed as argument to method.

n.min

integer Minimum number of distinct values in the explanatory variable (on the rhs of formula) for fitting to the attempted.

fit.seed

RNG seed argument passed to set.seed(). Defaults to NA, indicating that set.seed() should not be called.

na.rm

a logical indicating whether NA values should be stripped before the computation proceeds.

orientation

character Either "x" or "y" controlling the default for formula. The letter indicates the aesthetic considered the explanatory variable in the model fit.

Details

This function does the model fitting and returns a fitted model object. It decodes the method, sorts the quantiles and does the fit.

Examples

Run this code

ggpmisc:::quant_helper_fun(data.frame(x = mpg$displ, y = mpg$hwy), method = "br")

Run the code above in your browser using DataLab