Learn R Programming

algebraic.dist (version 0.9.1)

conditional.mvn: 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 mvn
conditional(x, P = NULL, ..., given_indices = NULL, given_values = NULL)

Value

A normal, mvn, or empirical_dist object.

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

Examples

Run this code
# 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)
# \donttest{
set.seed(42)
X2_mc <- conditional(X, P = function(x) x[1] > 0)
# }

Run the code above in your browser using DataLab