Skip to main content
. Author manuscript; available in PMC: 2020 Aug 1.
Published in final edited form as: J Math Psychol. 2019 May 20;91:128–144. doi: 10.1016/j.jmp.2019.04.004

Table 1:

A comparison between the key equations in DP and how they can be implemented in R. The last column covers the primary R functions that carry out the calculations. The newly observed data entry is evaluated by the dmvnormO function to obtain its log density, given appropriate input parameters for the predictive distributions. Readers who prefer a different computer programming language may use these to guide their implementation.

Equations for DP Line(s) R code
ni,kn1+αN(y~i;yknkτk+μ0τ0nkτk+τ0,1nkτk+τ0+σy2)
Equation (12)
108 – 110 mean_p <- sig_p %*% (tau_y %*% sum_data +
tauO %*% t(muO))
logp[c_i] <- log(n_k[c_i]) + dmvnorm(data[n,],
mean = mean_p, sigma = sig_p + sigma_y, log = TRUE)
αn1+αN(y~i;μ0,σ02+σy2)
Equation (13)
117 – 118 logp[ Nclust+1 ] >- log(alpha) + dmvnorm(data[n,] ,
mean mu0, sigma = sigma0 + sigma_y, log = TRUE)