如何计算伽马分布的中位数?

时间:2018-05-01 13:44:44

标签: matlab gamma-distribution

我有以下分布,我想计算中位数:

x=0:0.01:10;
x=[x' x' x' x' x'];
a=ones(1,1001)';
a=[a*2 a*4 a*6 a*8 a*10];
b=2;
f = gampdf(x,a,b);
plot(x,f)
grid on

Visualization of Distribution

2 个答案:

答案 0 :(得分:1)

用户TwistedSim回答了我的问题。

  

您需要找到从0到m的积分给出的值m   你0.5。您可以使用c = cumsum(f)*dx中的dx = 0.01来完成此操作   案件。之后只需使用find(c>0.5, 1, 'first')

答案 1 :(得分:0)

dx = 0.04;
b=2;

x=kron([0:dx:10]',ones(1,5));
a=kron(ones(size(x,1),1),[2:2:10]);
f = gampdf(x,a,b);
cf = cumsum(f)*dx;
[i,j] = find(cf(1:end-1,:)<0.5 & cf(2:end,:)>=0.5);

cflow  = cf(sub2ind(size(x),i  ,j));
cfhigh = cf(sub2ind(size(x),i+1,j));

xm = x(i)+dx/2 + (0.5-cflow)./(cfhigh-cflow) * dx
fm = gampdf(xm',a(1,:),b)';

plot(x,f)
hold on; plot([xm xm]',[fm fm]','*'); hold off
grid on