I am struggling with how to program a simple latent mixture model in JAGS. I have a vector of 10 data points and I want to model the data as either coming from a normal distribution or a beta distribution. I want to simultaneously estimate the posterior densities of the parameters of each model, while estimating the probability that the data came from each model:

Ideally, I would like to model the data as:

Data[i] ~ dt(mu, sd, df)*equals(Model.Index, 0) + dbeta(alpha, beta) * equals(Model.Index, 1)

Where Model.Index is a bernoulli indicator variable. But this syntax is not JAGS friendly.

I have included sample code (from R) below. If someone could help me fix the code such that it would allow me to estimate both model parameters and the probability of each model that would be great!

### Start Sample R Code

library("R2jags")

Data <- rnorm(10, .5, .1)

Model.String <- "

model{

for (i in 1:10) {

# This is what I want to do: calculate the likelihood of the data depending on whether Model = 0 (the student t model), or Model = 1 (the beta model)

# Data[i] ~ dt(mu, sd, df)*equals(Model.Index, 0) + dbeta(alpha, beta) * equals(Model.Index, 1)

# But JAGS doesn't like this

# These work individually, but How do I get JAGS to estimate the probability of either model?

Data[i] ~ dt(mu, sd, df)T(0,1)

# Data[i] ~ dbeta(alpha, beta)

}

Model.Index ~ dbern(.5)

mu ~ dnorm(0, .001)

sd ~ dgamma(.001, .001)

df ~ dgamma(.001, .001)

alpha ~ dunif(0, 100)

beta ~ dunif(0, 100)

}

"

writeLines(Model.String, con = "model.txt")

data <- list("Data")

parameters.to.monitor <- c("mu", "sd", "df", "Model.Index", "alpha", "beta")

samples <- jags(data, parameters.to.save = parameters.to.monitor, model.file = "model.txt", n.chains = 1, n.iter = 100, n.burnin = 1, n.thin = 1, DIC = T)