Description Usage Arguments Details Value Examples

Set up a finite mixture family for use in brms.

1 |

`...` |
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 |

`flist` |
Optional list of objects, which are treated in the
same way as objects passed via the |

`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 |

`order` |
Ordering constraint to identify mixture components.
If |

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.

Ordering intercepts in mixtures of ordinal families is not possible as each family has itself a set of vector of intercepts (i.e. ordinal thresholds). Instead, brms will fix the vector of intercepts across components in ordinal mixtures, if desired, so that users can try to identify the mixture model via selective inclusion of predictors.

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`

.

An object of class `mixfamily`

.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | ```
## 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, dpar = mu1),
prior(normal(5, 7), Intercept, dpar = 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)
## End(Not run)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.