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,
  expected = FALSE,
  ...
)

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

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

## S3 method for class 'Normal'
family(object, links = NULL, initialize = NULL, ...)

## S3 method for class 'Poisson'
family(object, links = NULL, initialize = NULL, ...)

distributions3_family(
  distribution,
  links,
  score = TRUE,
  hessian = FALSE,
  update = FALSE,
  expected = 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.
expected logical. Should the expected rather than the observed Hessian be used?
… 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 with the same length as y.

Details

Using family methods, it is possible to set up gamlss2.family objects based on distribution objects leveraging the distributions3 infrastructure. The workhorse function is distributions3_family that defines all family elements using the standard distributions3 generics. Additionally, dedicated methods for specific classes such as GAMLSS or Normal etc. define further family elements for which no standard generic functions are available (e.g., the links or initialize functions) and then call the distributions3_family workhorse function.

Value

A list inheriting from gamlss2.family.

Examples

library("gamlss2")

library("distributions3")
f <- family(Poisson(), links = c(lambda = "log"))
str(f)
List of 19
 $ 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)  
 $ support            :function (par, ...)  
 $ score              :List of 1
  ..$ lambda:function (par, y, ...)  
 $ valid.response     :function (x)  
 $ initialize         :List of 1
  ..$ lambda:function (y, ...)  
 - attr(*, "class")= chr "gamlss2.family"