Make sure that mean and covariance of data are correctly computed with only one observation

Need to always compute mean along first dimension

(cherry picked from commit 2d371b1997f5fa07fcbbf47e5923d7817d07c6b9)
time-shift
Johannes Pfeifer 2018-01-11 22:08:03 +01:00 committed by Stéphane Adjemian (Charybdis)
parent 0d11246c35
commit b4204f8b9e
2 changed files with 3 additions and 3 deletions

View File

@ -267,7 +267,7 @@ else
end
% Compute the empirical mean of the observed variables.
DatasetInfo.descriptive.mean = nanmean(DynareDataset.data);
DatasetInfo.descriptive.mean = nanmean(DynareDataset.data,1);
% Compute the empirical covariance matrix of the observed variables.
DatasetInfo.descriptive.covariance = nancovariance(DynareDataset.data);

View File

@ -51,7 +51,7 @@ function CovarianceMatrix = nancovariance(data)
CovarianceMatrix = zeros(size(data,2));
if isanynan(data)
data = bsxfun(@minus,data,nanmean(data));
data = bsxfun(@minus,data,nanmean(data,1));
for i=1:size(data,2)
for j=i:size(data,2)
CovarianceMatrix(i,j) = nanmean(data(:,i).*data(:,j));
@ -61,7 +61,7 @@ if isanynan(data)
end
end
else
data = bsxfun(@minus,data,mean(data));
data = bsxfun(@minus,data,mean(data,1));
CovarianceMatrix = (transpose(data)*data)/size(data,1);
end