NegBetaLogLike: Compute the (negative) log-likelihood of a mixture of betas

View source: R/01-betamix.R

NegBetaLogLikeR Documentation

Compute the (negative) log-likelihood of a mixture of betas

Description

Compute the (negative) log-likelihood of a mixture of beta distributions for a given set of observations. We take the negative in order to use the function in a call to nlm, which minimizes the objective function, when we actually want to compute the maximum likelihood.

Usage

NegBetaLogLike(param, vec, z)

Arguments

param

A vector of parameters of length 2K

vec

A data vector of length N

z

A matrix of size NxK of nonegative real numbers, with the sum of each row equal to 1.

Author(s)

Kevin R. Coombes krc@silicovore.com

Examples

set.seed(73892)
datavec <- c(rbeta(30, 1, 4),
             rbeta(70, 7, 4)) # mixture of two betas

# randomly initialize Z
temp <- sample(2, 100, replace = TRUE)
Z <- matrix(0, nrow = 100, ncol = 2)
for (I in 1:100) Z[I, temp[I]] <- 1

# initialize parameters (2 identical components)
initparam <- rep(1/2, 4)
NegBetaLogLike(initparam, datavec, Z)

# use true parameters
NegBetaLogLike(c(1, 4, 7, 4), datavec, Z)

BetaModels documentation built on Feb. 9, 2024, 3:01 a.m.