sample_from_constraints {restrictedMVN} | R Documentation |
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.
sample_from_constraints(linear_part, offset, mean_param, covariance, initial_point, ndraw = 8000, burnin = 2000)
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 |
Z ndraw x d matrix of samples
# 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)