Learn R Programming

VGAM (version 1.0-5)

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, …)

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.

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.

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.

Examples

Run this code
# NOT RUN {
zdata <- data.frame(x2 = runif(nn <- 50))
zdata <- transform(zdata, Ps01    = logit(-0.5       , inverse = TRUE),
                          Ps02    = logit( 0.5       , inverse = TRUE),
                          lambda1 =  loge(-0.5 + 2*x2, inverse = TRUE),
                          lambda2 =  loge( 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