brm_optimizing: Maximum-likelihood fitting of a brm-style model

View source: R/brm_optimizing.R

brm_optimizingR Documentation

Maximum-likelihood fitting of a brm-style model

Description

Maximum-likelihood fitting of a brm-style model

Usage

brm_optimizing(
  formula = NA,
  data = NA,
  ...,
  iter = 2000,
  brmModel = NA,
  strata = NA,
  crossvals = 0,
  bootstrap = NA,
  refresh = 0
)

Arguments

formula

Model formula

data

Model data

...

Additional arguments to pass to an initial brm model

iter

Number of iterations. If strata == NA then this is draws from a normal approximation (inverse Hessian); if strata != NA then this is the number of bootstrap samples.

brmModel

An initial brm model to re-fit using maximum-likelihood.

strata

The strata to use in resampling; a vector the length of the data set's rows. If all values are equal, no stratification is used in resampling

crossvals

Number of cross-validations [currently not implemented]

bootstrap

Bootstrapping is done by default if strata is provided. However, in certain cases (e.g., if cross-validation is desired but bootstrapping is not), bootstrapping can be turned off by setting bootstrap = F

refresh

Should progress be printed?

Use optimizing fit a brm-style model.

This function is an attempt to merge the usability and flexibility of brm and the [potential] efficiency of optimizing. This may be useful in various circumstances, for example, when desiring a direct comparison between Bayesian and maximum-likelihood methods (e.g., to give an indication of the influence of priors), or when other methods are problematically computationally expensive. While it is always recommended to use brm with algorithm = 'sampling', preferably checking robustness to priors and model specification through model comparison, sometimes this ideal is not going to be feasible. The current function provides maximum-likelihood estimation with a brm-like interface.

Several major limitation persists, however. One limitation is that sampling methods inherently provide distributions of parameters whereas maximum-likelihood methods do not. The simplest solution to this would be using the Hessian of the optimization, but this matrix is not always well-behaved. A potentially more robust solution is to bootstrap the model (i.e., in principle, draw parameters from their sampling distribution by resampling data with replacement and re-fitting the model), but this leads to the second limitation. As of now the implementation of brm_optimizing is apt to crash the R session with repeated calls or with very large models/datasets; bootstrapping as well as robustness checks of point estimates are necessary to fully interpret maximum-likelihood fits, but these are limited when R is apt to crash.

In summary, the user is advised to proceed with caution. Repeated maximum-likelihood fitting and bootstrapping are likely to be the most beneficial applications of this method, but the current implementation is somewhat unstable for these applications.

Note

Most errors and warnings can be ignored; they are likely do due hiccups in the pipeline that do not influence the final outcome. The error Error in chol.default(-H) indicates that the Hessian was ill-behaved and direct approximations of the estimates' standard errors were likely impossible. As long as the resulting object contains Est.Error and CI, however, it is likely that at least one estimation run allowed for these approximations.

Examples


m1 <- brm_optimizing(Sepal.Width ~ Sepal.Length * Petal.Width + (1|Species),iris)

    m_cv_1 <- brm_optimizing(Sepal.Width ~ Sepal.Length * Petal.Width + (1|Species),iris
,strata = iris$Species,iter = 500, 
bootstrap = F, crossvals = 50)
m_cv_2 <- brm_optimizing(Sepal.Width ~ Sepal.Length * Petal.Width,iris
                         ,strata = iris$Species,iter = 500, 
                         bootstrap = F, crossvals = 50)
m_cv_1$logLik_oos - m_cv_2$logLik_oos # m_cv_1 is much better! test 1, 50 crossvals: 57.7; test 2: ; test 3: 


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