BayesFactorSlope: Bayes Factor for Slope Parameters in Latent-Trait MPT

View source: R/BFslope.R

BayesFactorSlopeR Documentation

Bayes Factor for Slope Parameters in Latent-Trait MPT

Description

Uses the Savage-Dickey method to compute the Bayes factor that the slope parameter of a continuous covariate in traitMPT is zero vs. positive/negative/unequal to zero.

Usage

BayesFactorSlope(
  fittedModel,
  parameter,
  direction = "!=",
  approx = "normal",
  plot = TRUE,
  ...
)

Arguments

fittedModel

a fitted latent-trait model fitted with traitMPT with predictor variables that have been defined via predStructure.

parameter

name of the slope parameter (e.g., "slope_d_covariate").

direction

alternative hypothesis: whether slope is smaller or larger than zero ("<" or ">") or unequal to zero ("!=").

approx

how to approximate the posterior density of the slope parameter at zero: approx="normal" uses a normal approximation to all samples and approx="logspline" uses a nonparametric density estimate of the package logspline. Usually, both methods provide similar results.

plot

if TRUE, the prior and posterior densities and the ratio at slope=0 are plotted.

...

further arguments passed to logspline, which is used to approximate the density of the posterior distribution.

Details

The Bayes factor is computed with the Savage-Dickey method, which is defined as the ratio of the density of the posterior and the density of the prior evaluated at slope=0 (Heck, 2019). Note that this method cannot be used with default JZS priors (IVprec="dgamma(.5,.5)") if more than one predictor is added for an MPT parameter. As a remedy, a g-prior (normal distribution) can be used on the slopes by setting the hyperprior parameter g to a fixed constant when fitting the model: traitMPT(..., IVprec = 1) (see Heck, 2019).

References

Heck, D. W. (2019). A caveat on the Savage-Dickey density ratio: The case of computing Bayes factors for regression parameters. British Journal of Mathematical and Statistical Psychology, 72, 316–333. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/bmsp.12150")}

Examples

## Not run: 
# latent-trait MPT model for the encoding condition (see ?arnold2013):
EQNfile <- system.file("MPTmodels/2htsm.eqn", package = "TreeBUGS")
d.enc <- subset(arnold2013, group == "encoding")

fit <- traitMPT(EQNfile,
  data = d.enc[, -(1:4)], n.thin = 5,
  restrictions = list("D1=D2=D3", "d1=d2", "a=g"),
  covData = d.enc[, c("age", "pc")],
  predStructure = list("D1 ; age")
)
plot(fit, parameter = "slope", type = "default")
summary(fit)

BayesFactorSlope(fit, "slope_D1_age", direction = "<")

## End(Not run)

TreeBUGS documentation built on May 31, 2023, 9:21 p.m.