distfit {disttree}R Documentation

Maximum-Likelihood Fitting of Parametric Distributions

Description

The function distfit carries out maximum-likelihood estimation of parameters for distributions from the GAMLSS family (for generalized additive models for location, scale, and shape). The parameters can be transformed through link functions but do not depend on further covariates (i.e., are constant across observations).

Usage

distfit(y, family, weights = NULL, start = NULL, start.eta = NULL, 
        vcov = TRUE, type.hessian = c("checklist", "analytic", "numeric"), estfun = TRUE, 
        bd = NULL, fixed = NULL, fixed.values = NULL, 
        censtype = "none", censpoint = NULL, ocontrol = list(), ...)

Arguments

y

numeric vector of the response

family

specification of the response distribution. Either a gamlss.family object, a list generating function or a family list.

weights

optional numeric vector of case weights.

start

starting values for the distribution parameters handed over to optim

start.eta

starting values for the distribution parameters on the link scale handed over to optim.

vcov

logical. Specifies whether or not a variance-covariance matrix should be calculated and returned.

type.hessian

Can either be 'checklist', 'analytic' or 'numeric' to decide how the hessian matrix should be calculated in the fitting process in distfit. For 'checklist' it is checked whether a function 'hdist' is given in the family list. If so, 'type.hessian' is set to 'analytic', otherwise to 'numeric'.

estfun

logical. Should the matrix of observation-wise score contributions (or empirical estimating functions) be returned?

bd

binomial denominator: additional parameter needed for binomial gamlss.families

fixed

FIXME

fixed.values

FIXME

censtype

Can either be 'none', 'left' or 'right' to set the type of censoring for censored response.

censpoint

numeric value. Censoring point can be set for censored response.

ocontrol

List with control parameters passed to optim.

...

further arguments passed to optim.

Details

The function distfit fits distributions, similar to fitdistr from MASS (Venables and Ripley 2002) but based on GAMLSS families (Stasinopoulos and Rigby 2007).

Provides analytical gradients and hessian, can be plugged into mob.

The resulting object of class distfit comes with a set of standard methods to generic functions including coef, estfun, vcov, predict and logLik.

Value

distfit returns an object of class distfit which is a list with the following components:

npar

number of parameter

y

numeric vector of the response

ny

number of observations

weights

numeric vector of case weights handed over as input argument

family

name of the distribution family

familylist

if the input argument 'family' was already a list, this list is returned. Otherwise the generated family list is returned.

start

used starting values in optim that were handed over as input argument

starteta

starting value on the link scale used in optim

opt

list returned by optim

converged

logical. TRUE if optim returnes convergence = 0 and FALSE else.

par

fitted distribution parameters (on parameter scale)

eta

fitted distribution parameters (on link scale)

hess

hessian matrix

vcov

variance-covariance matrix

loglik

value of the maximized log-likelihood function

call

function call

estfun

matrix with the scores for the estimated parameters. Each line represents an observation and each column a parameter.

ddist

density function with the estimated distribution parameters already plugged in

pdist

probability function with the estimated distribution parameters already plugged in

qdist

quantile function with the estimated distribution parameters already plugged in

rdist

random number generating function with the estimated distribution parameters already plugged in

method

optimization method applied in optim

References

Stasinopoulos DM, Rigby RA (2007). Generalized Additive Models for Location Scale and Shape (GAMLSS) in R, Journal of Statistical Software, 23(7), 1-46. doi: 10.18637/jss.v023.i07

Venables WN, Ripley BD (2002). Modern Applied Statistics with S. 4th Edition. Springer-Verlag, New York.

See Also

gamlss.family, optim

Examples

## simulate artifical negative binomial data
set.seed(0)
y <- rnbinom(1000, size = 1, mu = 2)
  
## simple distfit
df <- distfit(y, family = NBI)
coef(df)
confint(df)
logLik(df)

## using tabulated data
ytab <- table(y)
df2 <- distfit(as.numeric(names(ytab)), family = NBI, weights = ytab)
coef(df2)
confint(df2)
logLik(df2)

## coefficients tests
if(require("lmtest")) {
  coeftest(df)
  coeftest(df2)
}

## censored logistic example
if(require("crch") & require("gamlss.cens")) {
    library("crch")
    data("RainIbk", package = "crch")
    m1 <- crch(rain ~ 1, data = RainIbk, left = 0, dist = "logistic")
  
    library("gamlss.cens")
    gen.cens(LO, type = "left")
    m2 <- distfit(RainIbk$rain, family = LOlc, cens = "left", censpoint = 0)
    
    dist_list_cens_log <- disttree::dist_crch(dist = "logistic", 
                                              type = "left",
                                              censpoint = 0)
    m3 <- distfit(RainIbk$rain, family = dist_list_cens_log)
    
    coef(m1)
    coef(m2, type = "link")
    coef(m3, type = "link")
    logLik(m1)
    logLik(m2)
    logLik(m3)
}

[Package disttree version 0.1-0 Index]