# NOT RUN {
## simulate some data
set.seed(1234)
dat <- data.frame(
y = c(rnorm(100), rnorm(50, 2)),
x = rnorm(150)
)
## fit a simple normal mixture model
mix <- mixture(gaussian, nmix = 2)
prior <- c(
prior(normal(0, 5), Intercept, nlpar = mu1),
prior(normal(0, 5), Intercept, nlpar = mu2),
prior(dirichlet(2, 2), theta)
)
fit1 <- brm(bf(y ~ x), dat, family = mix,
prior = prior, chains = 2, inits = 0)
summary(fit1)
## compute the membership probabilities
ppm <- pp_mixture(fit1)
str(ppm)
## extract point estimates for each observation
head(ppm[, 1, ])
## classify every observation according to
## the most likely component
apply(ppm[, 1, ], 1, which.max)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab