Commit b4204f8b authored by Johannes Pfeifer 's avatar Johannes Pfeifer Committed by Stéphane Adjemian (Charybdis)

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)
parent 0d11246c
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment