logLike {UEM}R Documentation

Log-likelihood of fitted model

Description

Produces numerical value of the log-likelihood of a fitted model.

Usage

logLike(theta, y)

Arguments

theta
y

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (theta, y, K) 
{
    if (is.vector(y)) {
        y <- matrix(y, ncol = 1)
    }
    if (is.null(theta$family)) {
        if (!is.null(theta$var)) {
            theta$family <- "Gaussian"
        }
        else {
            theta$family <- "Poisson"
        }
    }
    dens <- matrix(0, dim(y)[1], K)
    for (k in 1:K) {
        dens[, k] <- switch(theta$family, Gaussian = theta$pi[k] * 
            dmvnorm(y, mean = theta$mu[k, ], sigma = theta$var[[k]]), 
            Poisson = theta$pi[k] * dpois(y, lambda = theta$mu[k]))
    }
    loglik <- sum(log(apply(dens, 1, sum)))
    return(loglik)
  }

[Package UEM version 0.3-1 Index]