Generate a ‘gamlss2’ Family from a ‘distributions3’ Object

Description

Set up a [gamlss2.family] object based on an object inheriting from ‘distribution’ (as provided by the distributions3 package).

Usage

## S3 method for class 'distribution'
family(object, links, score = TRUE, hessian = FALSE, update = FALSE, ...)

## S3 method for class 'GAMLSS'
family(object, ...)

## S3 method for class 'gamlss.family'
family(object, score = TRUE, hessian = FALSE, update = FALSE, ...)

distributions3_family(
  distribution,
  links,
  score = TRUE,
  hessian = FALSE,
  update = FALSE,
  create_distribution = "structure",
  type = NULL,
  valid.response = NULL,
  initialize = NULL,
  ...
)

Arguments

object an object specifying a distribution, typically created by Normal or Binomial or GAMLSS. Additionally, a gamlss.family from the gamlss.dist package is also supported.
links named vector or list. Specification of one link per parameter to be modeled, either via a character string to be passed to make.link2 or a link-gamlss2 object (inheriting from link-glm).
score logical. Should the score method for the distribution object be used to compute the scores? If set to FALSE they are approximated numerically.
hessian logical. Should the hessian method for the distribution object be used to compute the Hessians? If set to FALSE they are approximated numerically.
update logical. Should the score and hessian methods for the distribution object be used to compute the updates of the linear predictor and the corresponding weights? If set to FALSE they are approximated numerically.
arguments passed from the methods to the workhorse function distributions3_family.
distribution character. Name of the class and distribution object creator, e.g., “Normal” or “Binomial”.
create_distribution either a function or one of the character strings “structure” or “do.call”. This specifies how to create a distribution object from a (fitted) parameter list (typically from [gamlss2]). Either a dedicated function can be specified or such a function is set up internally. If create_distribution = “structure” then only the class attribute is added in a structure() call. If set to “do.call” then the distribution object is created via do.call() to the class creator (such as Normal etc.). The latter is safer but requires much more overhead.
type character. Specification of the type of distribution (“continuous” vs. “discrete”).
valid.response function. A function(x) returning a logical indicating whether x is a valid response for the distribution.
initialize list of functions. A named list with one function(y, …) per parameter to be modeled, returning an initialization for this parameter.

Details

The workhorse function distributions3_family sets up a gamlss2.family list by leveraging the generic functions and methods from the distributions3 package. The main idea is that gamlss2 in each iteration and in the final model fit provides a list of fitted parameters. These can then be mapped to the corresponding distribution class and all the corresponding methods (such as pdf for computing the probability density function) from distributions3 can be leveraged to compute the building blocks for fitting the model (e.g., pdf, score, hessian, etc.) and for assessing the final model fit.

The family methods all call distributions3_family internally but help to automatically infer and set up some of the elements of the family.

Value

A list inheriting from gamlss2.family.

Examples

library("gamlss2")

library("distributions3")
f <- family(Poisson(), links = c(lambda = "log"))
str(f)
List of 17
 $ family             : chr "Poisson"
 $ names              : chr "lambda"
 $ links              :List of 1
  ..$ lambda:List of 6
  .. ..$ linkfun :function (mu)  
  .. ..$ linkinv :function (eta)  
  .. ..$ mu.eta  :function (eta)  
  .. ..$ valideta:function (eta)  
  .. ..$ name    : chr "log"
  .. ..$ mu.eta2 :function (eta)  
  .. ..- attr(*, "class")= chr [1:2] "link-gamlss2" "link-glm"
 $ log_likelihood     :function (par, y, ...)  
 $ mu                 :function (par, ...)  
 $ pdf                :function (par, y, log = FALSE)  
 $ cdf                :function (par, y, ...)  
 $ random             :function (par, n)  
 $ quantile           :function (par, p)  
 $ crps               :function (par, y, ...)  
 $ mean               :function (par)  
 $ variance           :function (par)  
 $ skewness           :function (par)  
 $ kurtosis           :function (par)  
 $ create_distribution:function (par)  
 $ score              :List of 1
  ..$ lambda:function (par, y, ...)  
 $ valid.response     :function (x)  
 - attr(*, "class")= chr "gamlss2.family"