Returns priors in the form bnec accepts them, either from a fit
that has already been run or from a formula and data before anything is
fitted.
get_priors(object, ...)
# S3 method for class 'formula'
get_priors(
object,
data,
family = NULL,
prior_type = "uninformative",
asymptote_observed = TRUE,
model_survival = NULL,
predictor_scale = "auto",
x_control = NULL,
...
)An object of class bayesnecfit or
bayesmanecfit as returned by bnec, or
bayesnechurdlefit as returned by bnec_hurdle;
or a bayesnecformula, a formula or a
character string that can be coerced to one. A grouped
fit from bnec_group returns priors by level. A
bayesnecjointfit from bnec_joint is accepted.
Class-specific arguments, including level for a grouped
fit. Other arguments are refused by fitted objects.
A data.frame containing the data referred to
by the formula.
A family function, as passed to
bnec. If NULL (the default) it is chosen from the data
the way bnec would.
A character string, either
"uninformative" (the default) or "regularizing". See
bnec.
A logical declaring whether
the highest predictor level reached the lower asymptote of the curve.
FALSE replaces the bot entry and removes the upper bound of
the nec and ec50 entries, which is how the entries a fit under
that declaration would use can be read without fitting. See
bnec.
An optional character string naming
the equation for the second block of a joint hurdle or zero-inflated fit. See
bnec.
A character string declaring
whether the predictor is supplied as "concentration", already
"log" transformed, or should use the existing "auto" rule.
See bnec.
The control concentration on the recorded predictor scale,
as in bnec. It sets the lower bound of the default
nec and ec50 priors. A regularising top prior needs an
observed response at this concentration.
For a single model, an object of class
brmsprior. For a model set, a named
list of them, one per model, named as
bnec expects a named prior list to be. For a
bayesnechurdlefit, a list of two such
objects, one per component. For a bayesnecgroupfit, a named
list of these results by level. For a bayesnecjointfit, one
brmsprior, because the levels share one fit. Where
every level was fitted one equation, each prior covers that parameter at
every level, and the object can be passed back to bnec_joint
through prior. Where the levels were fitted different equations, it
names each level's own parameters, as print() on the fit describes,
and bnec_joint does not accept it.
Two entry points, answering two different questions.
Given a fit, get_priors returns the priors that fit actually
used, including any the user overrode. This is the record of what was run:
bnec(formula, data = data, prior = get_priors(fit)) reproduces the same
model.
Given a formula and data, it returns the priors bnec
would generate, without fitting anything, so they can be inspected and edited
before the first run. The family is chosen from the data exactly as
bnec would unless one is supplied, and models invalid for it are
dropped with the same message.
The two can disagree, and that is the point of having both: once a prior has been overridden, the fit's priors are no longer the ones the defaults would produce. Given the same formula, data and family, and no user prior, they agree.
What is returned is the population-level priors on the parameters of the
model's own non-linear formula, which are the ones bnec accepts
through prior. Where a disp term adds a variance function on the
fitted mean – disp("power") and the other named forms – its
parameters (c0, c1, ...) belong to that formula and come back
with the curve parameters. They are needed: bnec takes a
supplied prior whole, so a set handed back without them leaves brms to
put a flat prior on each, which is a different model. See
bayesnecformula.
What is left to brms and its defaults, and so is not returned from a
formula, is the family's own dispersion parameter (sigma,
shape, phi) where dispersion is held constant, and the
linear predictor of a disp(~x) sub-model. A prior on sigma,
shape or phi can be added to the set passed to
bnec(prior = ). It reaches brms in place of the default, the
initial value of that parameter is left to Stan, and get_priors on
the fit returns it with the curve's priors. A prior on a slope of a
disp(~x) sub-model, of class "b" with dpar set, is
refused, because the initial-value search reads it as a curve parameter
that the equation does not have.
This is why get_priors is not pull_prior, which returns
the whole brmsprior a fit carries – brms defaults, duplicated
vectorised rows and all – and is for looking at rather than for feeding back
in.
The returned priors are specific to a formula generated by bnec().
Each non-linear parameter in that formula has one population-level
coefficient, its intercept, so a prior naming the parameter and no
coefficient applies to that scalar. After extending a parameter's
right-hand side in a formula passed directly to brm,
check whether the added coefficients have the same meaning and support. For
example, after changing top ~ 1 to top ~ treatment, the same
prior applies to both the intercept and the treatment contrasts, although a
contrast need not have the support of top. A no-intercept cell-means
formula such as top ~ 0 + treatment instead gives every coefficient
the meaning and support of a treatment-specific top, so a shared
parameter-level prior can be appropriate.
Use get_prior to inspect the target coefficients. Where
their meaning or support differs, rebuild the priors under the
parameterisation used by that formula rather than reusing this object
unchanged. Adding coef = "Intercept" is not a general conversion:
brms does not allow coef together with lb or
ub, and those bounds are part of the priors bayesnec
generates for several parameters.
library(bayesnec)
data(manec_example)
# the priors a fit used, ready to pass back to bnec(prior = )
get_priors(manec_example)
#> $nec4param
#> prior class coef group resp dpar
#> normal(0, 5) b
#> normal(-0.475731934041565, 3.6135432617749) b
#> lognormal(-0.132723577442522, 1.68292842267636) b
#> normal(2.63236428713204, 3.6135432617749) b
#> nlpar lb ub tag source
#> beta <NA> <NA> user
#> bot <NA> <NA> user
#> nec 0.03234801324009 3.22051966293556 user
#> top <NA> <NA> user
#>
#> $ecx4param
#> prior class coef group resp dpar
#> normal(0, 5) b
#> normal(-0.475731934041565, 3.6135432617749) b
#> lognormal(-0.132723577442522, 1.68292842267636) b
#> normal(2.63236428713204, 3.6135432617749) b
#> nlpar lb ub tag source
#> beta <NA> <NA> user
#> bot <NA> <NA> user
#> ec50 0.03234801324009 3.22051966293556 user
#> top <NA> <NA> user
#>
# the priors bayesnec would generate, without fitting anything
get_priors(y ~ crf(x, "nec3param"), data = nec_data)
#> prior class coef group resp dpar
#> normal(0, 5) b
#> beta(5, 2) b
#> lognormal(-0.132723577442522, 1.68292842267636) b
#> nlpar lb ub tag source
#> beta <NA> <NA> user
#> top 0 1 user
#> nec 0.03234801324009 3.22051966293556 user