vendredi 26 avril 2019

Simulate left Truncated Gamma distribution with mean = 1 and variance =0.4

Suppose $X$~Gamma$\left(\alpha, \beta\right)$, I would like to truncate all values of $X

MATLAB codes:

t = 0.5;  theta = 0.4; 
syms alpha beta 
EX = beta*( igamma(alpha+1,t/beta) /  igamma(alpha,t/beta) ); %Mean  
EX2 = beta^2*( igamma(alpha+2,t/beta) /  igamma(alpha,t/beta) );%Second moment         
VarX = EX2 -EX^2; %Variance       
cond1 = alpha > 0; cond2 = beta > 0; cond3 = EX==1; cond4 = VarX ==theta;
conds =[cond1 cond2 cond3 cond4]; vars = [alpha, beta];
sol = solve(conds, [alpha beta], 'ReturnConditions',true);
soln_alpha = vpa(sol.alpha)
soln_beta = vpa(sol.beta)

The above code returns a numeric answer only if the constraint that $\alpha>0$ is relaxed. The numeric answer has a negative value of $\alpha$ which is wrong since both $\alpha$ (shape parameter) and $\beta$ (scale parameter) must be strictly positive.




Aucun commentaire:

Enregistrer un commentaire