Multivariate normal random numbers vs. random numbers from normal distribution
Mostra commenti meno recenti
I sampled random numbers using both samples from the multivariate normal distribution and samples from the normal distribution with specified mean and variance.
I have a mean vector mu and a covariance matrix sigma:
mu = [-0.25, 0.03, 0.01]'
sigma = eye(length(mu))
Using multivariate normal random numbers, I get the following results:
rng default % for reproducibility
R = mvnrnd(mu, sigma, 3)
R =
0.2877 0.8922 -0.4236
1.5839 0.3488 0.3526
-2.5088 -1.2777 3.5884
Using random numbers from the normal distribution with a specific mean (b) and variance (a), I get the following results:
a = 1; % std
b = mu(1); % mean
rng default
y = a.*randn(3,1) + b
y =
0.2877 0.5677
1.5839 1.8639
-2.5088 -2.2288
To create the second column, I used b = mu(2).
I wonder why the results are different in these cases. For the first column the result is the same, but from the second column it changes. Shouldn't this be the same? If not, what is the right way to draw random numbers for the mean vector mu.
Risposta accettata
Più risposte (1)
I'm not quite sure what you did to create y, since the code generates y as a single column.
It looks like y was produced by:
mu = [-0.25, 0.03, 0.01]';
sigma = eye(length(mu));
y = zeros(3,2);
rng default
y(:,1) = randn(3,1)+mu(1);
rng default
y(:,2) = randn(3,1)+mu(2)
However, that's not correct because y(:,2) needs to be generated from samples of RVs that are independent of those used to generate y(:,1).
The output from mvnrnd() in this example can be reconstructed as follows using nine samples of randn (three samples of a 3-dimensional random vector) :
rng default % for reproducibility
R = mvnrnd(mu, sigma, 3)
rng default
R1 = randn(3,3) + mu.'
R - R1
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!