sampling error from a truncated normal distribution

8 ビュー (過去 30 日間)
piyius raj
piyius raj 2020 年 3 月 16 日
回答済み: Jeff Miller 2020 年 3 月 16 日
Hi everyone,
Please see the code below. I tried to sample from a truncated normal distibution but the sample histogram is not matching with the actual truncated distribution plot. Can anyone help me with this.
t = 0.01;
n = 10000;
d_mu = 0.0052;
d_COV = 61.35;
d_sig = d_COV*d_mu/100;
pd = makedist('Normal','mu',d_mu,'sigma',d_sig); % normal distribution
tpd = truncate(pd,0,t); % truncated normal distribution
d_norm = random(pd,n,1); % sample from normal
d_tnorm = random(tpd,n,1); % sample from truncated normal
x = linspace(-.01,.02,n);
figure
plot(x,pdf(pd,x))
hold on
plot(x,pdf(tpd,x),'LineStyle','--')
histogram(d_tnorm,30)
legend('Normal','Truncated','Truncated bar')
hold off

回答 (2 件)

Walter Roberson
Walter Roberson 2020 年 3 月 16 日
When you use truncate(), it does not make the samples outside the range just vanish: it adjusts the distribution so that the total is still 1.
Truncated distribution, returned as a probability distribution object. The probability distribution function (pdf) of t is 0 outside the truncation interval. Inside the truncation interval, the pdf of t is equal to the pdf of pd, but divided by the probability assigned to that interval by pd.
  5 件のコメント
Walter Roberson
Walter Roberson 2020 年 3 月 16 日
d_pit_COV and d_pit_mu are not defined.
piyius raj
piyius raj 2020 年 3 月 16 日
Sorry. The correct code is
t = 0.01;
n = 10000;
d_mu = 0.0052;
d_COV = 61.35;
d_sig = d_COV*d_mu/100;
pd = makedist('Normal','mu',d_mu,'sigma',d_sig); % normal distribution
tpd = truncate(pd,0,t); % truncated normal distribution
d_norm = random(pd,n,1); % sample from normal
d_tnorm = random(tpd,n,1); % sample from truncated normal
x = linspace(-.01,.02,n);
figure
plot(x,pdf(pd,x))
hold on
plot(x,pdf(tpd,x),'LineStyle','--')
histogram(d_tnorm,30)
legend('Normal','Truncated','Truncated bar')
hold off

サインインしてコメントする。


Jeff Miller
Jeff Miller 2020 年 3 月 16 日
Change the histogram line to this:
histogram(d_tnorm,30,'Normalization','pdf')

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by