parameter: Model Parameters

parameterR Documentation

Model Parameters


These functions add parameters to a model. Parameters can either be used in features, or added directly to a model using the plus operator. The value of parameters can be specified in the simulation command (for par_named and par_range), sampled from a prior distribution (par_prior) or can be derived from other parameters (par_expr).





par_range(name, lower, upper)

par_prior(name, prior)



An R expression. This allows to define a parameter using an R expression. It can contain other named parameters (e.g. 2 * a will create an parameter that is twice the value of an existing parameter a). Make sure that the expression always evaluates to a valid parameter value (a single numeric in almost all cases).


An R expression. The constant value of the parameter. Different to expr, the expression is evaluated immediately and can not depend on other named parameters.


Character. The name of the parameter. Must be unique in a model.


A numeric. The lower boundary of the parameter's range.


A numeric. The upper boundary of the parameter's range.


An expression. Evaluation this expression should give a sample from the prior distribution you want for the parameter. For example using rnorm(1) gives a standard normal prior.


  • par_expr(): Creates a parameter with value determined by evaluating an expression.

  • par_const(): Creates an parameter that is equal to a fixed value. Different to par_expr, the value is evaluated on parameter creation.

  • par_named(): Creates an parameter whose value is specified via the pars argument in simulate.coalmodel.

  • par_range(): Creates an parameter that can take a range of possible values. Similar to par_named, the value of the parameter used in a simulation is set via the pars argument. This is primarily intended for creating model parameters for jaatha.

  • par_prior(): Creates a named parameter with a prior distribution. Before each simulation, the expression for the prior is evaluated. The resulting value can be used in par_expr under the chosen name.


Paul Staab

See Also

For parameters that variate between the loci in a model: par_variation, par_zero_inflation


# A parameter (here for the mutation rate) that is always
# equal to '5':
model_base <- coal_model(20, 1) +

model <- model_base +

# With using a prior:
model <- model_base +
  feat_mutation(par_prior("theta", rnorm(1, 5, .1)))

# Using a named parater:
model <- model_base +
simulate(model, pars = c(theta = 5))

# or similarly a ranged parameter:
model <- model_base +
  feat_mutation(par_range("theta", 1, 10))
simulate(model, pars = c(theta = 5))

# Expressions can be used to derive parameters from
# other parameters:
model <- model_base +
  par_named("theta_half") +
  feat_mutation(par_expr(theta_half * 2))
simulate(model, pars = c(theta_half = 2.5))

model <- model_base +
  par_named("theta_log") +
simulate(model, pars = c(theta_log = log(5)))

coala documentation built on May 29, 2024, 11:14 a.m.