Get the difference between two conditions in the raw scale from a model with a lognormal likelihood

Incidentally a somewhat related conversation over here:

led to creation of an early draft brmsmargins package on github. Once installed, you could get what you want using:

library(brmsmargins)

## AME for two specific trials (0, 1)
marg <- brmsmargins(
  fit_press_trial,
  at = data.frame(c_trial = c(0, 1)),
  contrasts = cbind(
    "Estimate c_trial = 0" = c(1, 0),
    "Estimate c_trial = 1" = c(0, 1),
    "Estimate c_trial 1 - 0" = c(-1, 1)),
  CI = 0.95, CIType = "HDI")
marg$ContrastSummary

##              M          Mdn           LL          UL PercentROPE PercentMID
##1: 168.26971114 168.26542263 166.14610932 170.4999232          NA         NA
##2: 168.35775319 168.35455232 166.15603648 170.5090509          NA         NA
##3:   0.08804205   0.08793096   0.06797247   0.1081785          NA         NA
##     CI CIType ROPE  MID                  Label
##1: 0.95    HDI <NA> <NA>   Estimate c_trial = 0
##2: 0.95    HDI <NA> <NA>   Estimate c_trial = 1
##3: 0.95    HDI <NA> <NA> Estimate c_trial 1 - 0

This gives you the contrast, on the original metric between c_trial 0 and 1.
Or if you want more of an average marginal effect of the slope, you can use numerical derivatives as below. In this instance, they are fairly trivially different, but may be of use.

## AME for the numerical derivative
marg2 <- brmsmargins(
  fit_press_trial,
  add = data.frame(c_trial = c(0, 1e-5)),
  contrasts = cbind(
    "Estimate AME for slope of c_trial " = c(-1/1e-5, 1/1e-5)),
  CI = 0.95, CIType = "HDI")

marg2$ContrastSummary
##            M        Mdn         LL        UL PercentROPE PercentMID   CI
##1: 0.08815504 0.08803763 0.06801887 0.1083883          NA         NA 0.95
##   CIType ROPE  MID                              Label
##1:    HDI <NA> <NA> Estimate AME for slope of c_trial 

Note that both these solutions would marginalize over the sample distribution of covariates, if you had any covariates.

2 Likes