Quantiles for GAMLSS

Description

The function computes estimated quantiles and optionally produces a plot.

Usage

## S3 method for class 'gamlss2'
quantile(x, probs = c(0.025, 0.25, 0.50, 0.75, 0.975),
  variable = NULL, newdata = NULL,
  plot = FALSE, data = TRUE,
  n = 100L, ...)

Arguments

x An object of class “gamlss2”.
probs Numeric vector of probabilities with values in [0,1].
variable Covariate selector for single-covariate models: TRUE uses the sole covariate; an integer or character selects by column position or name. NULL (default) or FALSE computes quantiles at the supplied or fitted observations without a covariate grid.
newdata Data frame that should be used for computing the quantiles.
plot Logical, should an ordered quantile plot or a covariate plot be shown?
data Logical, should observed responses be added to the plot when available?
n Integer, number of observations that should be used to compute an equidistant grid for the selected variable.
… Arguments such as col, legend = TRUE/FALSE. See the examples.

Details

Quantiles are computed from the predicted response distributions. Probabilities are passed to the family’s quantile function without clipping. Endpoint probabilities can return infinite quantiles, and invalid probabilities are handled by the family.

With plot = TRUE and no selected variable, the x-axis shows observation ranks as percentages, ordered by fitted median; the y-axis is on the response scale. Lines show the fitted conditional quantiles at probs, and points show observed responses when data = TRUE. The same ordering is used for the responses and all quantiles, so each position refers to one observation. If newdata does not contain the response, only the fitted quantile curves are shown.

Value

A data frame with one row per prediction and one column per probability. With variable = NULL, a single probability returns a numeric vector. When a covariate is selected, it is included as the first column. With plot = TRUE, the result is returned invisibly.

See Also

gamlss2.

Examples

library("gamlss2")

data("SpirometryUS", package = "gamlss2")

## subset for female
d <- subset(SpirometryUS, gender == "female")

## model formula
f <- fev1 ~ s(age) | . | . | .

## estimate model
m <- gamlss2(f, data = d, family = BCPE)

## compute quantiles using "newdata"
nd <- d[1:10, ]
print(quantile(m, newdata = nd))

## plot quantiles ordered by the fitted median
quantile(m, plot = TRUE)

## quantile plot using covariate data
quantile(m, plot = TRUE,
  variable = TRUE, pos = "topright")

## plot without raw data
quantile(m, plot = TRUE,
  variable = TRUE, pos = "topright", data = FALSE)