Generate random errors for data with specific covariance matrices

7 ビュー (過去 30 日間)
Mary Tavoosi
Mary Tavoosi 2021 年 10 月 3 日
コメント済み: Mary Tavoosi 2021 年 10 月 3 日
Hello
I have simulated 450 data for a linear regression model with 5 independent variables and a dependent variable (y=a*x1+b*x2+c*x3+d*x4+e*x5+f). Each of these data has specific weights(Wy, Wx1, Wx2, Wx3, Wx4, Wx5) . Now I want to add a random error with a mean of zero and variance (for example Sigma*inv(W) ) of each variables to this data. How can this be done?

回答 (1 件)

the cyclist
the cyclist 2021 年 10 月 3 日
If you have the Statistics and Machine Learning Toolbox, you can generate correlated normal variables with the mvnrnd function.
  3 件のコメント
the cyclist
the cyclist 2021 年 10 月 3 日
If you read the documentation carefully, you will see that you can specify the full variance matrix. Here is an example:
N = 1000000;
mu = [0; 0; 0];
sigma = [1.0 0.5 0.5;
0.5 0.9 0.7;
0.5 0.7 0.7];
x = mvnrnd(mu,sigma,N);
var(x)
ans = 1×3
0.9983 0.8980 0.6988
Mary Tavoosi
Mary Tavoosi 2021 年 10 月 3 日
thank you

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by