Create a GDF Distribution

Description

The GDF (gamlss2 Distribution Family) is a unified class with corresponding methods that represent all distributional families supported by the gamlss2 package. It enables seamless integration with the distributions3 workflow and provides a consistent interface for model fitting and distributional computations.

Usage

GDF(family, parameters)

Arguments

family character. Name of a gamlss2.family or a family provided by the gamlss.dist package, e.g, NO or BI for the normal or binomial distribution, respectively.
parameters numeric, matrix, list or data frame, see the examples.

Details

The S3 class GDF is a slightly more general implementation of the S3 class GAMLSS tailored for gamlss2. For details please see the documentation of GAMLSS

Value

A GDF object, inheriting from distribution.

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

Examples

library("gamlss2")


## package and random seed
library("distributions3")
set.seed(6020)

## one normal distribution
X <- GDF("NO", c(mu = 1, sigma = 2))
X
[1] "GDF NO(mu = 1, sigma = 2)"
## two normal distributions
X <- GDF("NO", cbind(c(1, 1.5), c(0.6, 1.2)))
X
[1] "GDF NO(mu = 1.0, sigma = 0.6)" "GDF NO(mu = 1.5, sigma = 1.2)"
## three Weibull distributions
X <- GDF("WEI", list(mu = c(1, 1, 2), sigma = c(1, 2, 2)))
X
[1] "GDF WEI(mu = 1, sigma = 1)" "GDF WEI(mu = 1, sigma = 2)"
[3] "GDF WEI(mu = 2, sigma = 2)"
## see ?gamlss.dist::GAMLSS for the remainder of this example
## example using gamlss2
data("abdom", package = "gamlss.data")

## estimate model
m <- gamlss2(y ~ s(x) | . | . | ., data = abdom, family = GA)
GAMLSS-RS iteration  1: Global Deviance = 4782.0591 eps = 0.389820     
GAMLSS-RS iteration  2: Global Deviance = 4781.189 eps = 0.000181     
GAMLSS-RS iteration  3: Global Deviance = 4781.1889 eps = 0.000000     
## extract, also works with newdata
d <- data.frame(
  "mean" = mean(m),
  "median" = median(m),
  "q95" = quantile(m, probs = 0.95),
  "variance" = variance(m),
  "pdf" = pdf(m),
  "cdf" = cdf(m)
)
print(head(d))
      mean   median      q95 variance        pdf       cdf
1 63.75727 63.57843 73.67513 34.22323 0.05199436 0.2108232
2 63.75727 63.57843 73.67513 34.22323 0.06782998 0.5287075
3 63.75727 63.57843 73.67513 34.22323 0.02977634 0.0880195
4 65.07825 64.89860 75.11900 35.09257 0.05606336 0.2505177
5 67.80200 67.62069 78.09301 36.89708 0.03680864 0.8462498
6 67.80200 67.62069 78.09301 36.89708 0.03033053 0.0955850