Title: | Robust Bayesian Linear Mixed-Effects Models using ABC |
---|---|
Description: | Bayesian robust fitting of linear mixed effects models through weighted likelihood equations and approximate Bayesian computation as proposed by Ruli et al. (2017) <arXiv:1706.01752>. |
Authors: | Erlis Ruli [aut, cre], Nicola Sartori [aut], Laura Ventura [aut] |
Maintainer: | Erlis Ruli <[email protected]> |
License: | GPL-2 |
Version: | 0.1.3 |
Built: | 2024-11-22 06:53:25 UTC |
Source: | CRAN |
The ergoStool
data frame has 36 rows and 3 columns.
This data frame contains the following columns:
a numeric vector giving the effort (Borg scale) required to arise from a stool.
a factor with levels
T1
,
T2
,
T3
, and
T4
giving the stool type.
an ordered factor giving a unique identifier for the subject in the experiment.
Devore (2000) cites data from an article in Ergometrics (1993, pp. 519-535) on “The Effects of a Pneumatic Stool and a One-Legged Stool on Lower Limb Joint Load and Muscular Activity.”
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.9)
Devore, J. L. (2000), Probability and Statistics for Engineering and the Sciences (5th ed), Duxbury, Boston, MA.
Computes the Highest Posterior Density (HPD) interval from a posterior sample. Works only for scalar marginal posteriors.
hpd(x, prob = 0.95)
hpd(x, prob = 0.95)
x |
a univariate or a posterior sample for a scalar parameter. |
prob |
posterior probability content. |
vector of two doubles.
Performs Full Significance Bayesian Testing (FSBT) for univariate sharp
null hypothesis based on a posterior sample. The marginal posterior density is obtained by kernel density estimation from sim.sample
.
kdeFSBT(H0, sim.sample)
kdeFSBT(H0, sim.sample)
H0 |
a scalar value under the null hypothesis. |
sim.sample |
a sample from the marginal posterior distribution. |
double
Pereira, C. A. d. B., Stern, J. M. and Wechsler, S. (2008) Can a significance test be genuinely Bayesian? Bayesian Analysis 3, 79-100.
x <- rnorm(1000, 0, 1) kdeFSBT(-1, x)
x <- rnorm(1000, 0, 1) kdeFSBT(-1, x)
This function fits robust Bayesian LMMs to data via robust REML estimating functions. The latters are those proposed by Richardson & Welsh (1995), which are robustified versions of restricted maximum likelihood (REML) estimating equations. Posterior sampling is done with an ABC-MCMC algorithm, where the data are summarised through a rescaled version of the aforementioned estimating functions; see Ruli et al. (2017) for the properties and details of the method. The current package version (0.1.2) supports only models with a single random effects. Extensions to more general settings will be provided in the future versions of the package.
rblme(nabc, h.obj, chain.control = list(trace.init = NULL, thin.by = NULL), n.cores = 1)
rblme(nabc, h.obj, chain.control = list(trace.init = NULL, thin.by = NULL), n.cores = 1)
nabc |
number of posterior samples. |
h.obj |
list of objects as returned by the |
chain.control |
parameters that control the tracing and the thinning of the chain(s). |
n.cores |
number of cores for parallel computation on non Windows machines. For |
list or list of lists with elements abc
and effi
. In case of n.cores
=1, effi
is the actual acceptance rate of the ABC-MCMC algorithm whereas in abc
are stored the posterior samples. The latters are stored as a nabc matrix, where
is the number of fixed effects, i.e. the number of columns in the design matrix and
is the number of variance components. Hence, the first
rows of the matrix
abc
give the posterior samples for the fixed effects and the last two rows give the posterior samples for the log-variances of the fixed effects and the residual term, respectively. If n.cores
> 1, i.e. if simulations are performed in parallel, then a list of lists is returned, where each element of the list is a list with elements abc
and effi
, where abc
and effi
are as those aforementioned.
Ruli E., Sartori N. & Ventura L. (2017) Robust approximate Bayesian inference with an application to linear mixed models. https://arxiv.org/abs/1706.01752
Richardson A. M. & Welsh A. H. (1995) Robust restricted maximum likelihood in mixed linear models. Biometrics 51, 1429-1439.
## The following example is meant for function documentation. ## For realistic use probably you'll need to take a larger sample and choose a ## "better" bandwidth h. data(ergoStool) require(lme4) fm1 <- lmer(effort~Type + (1| Subject), data = ergoStool) ## tune h to get 0.8% acceptance hopt <- tune.h(effort~Type + (1|Subject), data = ergoStool, n.samp = 1e+4, acc.rate = 0.01, n.sim.HJ = 100, grid.h = seq(0.3, 0.7, len = 3), prior = list(beta.sd = 10, s2.scale = 5), n.cores = 1) ## draw posterior samples with hopt. abc.tmp <- rblme(nabc = 1e+4, h.obj = hopt, n.cores = 1) # process ABC samples abc.sim <- t(abc.tmp$abc) abc.sim[,c(5,6)] <- exp(abc.sim[,c(5,6)]) # ABC posterior colMeans(abc.sim) # REML estimates summary(fm1)
## The following example is meant for function documentation. ## For realistic use probably you'll need to take a larger sample and choose a ## "better" bandwidth h. data(ergoStool) require(lme4) fm1 <- lmer(effort~Type + (1| Subject), data = ergoStool) ## tune h to get 0.8% acceptance hopt <- tune.h(effort~Type + (1|Subject), data = ergoStool, n.samp = 1e+4, acc.rate = 0.01, n.sim.HJ = 100, grid.h = seq(0.3, 0.7, len = 3), prior = list(beta.sd = 10, s2.scale = 5), n.cores = 1) ## draw posterior samples with hopt. abc.tmp <- rblme(nabc = 1e+4, h.obj = hopt, n.cores = 1) # process ABC samples abc.sim <- t(abc.tmp$abc) abc.sim[,c(5,6)] <- exp(abc.sim[,c(5,6)]) # ABC posterior colMeans(abc.sim) # REML estimates summary(fm1)
Tunes the bandwidth of the ABC distance to get the desired level of acceptance rate specified via
acc.rate
. Besides tuning , the function also builds the relevant quantities needed for running
rblme
. For generating such quantities an internal call to lmer
is performed.
tune.h(formula, data, ..., n.samp = 1e+5, n.sim.HJ = 500, acc.rate, grid.h, prior, cHub = 1.345, cHub2 = 2.07, init, n.cores = 1, use.h)
tune.h(formula, data, ..., n.samp = 1e+5, n.sim.HJ = 500, acc.rate, grid.h, prior, cHub = 1.345, cHub2 = 2.07, init, n.cores = 1, use.h)
formula |
two-sided linear formula object describing the
fixed-effects part of the model, with the response on the left of
a |
data |
optional data frame containing the variables named
in |
... |
other arguments to be passed to |
n.samp |
number of pilot posterior samples to be drawn with ABC for each value of |
n.sim.HJ |
number of simulations to be used for computing the sensitivity and variability matrices. |
acc.rate |
desired acceptance rate of the ABC-MCMC algorithm. |
grid.h |
grid of |
prior |
named list of user-defined prior hyper-parameters. See "Details" below. |
cHub |
tuning constant of the Huber function for the location parameter. |
cHub2 |
tuning constant of the Huber proposal 2 function for the scale parameter. |
init |
optional object to use for starting values. Currently ignored as initial values are taken from |
n.cores |
number of cores for parallel computation on non Windows machines. |
use.h |
bandwidth to be used for the ABC distance. If provided, no tuning for |
Given a specification of the formula
and data
the function calls internally rlmer
and extracts from the resulting object all the necessary quantities. Then proceeds by finding the solution of the REML II robust estimating equations (Richardson & Welsh 1995), with the REML estimate used as starting point. The sensitivity and the variability matrices are computed by simulation at the solution of the robust REML II estimating equation. Depending on whether use.h
or acc.rate
and grid.h
are specified, the function has a different behaviour. If acc.rate
and grid.h
are provided, then an adaptive step is performed in order to get an "optimal" which gives the desired acceptance rate
acc.rate
. IN particular, for each value of grid.h
, the function draws n.samp
posterior samples with the ABC-MCMC algorithm and saves the resulting acceptance rate. Lastly, a function is built via a smoothing spline with acceptance rates being the s and
grid.h
being the s. The "optimal" value of
is found, within
grid.h
, as the prediction the spline function at acc.rate
. If you already have an value in mind then specify it via
use.h
and leave grid.h
and acc.rate
unspecified. Note that, in this case the acceptance rate of the ABC-MCMC algorithm may not be the one you wish to obtain since it depends in some complicated way also from . Currently, the prior for the
fixed effects is the product of
scalar normals with mean zero and user-specified variance
beta.sd
(see Examples) equal for all the parameters. For the variance components the prior is a halfCauchy with user-specified scale s2.scale
. Both variance parameters are assumed to have equal prior scale.
list.
Ruli E., Sartori N. & Ventura L. (2017) Robust approximate Bayesian inference with an application to linear mixed models. https://arxiv.org/abs/1706.01752
Richardson A. M. & Welsh A. H. (1995) Robust restricted maximum likelihood in mixed linear models. Biometrics 51, 1429-1439.