I have a matrix A as a row vector containing some missing values NaN. Let's assume it looks like the following:
A = [2; NaN; 0.3; NaN; -0.8; NaN; 1; -0.5; NaN; 0.2];
The series has a A_mean = nanmean(A, 1) of 0.37 and a A_std = nanstd(A, 1) of 0.93.
I created a random vector B of the same size in
B = rand(1, 10)';
I defined an upper bound ub and a lower bound lb as
ub = A_mean * 5;
lb = A_mean * (-5);
So I changed B to
B = ub + (lb-ub) * rand(1, 10);
I can replace all NaN values in A by
idx = isnan(A);
A(idx) = B(idx);
Taking A_std = nanstd(A, 1) of this new defined vector leads to std, which is randomly different to 0.93.
I would like to know, whether I can replace the missing values NaN in A with random variables and keep the std the same?
Aucun commentaire:
Enregistrer un commentaire