loglik_mult: Extract log-likelihood from a mixture of multinomials

Description Usage Arguments Value Examples

View source: R/utility_functions.R

Description

Extract log-likelihood from a mixture of multinomials

Usage

1
loglik_mult(X, Theta, Lambda = NULL, p)

Arguments

X

a matrix of dimension N (number of observation) x M (number of variables) containing multinomials observations.

Theta

matrix of dimension M x H.

Lambda

matrix of dimension H x K. Can be NULL.

p

vector containing the proportions of each cluster. Must be of dimension K (or H if Lambda is NULL).

Value

The function returns the log-likelihood of the data to the model

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
travelers <- travelers[ ,-1]
M <- ncol(travelers)
K <- 5

Theta0    <- t(dplyr::sample_n(travelers, K))
Theta0    <- Theta0 / matrix(rep(apply(Theta0, 2, sum), M), nrow = M, ncol = K, byrow = TRUE)
travelers <- as.matrix(travelers)
p0        <- rep(1 / K, K)

llh <- loglik_mult(travelers, Theta0, p = p0)
llh

LenaCarel/nmfem documentation built on Dec. 4, 2019, 12:14 p.m.