rnorm.par: Generate a parameter block of standard normal samples

View source: R/mis_rnorm.par.R

rnorm.parR Documentation

Generate a parameter block of standard normal samples

Description

This function initializes an array of class "param_block" containing samples from standard normal distribuion (i.e., mean 0 and standard deviation 1). There are most helpful for calculating distributions of expected rates over some time interval.

Usage

rnorm.par(
  niter = 1,
  n = 1,
  nchains = 1,
  simplify = TRUE,
  fit = NULL,
  chain.names = paste("chain", seq_len(nchains))
)

Arguments

niter

The number of iterations/rows of the resulting param_block array.

n

The number of parameters/columns of the resulting param_block array.

nchains

The number of chains/slices of the reuslting param_block array.

simplify

TRUE or FALSE: should the resulting param_block array be simplified? If TRUE (the default), dimensions of length 1 in the result are automatically collapsed, with corresponding information stored as attributes (this is the default behavior of param_block operators).

fit

An object of class "evorates_fit" or "param_block". If not NULL (the default), the resulting param_block array will copy the names and dimensions of fit except for parameters/columns.

chain.names

A character vector of names for the chains/slices of the resulting param_block array.

Details

The resulting normal samples may be transformed to have different means/standard deviations by multiplying with and adding constants–see examples below.

Value

An array of class "param_block" with a param_type of "chains". The dimension of these arrays will generally go in the order of iterations, then parameters, then chains. Any dimensions of length 1 are collapsed and stored as attributes if simplify is TRUE. Parameters are all named "N(0;1)i", where i denotes the ith column of the resulting array.

See Also

param_block-class for general information on param_block arrays and %chains%(), %quantiles%(), %means%(), %diagnostics%(), and %select%() for more information on param_block operators.

Examples

rnorm.par(1500, 1, 4)
#compare without simplification
rnorm.par(1500, 1, 4, simplify = FALSE)

#using a fitted evorates model to automatically determine dimensions/names
data("cet_fit")
rnorm.par(n = 2, fit = cet_fit)
#or a param_block
parblock <- rnorm.par(500, 3, 1)
rnorm.par(n = 5, fit = parblock)

#transforming to non-standard normal distribution
means <- c(-1, 5, 2)
sds <- c(2, 0.5, 1)
prof.plot(parblock * sds + means, alpha = 0.5, smooth = TRUE)

#distribution of fold-changes expected after 1 million years
rates.per.my<-exp(setNames(sqrt(cet_fit %chains% "R_sig2") * rnorm.par(fit = cet_fit) + cet_fit %chains% "R_mu",
                           "rates_per_my"))
prof.plot(rates.per.my)
#after 10 million years
rates.per.10my<-exp(setNames(sqrt(cet_fit %chains% "R_sig2") * sqrt(10) * rnorm.par(fit = cet_fit) + 10 * cet_fit %chains% "R_mu",
                             "rates_per_10my"))
prof.plot(rates.per.10my)
#easier to interpret on log scale maybe
prof.plot(log(rates.per.10my))            



bstaggmartin/backwards-BM-simulator documentation built on June 3, 2024, 5:51 p.m.