| d_cmm_sample | R Documentation |
Compute individual density contributions for
\bm{X}_i \sim \textrm{CMM}_k(m_i, \bm{p}_i, ν_i), \quad i = 1, …, n.
d_cmm_sample(X, P, nu, take_log = FALSE, normalize = TRUE)
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 |
|
normalize |
|
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.
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}.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.