# (linear) predictor as input for regression in brms

Hi Paul,

You possibly answered this questions before but I couldn’t find or remember your answer anymore. I hope not to bother you but is it possible in brms to use the outcome of a regression in a follow-up regression? Thus for example:

#1st step

# beta0, beta1 and sd1 are parameters. X and A are data.

mu1 = beta0 + beta1 * X
A ~ normal(mu1, sd1)

#2nd step

# alpha0, alpha1 and sd2 are parameters. B is data. mu1 is linear predictor from the first regression.

mu2 = alpha0 + alpha1 * mu1
B ~ normal(mu2, sd2)

• Operating System: OSX
• brms Version: 2.2.0

Thanks,
David

You could try the following:

``````fit1 <- brm(A ~ X, ...)
mu1 <- fitted(fit1)[, "Estimate"]
fit2 <- brm(B ~ mu1, ...)
``````

However, in this case, you through away all uncertainty in the linear predictor and just use its mean estimate per observation.

One crude way to incorporate the uncertainty in the linear predictor would be:

``````fit1 <- brm(A ~ X, ...)
fitted1 <- fitted(fit1)
mu1 <- fitted1[, "Estimate"]
sdmu1 <- fitted1[, "Est.Error"]
fit2 <- brm(B ~ me(mu1, sdmu1), ...)
``````

Thanks! I would greatly appreciate to incorporate all uncertainty. I tried to fit a non-linear model:

`bf(B ~ 1 + mu1, mu1 ~ 1 + A, nl = TRUE)`

but this is another model than I would like to fit.

`bf(A ~ X) + bf(B ~ A) + set_rescor(TRUE)`

fits the data possibly best, but I would like to use the linear predictor of bf(A ~ X) in bf(B ~ A). If this isn’t possible yet, your package is still a great help and I can adjust the stan code myself, but if this is possible with brms, I would prefer to use brms.

Thanks! I will try your other suggestion and will let you know the outcome.

The first “non-linear” model doesn’t really model the variation in `A`, but just in `B`.

``````bf(A ~ X) + bf(B ~ A) + set_rescor(TRUE)
``````

is syntactically close to what you want, but not spot on as you note correctly.

What you can always do is extract the output of

``````make_stancode(bf(A ~ X) + bf(B ~ A) + set_rescor(TRUE), ...)
``````

and amend the Stan code to your needs.

1 Like

Dear Paul,

Thanks a lot for your suggestions! Your suggestion using “fitted” worked also quite well but in the end I think that I prefer the multivariate model and to adjust the stan code slightly as this model is the model I would like to fit. Many thanks for your help, quick responses and for creating and maintaining brms!

David