So a while back I was interested in replicating a mediation analysis in this paper. They have written the function specified here which uses penalised splines to estimate non-linear effects of a mediator.

In short their model looks as follows;

I have implemented this in brms using the following model thanks to some help from on these forums;

```
m ~ s(t) + s(t, by = x) + (1 | id)
y ~ s(t) + s(t, by = m) + s(t, by = x) + (1 | id)
```

To calculate the percentage mediation at *t* you take the product of *a(t)B(t)*. In a simple mediation analysis this is easy, multiply the coefficients. If its a linear effect then its easy, multiple *t* by your coefficients, e.g. *(a * t) * (B * t)*. The problem is I have no idea how to achieve the same result with splines.

I was trying to cheat by using the `marginal_effects()`

. I was trying to enter zeros in the `conditions`

alongside a vector of *t* increments but I realise this isnt the same thingâ€¦

I would appreciate any assistance and will keep reading up on spline because I fell my lack of understanding there is whats part of the problemâ€¦

EDIT: Here is some sample output that might help;

```
Family: MV(gaussian, gaussian)
Links: mu = identity; sigma = identity
mu = identity; sigma = identity
Formula: y ~ s(t) + s(t, by = m) + s(t, by = x) + (1 | id)
m ~ s(t) + s(t, by = x) + (1 | id)
Data: dat (Number of observations: 375)
Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
total post-warmup samples = 4000
Smooth Terms:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sds(y_st_1) 1.20 0.92 0.22 3.48 498 1.01
sds(y_stm_1) 1.41 0.47 0.76 2.57 362 1.01
sds(y_stx_1) 1.24 0.55 0.50 2.64 388 1.01
sds(m_st_1) 3.11 1.36 1.27 6.46 436 1.01
sds(m_stx_1) 1.29 0.42 0.75 2.34 372 1.01
Group-Level Effects:
~id (Number of levels: 25)
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sd(y_Intercept) 0.88 0.15 0.65 1.20 264 1.00
sd(m_Intercept) 1.17 0.20 0.84 1.62 185 1.02
Population-Level Effects:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
y_Intercept 0.16 0.21 -0.23 0.60 215 1.03
m_Intercept 0.13 0.25 -0.37 0.62 87 1.04
y_st_1 1.36 0.48 0.26 2.25 346 1.01
y_st:m_1 0.55 0.17 0.21 0.92 191 1.04
y_st:m_2 0.48 0.25 -0.05 0.92 200 1.02
y_st:x_1 0.74 0.43 -0.15 1.52 214 1.02
y_st:x_2 0.47 0.54 -0.61 1.63 177 1.05
m_st_1 0.05 0.59 -1.13 1.22 665 1.00
m_st:x_1 0.46 0.05 0.36 0.56 808 1.00
m_st:x_2 0.20 0.07 0.08 0.33 614 1.01
Family Specific Parameters:
Estimate Est.Error l-95% CI u-95% CI Eff.Sample Rhat
sigma_y 1.02 0.04 0.95 1.10 1212 1.00
sigma_m 0.96 0.04 0.89 1.04 1361 1.00
```

TL:DR - How do I calculate *a(t)B(t)* when I am using splines in the above equation ?

- Operating System: W10
- brms Version: 2.6