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
m <- gamlss2(Ozone ~ s(Temp) | ., data = airquality, family = GA)
GAMLSS-RS iteration  1: Global Deviance = 930.1628 eps = 0.154681     
GAMLSS-RS iteration  2: Global Deviance = 925.1362 eps = 0.005403     
GAMLSS-RS iteration  3: Global Deviance = 924.8334 eps = 0.000327     
GAMLSS-RS iteration  4: Global Deviance = 924.7909 eps = 0.000045     
GAMLSS-RS iteration  5: Global Deviance = 924.7566 eps = 0.000037     
GAMLSS-RS iteration  6: Global Deviance = 924.7285 eps = 0.000030     
GAMLSS-RS iteration  7: Global Deviance = 924.7051 eps = 0.000025     
GAMLSS-RS iteration  8: Global Deviance = 924.6855 eps = 0.000021     
GAMLSS-RS iteration  9: Global Deviance = 924.6689 eps = 0.000017     
GAMLSS-RS iteration 10: Global Deviance = 924.6549 eps = 0.000015     
GAMLSS-RS iteration 11: Global Deviance = 924.6428 eps = 0.000013     
GAMLSS-RS iteration 12: Global Deviance = 924.6325 eps = 0.000011     
GAMLSS-RS iteration 13: Global Deviance = 924.6236 eps = 0.000009     
## 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 22.23839 21.16119 37.84301 72.52989 0.005163393 0.9712352
2 17.33198 15.87528 33.82326 77.02330 0.005554338 0.9641794
3 17.54759 16.55839 30.93017 52.64091 0.054558749 0.2351240
4 15.28824 13.86691 30.67807 66.42471 0.038640584 0.6883578
6 21.62571 20.72313 35.61413 59.01909 0.029735807 0.8094809
7 20.34534 19.49838 33.48711 52.10204 0.045459476 0.6809201