Set prior(s) for a network model
set_prior(x, prior, param = "", use_regexp = TRUE, quiet = FALSE)
set_priors(x, prior, param = "", use_regexp = TRUE, quiet = FALSE)
A networkModel
object.
A prior built with e.g. uniform_p() or hcauchy_p(). Call
available_priors()
to see a table of implemented
priors. Alternatively, if prior
is a tibble, the function will
try to use it to set parameter priors. The format of such an argument is
the same as the format of the output of the getter function
priors()
(see examples). Note that if `prior` is given as a
tibble, all other arguments (except `x`) are disregarded.
String, target parameter or regexp to target several
parameters. Default is the empty string ""
, which will match all
parameters.
Boolean, if TRUE
(the default) then param
is
used as a regular expression to match one or several parameter names.
Boolean, if FALSE
print a message indicating which
parameters had their prior modified.
A networkModel
object.
# Copy `aquarium_mod`
m <- aquarium_mod
priors(m)
#> # A tibble: 8 × 2
#> in_model prior
#> <chr> <list>
#> 1 eta <trun_normal(mean=0,sd=0.5)>
#> 2 lambda_algae <trun_normal(mean=0,sd=0.2)>
#> 3 lambda_daphnia <trun_normal(mean=0,sd=0.2)>
#> 4 lambda_NH4 <trun_normal(mean=0,sd=0.2)>
#> 5 upsilon_algae_to_daphnia <trun_normal(mean=0,sd=0.5)>
#> 6 upsilon_daphnia_to_NH4 <trun_normal(mean=0,sd=0.5)>
#> 7 upsilon_NH4_to_algae <trun_normal(mean=0,sd=0.5)>
#> 8 zeta <trun_normal(mean=0,sd=0.5)>
# Modify the priors of `m`
m <- set_priors(m, exponential_p(0.5), "lambda")
#> Prior modified for parameter(s):
#> - lambda_algae
#> - lambda_daphnia
#> - lambda_NH4
priors(m)
#> # A tibble: 8 × 2
#> in_model prior
#> <chr> <list>
#> 1 eta <trun_normal(mean=0,sd=0.5)>
#> 2 lambda_algae <exponential(lambda=0.5)>
#> 3 lambda_daphnia <exponential(lambda=0.5)>
#> 4 lambda_NH4 <exponential(lambda=0.5)>
#> 5 upsilon_algae_to_daphnia <trun_normal(mean=0,sd=0.5)>
#> 6 upsilon_daphnia_to_NH4 <trun_normal(mean=0,sd=0.5)>
#> 7 upsilon_NH4_to_algae <trun_normal(mean=0,sd=0.5)>
#> 8 zeta <trun_normal(mean=0,sd=0.5)>
# Re-apply priors from the original `aquarium_mod`
prev_priors <- priors(aquarium_mod)
prev_priors
#> # A tibble: 8 × 2
#> in_model prior
#> <chr> <list>
#> 1 eta <trun_normal(mean=0,sd=0.5)>
#> 2 lambda_algae <trun_normal(mean=0,sd=0.2)>
#> 3 lambda_daphnia <trun_normal(mean=0,sd=0.2)>
#> 4 lambda_NH4 <trun_normal(mean=0,sd=0.2)>
#> 5 upsilon_algae_to_daphnia <trun_normal(mean=0,sd=0.5)>
#> 6 upsilon_daphnia_to_NH4 <trun_normal(mean=0,sd=0.5)>
#> 7 upsilon_NH4_to_algae <trun_normal(mean=0,sd=0.5)>
#> 8 zeta <trun_normal(mean=0,sd=0.5)>
m <- set_priors(m, prev_priors)
#> Prior modified for parameter(s):
#> - eta
#> - lambda_algae
#> - lambda_daphnia
#> - lambda_NH4
#> - upsilon_algae_to_daphnia
#> - upsilon_daphnia_to_NH4
#> - upsilon_NH4_to_algae
#> - zeta
priors(m)
#> # A tibble: 8 × 2
#> in_model prior
#> <chr> <list>
#> 1 eta <trun_normal(mean=0,sd=0.5)>
#> 2 lambda_algae <trun_normal(mean=0,sd=0.2)>
#> 3 lambda_daphnia <trun_normal(mean=0,sd=0.2)>
#> 4 lambda_NH4 <trun_normal(mean=0,sd=0.2)>
#> 5 upsilon_algae_to_daphnia <trun_normal(mean=0,sd=0.5)>
#> 6 upsilon_daphnia_to_NH4 <trun_normal(mean=0,sd=0.5)>
#> 7 upsilon_NH4_to_algae <trun_normal(mean=0,sd=0.5)>
#> 8 zeta <trun_normal(mean=0,sd=0.5)>