Computes the distribution of \(AX + b\) where \(X \sim MVN(\mu, \Sigma)\). The result is \(MVN(A\mu + b, A \Sigma A^T)\).

affine_transform(x, A, b = NULL)

Arguments

x

A normal or mvn distribution object.

A

A numeric matrix (or scalar for univariate).

b

An optional numeric vector (or scalar) for the offset. Default is a zero vector.

Value

A normal or mvn distribution.

Details

For a univariate normal, scalars A and b are promoted to 1x1 matrices and scalar internally. Returns a normal if the result is 1-dimensional.

Examples

X <- mvn(c(0, 0), diag(2))
# Project to first component via 1x2 matrix
Y <- affine_transform(X, A = matrix(c(1, 0), 1, 2), b = 5)
mean(Y)
#> [1] 5

# Scale a univariate normal
Z <- affine_transform(normal(0, 1), A = 3, b = 2)
mean(Z)
#> [1] 2
vcov(Z)
#> [1] 9