robustLM_bayes: Fit a robust model, with fully Bayesian model comparisons

View source: R/robustLM_bayes.R

robustLM_bayesR Documentation

Fit a robust model, with fully Bayesian model comparisons

Description

Fits a median linear regression, with random effects (i.e., mixed-effects model) if desired, using brm and the asymmetric laplace distribution (fitting quantile = .5, i.e., median). Then fits a set of models dropping each fixed-effect term in turn, and uses bridge sampling to estimate the Bayes Factors of the full model relative to each sub-model. Returns the full model, with a data frame model$bayes_factors with each fixed effect's log (base 3) Bayes Factor.

Usage

robustLM_bayes(formula, data, ..., iter = 10000, showProgress = T, quiet = T)

Arguments

formula

Formula, as in lm(), brm() or lmer()

data

Data, as in lm() or lmer()

...

Additional arguments to pass to brm. For example, if multiple cores are available, cores=2 or more should drastically speed up performance.

iter

Number of iterations. More is better, within reasonable time constraints

showProgress

Show a small progress bar?

quiet

Logical. To show model progress, or hide it.

Details

Bridge sampling is run 5 times for each effect, and the most conservative (i.e., equivocal) of the resulting BF is returned.

These models are computationally expensive and require quite a bit of memory. Without enough memory they will likely crash the R session. Other sources of errors or crashing may be out-of-date packages, such as RcppParallel, StanHeaders, brms, bridgesampling.

While using algorighm = 'fullrank' speeds up the model (over the default algorithm = 'sampling' by a factor of over 3.5 in preliminary tests), it would be advised to fit and compare several fitting runs to assess the robustness of the resulting coefficients and Bayes Factors. In brief tests, some values have been quite consistent across fitting runs and others have not when using fullrank or meanfield; in general, waiting for sampling provides the most robust estimates.

See Also

brm, bayes_factor, and brmsfamily.

Examples

## Not run: 
# This fairly simple example takes about 160 seconds on a fairly good computer.
m <- robustLM_bayes(mot ~ ufov * enum, dat_cochraneEtAl_2019_PLOSOne) 

m$bayes_factors

## End(Not run)

akcochrane/ACmisc documentation built on Nov. 24, 2024, 11:22 a.m.