# mixture

0th

Percentile

##### Finite Mixture Families in brms

Set up a finite mixture family for use in brms.

##### Usage
mixture(..., flist = NULL, nmix = 1, order = NULL)
##### Arguments
...

One or more objects providing a description of the response distributions to be combined in the mixture model. These can be family functions, calls to family functions or character strings naming the families. For details of supported families see brmsfamily.

flist

Optional list of objects, which are treated in the same way as objects passed via the ... argument.

nmix

Optional numeric vector specifying the number of times each family is repeated. If specified, it must have the same length as the number of families passed via ... or flist.

order

Ordering constraint to identify mixture components. If 'mu' or TRUE, population-level intercepts of the mean parameters are ordered. If 'none' or FALSE, no ordering constraint is applied. If NULL (the default), order is set to 'mu' if all families are the same and 'none' otherwise. Other ordering constraints may be implemented in the future.

##### Details

Most families supported by brms can be used to form mixtures. The response variable has to be valid for all components of the mixture family. Currently, the number of mixture components has to be specified by the user. It is not yet possible to estimate the number of mixture components from the data.

For most mixture models, you may want to specify priors on the population-level intercepts via set_prior to improve convergence. In addition, it is sometimes necessary to set inits = 0 in the call to brm to allow chains to initialize properly.

For more details on the specification of mixture models, see brmsformula.

##### Value

An object of class mixfamily.

• mixture
##### Examples
# NOT RUN {
## simulate some data
set.seed(1234)
dat <- data.frame(
y = c(rnorm(200), rnorm(100, 6)),
x = rnorm(300),
z = sample(0:1, 300, TRUE)
)

## fit a simple normal mixture model
mix <- mixture(gaussian, gaussian)
prior <- c(
prior(normal(0, 7), Intercept, nlpar = mu1),
prior(normal(5, 7), Intercept, nlpar = mu2)
)
fit1 <- brm(bf(y ~ x + z), dat, family = mix,
prior = prior, chains = 2)
summary(fit1)
pp_check(fit1)

## use different predictors for the components
fit2 <- brm(bf(y ~ 1, mu1 ~ x, mu2 ~ z), dat, family = mix,
prior = prior, chains = 2)
summary(fit2)

## fix the mixing proportions
fit3 <- brm(bf(y ~ x + z, theta1 = 1, theta2 = 2),
dat, family = mix, prior = prior,
inits = 0, chains = 2)
summary(fit3)
pp_check(fit3)

## predict the mixing proportions
fit4 <- brm(bf(y ~ x + z, theta2 ~ x),
dat, family = mix, prior = prior,
inits = 0, chains = 2)
summary(fit4)
pp_check(fit4)

## compare model fit
LOO(fit1, fit2, fit3, fit4)
# }
# NOT RUN {
# }

Documentation reproduced from package brms, version 1.10.0, License: GPL (>= 3)

### Community examples

Looks like there are no examples yet.