Multivariate normal and lognormal joints
multivariate_normal.RdMany capital-model inputs arrive as a mean vector and a covariance matrix,
not as draws: a reserve by origin with Mack's covariance across origins,
lines joined by a correlation matrix. multivariate_normal() and
multivariate_lognormal() hold such a joint with its exact marginals and
moments; predictive_from_gaussian() draws it by seed.
Usage
multivariate_normal(mean, cov)
multivariate_lognormal(mean = NULL, cov = NULL, mu = NULL, log_cov = NULL)
multivariate_gaussian(ptr)Value
A multivariate_gaussian with properties kind ("normal" or
"lognormal"), dimension, mean, cov and correlation (on the original
scale), mu and log_cov (a lognormal's log scale, empty for a normal),
total_mean and total_variance.
Details
multivariate_lognormal() takes the mean and covariance on the original
scale, matched exactly (log_cov[i, j] = log(1 + cov[i, j] / (m[i] m[j])),
mu[i] = log(m[i]) - log_cov[i, i] / 2, the conversion behind Mack's
lognormal reserve), or mu and log_cov on the log scale.
The covariance must be symmetric and positive definite: a zero variance
or a perfect correlation is singular and refused. A covariance at or below
-m[i] m[j] has no lognormal, and the covariance on the log scale can fail
to be positive definite even when cov is; both are refused too.
marginal(joint, j) is component j's marginal, exact (a
normal_distribution or a lognormal). total() of a normal joint is
normal with mean sum(mean) and variance sum(cov); a sum of lognormals
is not lognormal, so a lognormal joint gives its total's moments as
total_mean and total_variance and errors in total().
Examples
cov <- matrix(c(400, 120, 120, 100), 2)
mvn <- multivariate_normal(c(100, 50), cov)
total(mvn)@sigma^2 # 400 + 2 * 120 + 100
#> [1] 740
marginal(mvn, 2)@sigma
#> [1] 10
mvl <- multivariate_lognormal(c(100, 50), cov)
mvl@cov # the covariance given
#> [,1] [,2]
#> [1,] 400 120
#> [2,] 120 100
mvl@total_variance
#> [1] 740