sampler_CRP error

17 views
Skip to first unread message

Cody Chen

unread,
Oct 8, 2025, 12:32:08 AMOct 8
to nimble-users
Hi all,

I encountered the following error message while implementing a DP mixture model using the Chinese restaurant process:

sampler_CRP: Variables being clustered must be conditionally independent. To model dependent variables being clustered jointly, you may use a multivariate distribution.

I didn't have this issue when using the stick-breaking construction. I'm curious about what caused this error. Is this a limitation of CRP or a functionality currently unavailable in NIMBLE? Any explanation would be appreciated. Thank you very much.

model <- nimbleCode({
  #===========================
  # model specification
  #===========================
  for (i in 1:N) {
    for(t in 1:Time) {
      # model the growth curve
      y[i,t] ~ dnorm(muy[i,t], var = sig2[z[i],t])
      muy[i,t] <- LS[i,1] + (t-1)*LS[i,2]
    }
    LS[i,1:2] ~ dmnorm(muLS[z[i],1:2], cov = cov_b[z[i],1:2,1:2])
  }
  #===========================
  # prior specification
  #===========================
  # --------- CRP ---------
  z[1:N] ~ dCRP(conc = alpha, size = N)
  # --------- alpha ---------
  alpha ~ dgamma(2, 2)
  # --------- muLS ---------
  for (i in 1:N) {
    muLS[i,1] ~ dnorm(0, var = 1000) # Intercept
    muLS[i,2] ~ dnorm(0, var = 1000) # Slope
    # --------- Cov_b ---------
    cov_b[i,1:2,1:2] ~ dinvwish(R[1:2,1:2],2)
    # --------- sig2 ---------
    for(t in 1:Time) {
      sig2[i,t] ~ dinvgamma(1,1)
    }
  }
})



Best,
Cody

Chris Paciorek

unread,
Oct 9, 2025, 11:03:41 AMOct 9
to Cody Chen, nimble-users
Hi Cody,

There are some Bayesian nonparametric model structures that our CRP-based sampling wouldn't sample correctly, so we have some checks in place to prevent use of the sampler in those cases. (In some cases, the checking may be a bit conservative.) In this case the 'problem' is coming from you trying to cluster the `sig2` values as well as the {`muLS`,`cov_b`} values. The CRP sampler does some calculations with the nodes that are dependent on the clustering variable (`z`) that are not set up to handle the complexity in this situation.

Our MCMC sampler assignment for the stickbreaking representation doesn't use the CRP sampling, which is why you don't see the issue there.

-chris

--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/nimble-users/6dac2144-57d4-4d9e-a0a4-9927cdec9fe1n%40googlegroups.com.

Cody Chen

unread,
Oct 9, 2025, 6:09:42 PMOct 9
to paci...@stat.berkeley.edu, nimble-users
Thank you so much, Chris. Your explanation is very helpful. I appreciate it.


Best,
Cody
Reply all
Reply to author
Forward
0 new messages