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
parent
0d11246c35
commit
b4204f8b9e
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue