Extracting Fitted or Predicted Probability Distributions from gamlss2 Models

Description

Methods for gamlss2 model objects for extracting fitted (in-sample) or predicted (out-of-sample) probability distributions as distributions3 objects.

Usage

## S3 method for class 'gamlss2'
prodist(object, ...)

Arguments

object A model object of class gamlss2.
… Arguments passed on to predict.gamlss2, e.g., newdata.

Details

For ordinary predictions, prodist(object, newdata = …) returns the same distributions as the default predict(object, newdata = …). Use prodist when code needs a common interface for extracting probability distributions from different supported model classes. Omit newdata to obtain fitted distributions.

The returned objects support distributions3 methods such as pdf(), cdf(), quantile(), and random(). They describe response variation conditional on the fitted parameters; they do not include parameter-estimation uncertainty.

Value

A distributions3 object inheriting from distribution. Its concrete class depends on the family: a distributions3 family retains its distribution class (e.g., Normal); families without a distribution constructor use GAMLSS2.

References

Zeileis A, Lang MN, Hayes A (2022). “distributions3: From Basic Probability to Probabilistic Regression”. Presented at useR! 2022 - The R User Conference. Slides, video, vignette, code at https://www.zeileis.org/news/user2022/.

See Also

GAMLSS2, family.distribution, predict.gamlss2

Examples

library("gamlss2")

library("distributions3")
data("cars", package = "datasets")
m <- gamlss2(dist ~ s(speed) | s(speed),
  data = cars, family = GA)

## prodist() and default predict() return the same distributions
nd <- data.frame(speed = c(10, 20, 30))
d <- prodist(m, newdata = nd)
all.equal(d, predict(m, newdata = nd))
print(d)

## evaluate the predicted distributions
quantile(d, c(0.05, 0.5, 0.95), elementwise = FALSE)
mean(d)
variance(d)
pdf(d, c(10, 50, 100))
cdf(d, c(10, 50, 100))
random(d, 5)

## fitted distributions reproduce the model log-likelihood
sum(log_pdf(prodist(m), cars$dist))
logLik(m)