bayes_mixture {BayesMultiMode} | R Documentation |
Creating a S3 object of class bayes_mixture
Description
Creates an object of class bayes_mixture
which can subsequently be used as argument in bayes_mode()
.
This function is useful for users who want to use the mode inference capabilities of BayesMultiMode
with mixture
estimated using external software.
Usage
bayes_mixture(
mcmc,
data,
burnin = 0,
dist = NA_character_,
pdf_func = NULL,
dist_type = NA_character_,
loglik = NULL,
vars_to_keep = NA_character_,
vars_to_rename = NA_character_,
loc = NA_character_
)
Arguments
mcmc |
A matrix of MCMC draws with one column per variable, e.g. eta1, eta2, ..., mu1, mu2, etc... |
data |
Vector of observation used for estimating the model. |
burnin |
Number of draws to discard as burnin; default is |
dist |
Distribution family of the mixture components supported by
the package (i.e. |
pdf_func |
(function) Pdf or pmf of the mixture components;
this input is used only if |
dist_type |
Either |
loglik |
Vector showing the log likelihood at each MCMC draw. |
vars_to_keep |
(optional) Character vector containing the names
of the variables to keep in |
vars_to_rename |
(optional) Use for renaming variables/parameters in |
loc |
(for continuous mixtures other than Normal mixtures) String indicating the location parameter of the distribution; the latter is used to initialise the MEM algorithm. |
Value
A list of class bayes_mixture
containing:
data |
Same as argument. |
mcmc |
Matrix of MCMC draws where the rows corresponding to burnin have been discarded; |
mcmc_all |
Matrix of MCMC draws. |
loglik |
Log likelihood at each MCMC draw. |
K |
Number of components. |
dist |
Same as argument. |
pdf_func |
The pdf/pmf of the mixture components. |
dist_type |
Type of the distribution, i.e. continuous or discrete. |
pars_names |
Names of the mixture components' parameters. |
loc |
Name of the location parameter of the mixture components. |
nb_var |
Number of parameters in the mixture distribution. |
Examples
# Example with a Student t ================================================
# Constructing synthetic mcmc output
mu <- c(0.5, 6)
mu_mat <- matrix(rep(mu, 100) + rnorm(200, 0, 0.1),
ncol = 2, byrow = TRUE
)
omega <- c(1, 2)
sigma_mat <- matrix(rep(omega, 100) + rnorm(200, 0, 0.1),
ncol = 2, byrow = TRUE
)
nu <- c(5, 5)
nu_mat <- matrix(rep(nu, 100) + rnorm(200, 0, 0.1),
ncol = 2, byrow = TRUE
)
eta <- c(0.8, 0.2)
eta_mat <- matrix(rep(eta[1], 100) + rnorm(100, 0, 0.05),
ncol = 1
)
eta_mat <- cbind(eta_mat, 1 - eta_mat)
xi_mat <- matrix(0, 100, 2)
fit <- cbind(eta_mat, mu_mat, sigma_mat, nu_mat, xi_mat)
colnames(fit) <- c(
"eta1", "eta2", "mu1", "mu2",
"omega1", "omega2", "nu1", "nu2", "xi1", "xi2"
)
# sampling observations
data <- c(
sn::rst(eta[1] * 1000, mu[1], omega[1], nu = nu[1]),
sn::rst(eta[2] * 1000, mu[2], omega[2], nu = nu[2])
)
pdf_func <- function(x, pars) {
sn::dst(x, pars["mu"], pars["sigma"], pars["xi"], pars["nu"])
}
dist_type <- "continuous"
BM <- bayes_mixture(fit, data,
burnin = 50,
pdf_func = pdf_func, dist_type = dist_type,
vars_to_rename = c("sigma" = "omega"), loc = "xi"
)
# plot(BM)