sample_from_constraints: Sample from multivariate normal distribution under affine...

Description Usage Arguments Value Examples

Description

sample_from_constraints returns a sample from the conditional multivariate normal, restricted by affine constraints. The constraints are coded by a linear matrix and an offset vector: linear_part %*% Z <= offset. The sampling uses a Gibbs sampler, and requires an initial vector that meets the restriction.

Usage

1
2
sample_from_constraints(linear_part, offset, mean_param, covariance,
  initial_point, ndraw = 8000, burnin = 2000)

Arguments

linear_part

r x d matrix for r restrictions and d dimension of Z

offset

r-dim vector of offsets

mean_param

d-dim mean vector of the unconditional normal

covariance

d x d covariance matrix of unconditional normal

initial_point

d-dim vector that initializes the sampler (must meet restrictions)

ndraw

size of sample

burnin

samples to throw away before storing

Value

Z ndraw x d matrix of samples

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Compute conditional mean of correlated lower-truncated vector
 
constr = thresh2constraints(3, lower = c(1,1,1))
covariance = matrix(c(1,0.5,0,0.5,1,0.5,0,0.5,1),nc=3)
 
samp = sample_from_constraints(linear_part = constr$linear_part,
                                    offset= constr$offset,
                                    mean_param = c(0,0,0),
                                    covariance = covariance,
                                    initial_point = c(1.5,1.5,1.5), 
                                    ndraw=500,
                                    burnin=2000)


# all points should be >= 1 
any(samp<1)
colMeans(samp)

restrictedMVN documentation built on May 1, 2019, 7:39 p.m.