Learn R Programming

joker (version 0.14.2)

loglikelihood: Log-Likelihood Function

Description

This function calculates the log-likelihood of an independent and identically distributed (iid) sample from a distribution. See Details.

Usage

ll(distr, x, ...)

Value

If only the distr argument is supplied, ll() returns a function. If both distr and x are supplied, ll() returns a numeric, the value of the log-likelihood function.

Arguments

distr

A Distribution object

x

numeric. A sample under estimation.

...

extra arguments.

Details

The log-likelihood functions are provided in two forms: the ll<name> distribution-specific version that follows the stats package conventions, and the S4 generic ll. Examples for the ll<name> version are included in the distribution-specific help pages, e.g. ?Beta (all distributions can be found in the See Also section of the Distributions help page).

As with the d(), p(), q(), r() methods, ll() can be supplied only with distr to return the log-likelihood function (i.e. it can be used as a functional), or with both distr and x to be evaluated directly.

In some distribution families like beta and gamma, the MLE cannot be explicitly derived and numerical optimization algorithms have to be employed. Even in ``good" scenarios, with plenty of observations and a smooth optimization function, extra care should be taken to ensure a fast and right convergence if possible. Two important steps are taken in package in this direction:

  1. The log-likelihood function is analytically calculated for each distribution family, so that constant terms with respect to the parameters can be removed, leaving only the sufficient statistics as a requirement for the function evaluation.

  2. Multidimensional problems are reduced to unidimensional ones by utilizing the score equations.

The resulting function that is inserted in the optimization algorithm is called lloptim(), and is not to be confused with the actual log-likelihood function ll(). The corresponding derivative is called dlloptim(). These functions are used internally and are not exported.

Therefore, whenever numerical computation of the MLE is required, optim() is called to optimize lloptim(), using the ME or SAME as the starting point (user's choice), and the L-BFGS-U optimization algorithm, with lower and upper limits defined by default as the parameter space boundary. Illustrative examples can be found in the package vignette.

See Also

distributions, moments, estimation

Examples

Run this code
# -----------------------------------------------------
# Beta Distribution Example
# -----------------------------------------------------

# Create the distribution
a <- 3
b <- 5
D <- Beta(a, b)

# ------------------
# dpqr Functions
# ------------------

d(D, c(0.3, 0.8, 0.5)) # density function
p(D, c(0.3, 0.8, 0.5)) # distribution function
qn(D, c(0.4, 0.8)) # inverse distribution function
x <- r(D, 100) # random generator function

# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself

# ------------------
# Moments
# ------------------

mean(D) # Expectation
var(D) # Variance
sd(D) # Standard Deviation
skew(D) # Skewness
kurt(D) # Excess Kurtosis
entro(D) # Entropy
finf(D) # Fisher Information Matrix

# List of all available moments
mom <- moments(D)
mom$mean # expectation

# ------------------
# Point Estimation
# ------------------

ll(D, x)
llbeta(x, a, b)

ebeta(x, type = "mle")
ebeta(x, type = "me")
ebeta(x, type = "same")

mle(D, x)
me(D, x)
same(D, x)
e(D, x, type = "mle")

mle("beta", x) # the distr argument can be a character

# ------------------
# Estimator Variance
# ------------------

vbeta(a, b, type = "mle")
vbeta(a, b, type = "me")
vbeta(a, b, type = "same")

avar_mle(D)
avar_me(D)
avar_same(D)

v(D, type = "mle")

Run the code above in your browser using DataLab