conditional.mvn: Conditional distribution for multivariate normal.

View source: R/mvn.R

conditional.mvnR Documentation

Conditional distribution for multivariate normal.

Description

Supports two calling patterns:

  1. Closed-form (via given_indices and given_values): Uses the exact Schur complement formula. Returns a normal (1D result) or mvn.

  2. Predicate-based (via P): Falls back to MC realization via ensure_realized.

Usage

## S3 method for class 'mvn'
conditional(x, P = NULL, ..., given_indices = NULL, given_values = NULL)

Arguments

x

An mvn object.

P

Optional predicate function for MC fallback.

...

Additional arguments forwarded to the predicate P.

given_indices

Integer vector of observed variable indices.

given_values

Numeric vector of observed values (same length as given_indices).

Value

A normal, mvn, or empirical_dist object.

Examples

# Closed-form conditioning: X2 | X1 = 1
sigma <- matrix(c(1, 0.5, 0.5, 1), 2, 2)
X <- mvn(c(0, 0), sigma)
X2_given <- conditional(X, given_indices = 1, given_values = 1)
mean(X2_given)
vcov(X2_given)

# Predicate-based MC fallback (slower)

set.seed(42)
X2_mc <- conditional(X, P = function(x) x[1] > 0)


algebraic.dist documentation built on Feb. 27, 2026, 5:06 p.m.