Learn R Programming

VGAM (version 1.1-8)

logLik.vlm: Extract Log-likelihood for VGLMs/VGAMs/etc.

Description

Calculates the log-likelihood value or the element-by-element contributions of the log-likelihood.

Usage

# S3 method for vlm
logLik(object, summation = TRUE, ...)

Value

Returns the log-likelihood of the object. If summation = FALSE then a \(n\)-vector or

\(n\)-row matrix (with the number of responses as the number of columns) is returned. Each element is the contribution to the log-likelihood. The prior weights are assimulated within the answer.

Arguments

object

Some VGAM object, for example, having class vglmff-class.

summation

Logical, apply sum? If FALSE then a \(n\)-vector or \(n\)-row matrix (with the number of responses as the number of columns) is returned. Each element is the contribution to the log-likelihood.

...

Currently unused. In the future: other possible arguments fed into logLik in order to compute the log-likelihood.

Author

T. W. Yee.

Warning

Not all VGAM family functions have had the summation checked.

Details

By default, this function returns the log-likelihood of the object. Thus this code relies on the log-likelihood being defined, and computed, for the object.

See Also

VGLMs are described in vglm-class; VGAMs are described in vgam-class; RR-VGLMs are described in rrvglm-class; AIC; anova.vglm.

Examples

Run this code
zdata <- data.frame(x2 = runif(nn <- 50))
zdata <- transform(zdata, Ps01    = logitlink(-0.5       , inverse = TRUE),
                          Ps02    = logitlink( 0.5       , inverse = TRUE),
                          lambda1 =  loglink(-0.5 + 2*x2, inverse = TRUE),
                          lambda2 =  loglink( 0.5 + 2*x2, inverse = TRUE))
zdata <- transform(zdata, y1 = rzipois(nn, lambda = lambda1, pstr0 = Ps01),
                          y2 = rzipois(nn, lambda = lambda2, pstr0 = Ps02))

with(zdata, table(y1))  # Eyeball the data
with(zdata, table(y2))
fit2 <- vglm(cbind(y1, y2) ~ x2, zipoisson(zero = NULL), data = zdata)

logLik(fit2)  # Summed over the two responses
sum(logLik(fit2, sum = FALSE))  # For checking purposes
(ll.matrix <- logLik(fit2, sum = FALSE))  # nn x 2 matrix
colSums(ll.matrix)  # log-likelihood for each response

Run the code above in your browser using DataLab