Bayesian estimation of a log - normal hierarchical model
Bayesian estimation of a log - normal hierarchical model
Function that estimates a log-normal linear mixed model with GIG priors on the variance components, in order to assure the existence of the posterior moments of key functionals in the original data scale like conditioned means or the posterior predictive distribution.
formula_lme: A two-sided linear formula object describing both the fixed-effects and random-effects part of the model is required. For details see lmer.
data_lme: Optional data frame containing the variables named in formula_lme.
y_transf: Logical. If TRUE, the response variable is assumed already as log-transformed.
functional: Functionals of interest: "Subject" for subject-specific conditional mean, "Marginal" for the overall expectation and "PostPredictive" for the posterior predictive distribution.
data_pred: Data frame with the covariate patterns of interest for prediction. All the covariates present in the data_lme object must be included. If NULL the design matrix of the model is used.
order_moment: Order of the posterior moments that are required to be finite.
nsamp: Number of Monte Carlo iterations.
par_tau: List of vectors defining the triplets of hyperparaemters for each random effect variance (as many vectors as the number of specified random effects variances).
par_sigma: Vector containing the tiplet of hyperparameters for the prior of the data variance.
var_pri_beta: Prior variance for the model coefficients.
inits: List of object for initializing the chains. Objects with compatible dimensions must be named with beta, sigma2 and tau2.
verbose: Logical. If FALSE, the messages from the Gibbs sampler are not shown.
burnin: Number of iterations to consider as burn-in.
n_thin: Number of thinning observations.
Returns
The output list provided is composed of three parts. The object $par_prior contains the parameters fixed for the variance components priors. The object $samples contains the posterior samples for all the paramters. They are returned as a mcmc object and they can be analysed trough the functions contained in the coda package in order to check for the convergence of the algorithm. Finally, in $summaries an overview of the posteriors of the model parameters and of the target functionals is provided.
Details
The function allows to estimate a log-normal linear mixed model through a Gibbs sampler. The model equation is specified as in lmer model and the target functionals to estimate need to be declared. A weakly informative prior setting is automatically assumed, always keeping the finiteness of the posterior moments of the target functionals.
Examples
library(BayesLN)# Load the dataset included in the packagedata("laminators")data_pred_new <- data.frame(Worker = unique(laminators$Worker))Mod_est<-LN_hierarchical(formula_lme = log_Y~(1|Worker), data_lme = laminators, data_pred = data_pred_new, functional = c("Subject","Marginal"), order_moment =2, nsamp =50000, burnin =10000)