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)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
|
Logical, integer, or character. Should quantiles be plotted against a covariate? If TRUE, the single model covariate is used. Alternatively, a covariate can be selected by position or name. This option is only available for single-covariate models.
|
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
The function applies the predict method to determine the parameters of the response distribution. It then computes the quantiles as specified in the argument probs.
With plot = TRUE and variable = NULL, observations are ordered once by their fitted median. The same ordering is applied to the observed responses and all fitted quantiles, so values at each position refer to the same observation. If newdata does not contain the response, only the fitted quantile curves are shown.
Value
The estimated quantiles. For multiple probabilities, a data frame is returned. For a single probability and variable = NULL, the result is simplified to a numeric vector.
See Also
gamlss2.