simple_effects: Calculate Simple Effects

simple_effectsR Documentation

Calculate Simple Effects

Description

Calculate the effect of a focal variable at different levels of a moderator. For categorical focal variables, it calculates pairwise differences (contrasts). For continuous focal variables, it calculates the slope (simple slopes).

Usage

simple_effects(
  fit,
  effect,
  prob = 0.95,
  sd_multiplier = 1,
  sd_slice = NULL,
  ...
)

Arguments

fit

Model fit object (e.g., 'map_fit', 'mcmc_fit').

effect

Character string of the interaction (e.g., "A:B"). The first variable is the focal variable.

prob

Probability for the credible/confidence interval (default is 0.95).

sd_multiplier

Multiplier for SD for continuous moderators (default is 1).

sd_slice

Logical or NULL. If TRUE, continuous moderators are evaluated at mean - SD, mean, and mean + SD. If FALSE, all observed moderator values are used. If NULL (default), sd slicing is used automatically when the moderator has 6 or more unique values.

...

Additional arguments.

Value

A 'ce_simple' object (data frame) containing the estimated effects and their credible intervals. For 'Classic_Fit' objects, test columns ('df', 't value', and 'Pr') are also returned when standard errors are available.

Examples


  data(debate, package = "BayesRTMB")
  fit <- rtmb_lm(sat ~ talk * perf, data = debate)
  map_fit <- fit$optimize()
  # Effect of talk at different levels of performance
  se <- simple_effects(map_fit, effect = "talk:perf")
  print(se)


BayesRTMB documentation built on Nov. 24, 2026, 9:06 a.m.