1
$\begingroup$

I have a question concerning generating samples for a given mean vector and covariance matrix.

mu = {0.422084, 0.518201, -1.13857, -1.34951, 0, 2};

cov = {{0.000749594187095, 0.000670223129197, -0.006164273736522, 
  -0.004243056424882, 0.011372890644823, 0.001311870031246}, 
 {0.000670223129197, 0.001244975293461, -0.004710830597348, 
  -0.010103508140104, 0.004972780726833, 0.009465313700532}, 
 {-0.006164273736522, -0.004710830597348, 0.094116175041483, 
  0.042219205628345, -0.371146407307241, -0.019976547027344}, 
 {-0.004243056424882, -0.010103508140104, 0.042219205628345, 
  0.16237356863464, -0.072506782444349, -0.393141309425425}, 
 {0.011372890644823, 0.004972780726833, -0.371146407307241, 
  -0.072506782444349, 3.22993771179459, 0.261221262531002}, 
 {0.001311870031246, 0.009465313700532, -0.019976547027344, 
  -0.393141309425425, 0.261221262531002, 2.6882275522931}}

dist= 
  MultinormalDistribution[mu, cov];

I want to draw some samples between -1 and 1 but i cant even generate one sample with:

Anyone knows why this is the case? Am I missing something? RandomVariate[TruncatedDistribution[{-1, 1}, dist], 1]

$\endgroup$

1 Answer 1

4
$\begingroup$

The first argument of TruncatedDistribution should be list of pairs with length equal to the dimension of dist:

RandomVariate[TruncatedDistribution[ConstantArray[{-1, 1}, Length @ mu], dist], 3]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.