Learn R Programming

RoBMA (version 4.0.0)

hatvalues.brma: Hat Values for brma Objects

Description

Computes hat values (leverages) from a fitted brma object. Returns posterior mean leverages, one for each observation.

Usage

# S3 method for brma
hatvalues(model, ...)

Value

A numeric vector of length K, one posterior mean leverage per observation.

Arguments

model

a fitted brma object

...

additional arguments (currently ignored)

Details

Hat values (leverages) measure the influence of each observation on the fitted values. In a Bayesian meta-analysis, the random effects variance \(\tau^2\) is uncertain, so the hat matrix depends on the posterior samples of \(\tau^2\).

This function computes the diagonal elements of the hat matrix: $$h_i = (X (X^T W X)^{-1} X^T W)_{ii}$$ where \(W\) is the weight matrix inverse to the marginal variance matrix.

The hat matrix is computed for each posterior draw and then averaged over draws, matching the vector output shape used by metafor.

This method is available only for normal outcome models without weightfunction selection.

Examples

Run this code
if (FALSE) {
if (requireNamespace("metadat", quietly = TRUE) &&
    requireNamespace("metafor", quietly = TRUE)) {
  data(dat.bcg, package = "metadat")
  dat <- metafor::escalc(
    measure = "RR",
    ai      = tpos,
    bi      = tneg,
    ci      = cpos,
    di      = cneg,
    data    = dat.bcg
  )

  fit <- brma(yi = yi, vi = vi, data = dat, measure = "RR")
  hatvalues(fit)
}
}

Run the code above in your browser using DataLab