parameter {coala}R Documentation

Model Parameters

Description

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).

Usage

par_expr(expr)

par_const(constant)

par_named(name)

par_range(name, lower, upper)

par_prior(name, prior)

Arguments

expr

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).

constant

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.

name

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

lower

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

upper

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

prior

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.

Functions

Author(s)

Paul Staab

See Also

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

Examples

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

model <- model_base +
  feat_mutation(par_const(5))
simulate(model)

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

# Using a named parater:
model <- model_base +
  feat_mutation(par_named("theta"))
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") +
  feat_mutation(par_expr(exp(theta_log)))
simulate(model, pars = c(theta_log = log(5)))

[Package coala version 0.6.0 Index]