histogram normalization not working
19 ビュー (過去 30 日間)
古いコメントを表示
Dear MATLAB experts,
I have a problem normalizing my AR(1) model histogram to pdf. In fact, when I try cdf or probabiltiy it works fine, but pdf option does not try properly.
The code is as follows:
% AROLS function
function [beta, Sig2,Cov]=AROLS(y,p)
T=size(y,1);
Y=y(p+1:T,1);
X=ones(T-p,1);
for j=1:p
X=[X,y(p+1-j:T-j,1)];
end
beta=(X'*X)\(X'*Y);
U=Y-X*beta;
Sig2=(U'*U)/(T-p-1);
Cov=Sig2*inv(X'*X);
end
% AR(1) model histogram
Ns=20;
N=10000;
T=200;
a0=0;
a1=0.7;
beta0=[a0;a1];
Amat=zeros(Ns,2);
for idx=1:Ns
u=randn(N,1);
y=zeros(N,1);
for n=2:N
y(n,1)=a0+a1*y(n-1,1)+u(n,1);
end
y=y(N-T+1:N,1);
p=1;
[beta,Sig2,Cov]=AROLS(y,p);
Amat(idx,:)=((beta-beta0)./sqrt(diag(Cov)))';
end
figure(1)
h=histogram(Amat(:,2),50,'Normalization', 'pdf');
grids=-3:0.1:3;
f=pdf('Normal', grids,0,1);
hold on
plot(grids,f,'-r')
hold off
So when I execute this code, the plot shows like this. But the histogram obviously is wrong because certain bars are over than 1. I'm totaly lost..
0 件のコメント
回答 (1 件)
Jeff Miller
2021 年 4 月 9 日
The histogram is not wrong, because pdf values can be more than 1. pdf values are normalized such that the total area under the blue bars is 1.0. Total area = sum(bar height x bar width). In this case some heights are greater than 1 because the bars are so narrow.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Histograms についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!