d_cmm_sample: Density for CMM random sample

View source: R/RcppExports.R

d_cmm_sampleR Documentation

Density for CMM random sample

Description

Compute individual density contributions for

\bm{X}_i \sim \textrm{CMM}_k(m_i, \bm{p}_i, ν_i), \quad i = 1, …, n.

Usage

d_cmm_sample(X, P, nu, take_log = FALSE, normalize = TRUE)

Arguments

X

An n \times k matrix of outcomes, where the ith row \bm{x}_i^\top represents the ith observation.

P

An n \times k matrix, where the ith row \bm{p}_i^\top represents the probability parameter for the ith observation.

nu

An n-dimensional vector of dispersion parameters ν_1, …, ν_n

take_log

TRUE or FALSE; if TRUE, return the value on the log-scale.

normalize

TRUE or FALSE; if FALSE, do not compute or apply the normalizing constant to each density value.

Details

The entire computation for this function is done in C++, and therefore may be more efficient than calling d_cmm in a loop from R.

Value

A vector of density values f(\bm{x}_1^\top \mid m_1, \bm{p}_1^\top, ν_1), …, f(\bm{x}_n^\top \mid m_n, \bm{p}_n^\top, ν_n), which may be on the log-scale and/or unnormalized according to input arguments. The value of each m_i is assumed to be ∑_{j=1}^k x_{ij}.

Examples

set.seed(1234)

n = 20
m = rep(10, n)
k = 3

x = rnorm(n)
X = model.matrix(~ x)
beta = matrix(NA, 2, k-1)
beta[1,] = -1
beta[2,] = 1
P = t(apply(X %*% beta, 1, inv_mlogit))

w = rnorm(n)
W = model.matrix(~ x)
gamma = c(1, -0.1)
nu = X %*% gamma

y = matrix(NA, n, k)
for (i in 1:n) {
    y[i,] = r_cmm(1, m[i], P[i,], nu[i], burn = 200)
}

d_cmm_sample(y, P, nu, take_log = TRUE)


andrewraim/COMMultReg documentation built on April 2, 2022, 11:04 p.m.