データのヒストグラム​と確率密度関数を重ね​書きするにはどうすれ​ばよいですか?

23 vues (au cours des 30 derniers jours)
MathWorks Support Team
MathWorks Support Team le 25 Oct 2013
データのヒストグラムと、その確率密度関数を重ね書きする方法を教えてください。

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 26 Oct 2013
与えられたデータからそのヒストグラムと確率密度関数を描画する Statistics Toolbox の関数に HISTFIT があります。
HISTFIT 関数では、与えられたデータから各種統計量(標本平均など)を求め、確率密度関数を描画します。
r = normrnd(10,1,100,1);
histfit(r,10,'normal') % ヒストグラムのビン数:10, 正規分布にフィッティング
なお、Statistics Toolbox 7.0(R2008b) 以前のバージョンの HISTFIT 関数では、正規分布以外の
分布を用いて確率密度関数を描画することはできません。
その場合には、以下のように実行します。
mu = 0;
sigma = 1;
data = normrnd(mu,sigma,100,1);
numbins = 10; % ヒストグラムのビン数
hist(data,numbins) % ヒストグラムの描画
hold on
[bincounts,binpositions] = hist(data,numbins);
binwidth = binpositions(2) - binpositions(1); % ビンの間隔を取得
histarea = binwidth*sum(bincounts); % ヒストグラムの面積
x = binpositions(1):0.001:binpositions(end); % 確率密度関数の横軸データ
y = normpdf(x,mu,sigma); % 確率密度関数
plot(x,histarea*y,'r','LineWidth',2) % ヒストグラムのスケールにあわせて描画
normpdf 関数などで得られる値をプロットした確率密度関数は、その面積が 1 になります。
そのため、元のデータのヒストグラムに重ね書きする場合には、ヒストグラムの総面積を求め、
スケーリングした後、プロットする必要があります。
本件に関する内容が、Statistics Toolbox のヘルプドキュメントに記載されています。
[Statistics Toolbox]
- [Probability Distributions]
-[Distribution Functions]
- [Distribution Fitting Functions]

Plus de réponses (0)

Produits


Version

R2009a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!