Generating a random variable that has a predefined covariance with other random variable
1 回表示 (過去 30 日間)
古いコメントを表示
I wanted to generate a normal random variable which has a predefined co-variance with another random number. But I can't figure out how to proceed.Here is the specific problem,
I have e~N(0,1) and I want to generate X such that cov(x,e)=1 and E(X)=0. How can I generate this random number with sample size 500?
Thanks!
0 件のコメント
採用された回答
Roger Stafford
2014 年 11 月 1 日
You haven't stated what you want the variance of X to be. If it is to be 1, the trivial solution would be to set X = e. For general var(X) = v (which must be greater than or equal to 1,) use this formula for generating X:
X = e(1:500) + sqrt(v-1)*randn(1,500);
where presumably 'e' and randn are statistically independent.
0 件のコメント
その他の回答 (2 件)
Matt J
2014 年 11 月 1 日
編集済み: Matt J
2014 年 11 月 1 日
How about just setting X=e ?
3 件のコメント
Roger Stafford
2014 年 11 月 1 日
Setting X = e does give a covariance of 1, because e was stated as N(0,1).
the cyclist
2014 年 11 月 1 日
編集済み: the cyclist
2014 年 11 月 1 日
If you have the Statistics Toolbox, you can use the mvnrnd command.
If you don't, you can use Cholesky decomposition to do this. This page seems to have a pretty good explanation, and there is even some MATLAB code there.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Random Number Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!