gen_curves: Generate Quantile Curves for a 'quantileplot'

View source: R/gen_curves.R

gen_curvesR Documentation

Generate Quantile Curves for a quantileplot

Description

Estimate smooth curves for quantiles of the outcome as a function of the predictor. This function calls mqgam from the qgam package. This function is typically called indirectly via a user call to quantileplot.

Usage

gen_curves(
  formula,
  data,
  weights = NULL,
  quantiles = c(0.1, 0.25, 0.5, 0.75, 0.9),
  show_ci = FALSE,
  credibility_level = 0.95,
  uncertainty_draws = 10,
  inverse_transformation = NULL,
  second_formula,
  argGam = NULL,
  ...
)

Arguments

formula

A bivariate model formula (e.g. y ~ s(x))

data

Data frame containing the variables in formula. If weights are specified, they must be a column of data.

weights

String name for sampling weights, which are a column of data. If not given, a simple random sample is assumed.

quantiles

Numeric vector containing quantiles to be estimated. Values should be between 0 and 1.

show_ci

Logical, defaults to FALSE. Whether to show credible intervals for the estimated smooth quantile curves.

credibility_level

Numeric probability value for credible intervals; default to 0.95 to produce 95 percent credible intervals. Only relevant if show_ci = TRUE.

uncertainty_draws

A whole number. If non-null, the number of simulated posterior draws to estimate for each smooth quantile curve. When used with the plot function, these appear in panels below the main plot.

inverse_transformation

A function of a scalar argument. Only used in the rare use case where the outcome has an extremely skewed distribution and the user wants to estimate the quantile curves on a transformed outcome, to be brought back to the original scale for the visualization. In that case, this argument is the function to convert from the transformed outcome back to the original scale. For instance, if the outcome in the model formula is log(y + 1) then the inverse transformation should be function(y) exp(y) - 1. This is a rare use case because it is only relevant when a transformation of the outcome aids the estimation of quantile curves. If you want to visualize on a transformed scale, you should instead create a transformed variable in data rather than conducting the transformation within the model formula. For common transformations (e.g. log(y)), the inverse_transformation argument can left NULL and will be determined automatically.

second_formula

Model formula to allow the learning rate to change as a function of the predictor. This is passed to mqgam as the second element in the form argument. Defaults to the same specification as formula but without the outcome variable.

argGam

Additional arguments to the GAM for model fitting. Passed to mqgam.

...

Other arguments passed to mqgam.

Value

A list of length 2. Element curves is a data frame containing the data for plotting smooth curves for quantiles of the outcome given the predictor. Element mqgam.out is the fitted object from mqgam.

References

Lundberg, Ian, Robin C. Lee, and Brandon M. Stewart. 2021. "The quantile plot: A visualization for bivariate population relationships." Working paper.

Lundberg, Ian, and Brandon M. Stewart. 2020. "Comment: Summarizing income mobility with multiple smooth quantiles instead of parameterized means." Sociological Methodology 50(1):96-111.

Fasiolo, Matteo, Simon N. Wood, Margaux Zaffran, Raphaƫl Nedellec, and Yannig Goude. 2020. "Fast calibrated additive quantile regression." Journal of the American Statistical Association.


ilundberg/quantileplot documentation built on May 23, 2022, 3:12 a.m.