Brms - non-linear model estimate parameter used within another model

Hey @benjamin_hlina , welcome!

EDIT: the following approach is incomplete because it does not handle ac as a shared parameter, as was intended. See the followup discussion here.

This worked: I separated your formula into two distinct formulas and specified the response in the priors. (I also upped the iterations to 40000.)

tp_formula <- bf(
  alpha ~ ac * (amax - amin) + amin,
  ac ~ 1,
  nl = TRUE
) + 
  bf(
    d15n ~ dn * (tp - (lambda + n1 * ac + n2 * (1 - ac))),
    ac ~ 1,
    n1 ~ 1,
    n2 ~ 1,
    tp ~ 1,
    dn ~ 1,
    nl = TRUE
  )

tp_priors <- c(
  # Beta prior for 'ac'
  brms::prior(beta(1, 1), lb = 0, ub = 1, resp = "alpha", nlpar = "ac"),
  brms::prior(beta(1, 1), lb = 0, ub = 1, resp = "d15n", nlpar = "ac"),
  # Baseline (n1)
  brms::prior(normal(8, 1), resp = "d15n", coef = "Intercept", nlpar = "n1"),
  # Baseline (n2)
  brms::prior(normal(10, 1), resp = "d15n", coef = "Intercept", nlpar = "n2"),
  # Trophic enrichment factor (ΔN)
  brms::prior(normal(3.4, 0.5), resp = "d15n", lb = 3, ub = 4, nlpar = "dn"),
  # Trophic Position (tp)
  brms::prior(uniform(2, 10), resp = "d15n", nlpar = "tp", lb = 2, ub = 10),
  # Standard deviation prior
  brms::prior(uniform(0, 10), resp = "alpha", class = "sigma"),
  brms::prior(uniform(0, 10), resp = "d15n", class = "sigma")
)

(I had to comment out problems = < pointer:0x120723a80 > , for your test data to work)

1 Like