Truncating Poisson distribution on desired support in Matlab

回眸只為那壹抹淺笑 提交于 2020-03-23 07:43:10

问题


I want to construct a 3-dimensional Poisson distribution in Matlab with lambda parameters [0.4, 0.2, 0.6] and I want to truncate it to have support in [0;1;2;3;4;5]. The 3 components are independent.

This is what I do

clear
n=3; %number components of the distribution 

supp_marginal=0:1:5;
suppsize_marginal=size(supp_marginal,2); 

supp_temp=repmat(supp_marginal.',1,n); 
supp_temp_cell=num2cell(supp_temp,1); 
output_temp_cell=cell(1,n);
[output_temp_cell{:}] = ndgrid(supp_temp_cell{:});
supp=zeros(suppsize_marginal^n,n);

for h=1:n
    temp=output_temp_cell{h};
    supp(:,h)=temp(:);  
end
suppsize=size(supp,1); 

lambda_1=0.4;
lambda_2=0.2;
lambda_3=0.6;

pr_mass=zeros(suppsize,1);
for j=1:suppsize
    pr_mass(j)=(poisspdf(supp(j,1),lambda_1).*...
                poisspdf(supp(j,2),lambda_2).*...
                poisspdf(supp(j,3),lambda_3))/...
                sum(poisspdf(supp(:,1),lambda_1).*...
                    poisspdf(supp(:,2),lambda_2).*...
                    poisspdf(supp(j,3),lambda_3));
end 

When I compute the mean of the obtained distribution, I get lambda_1 and lambda_2 but not lambda_3.

lambda_empirical=sum(supp.*repmat(pr_mass,1,3)); 

Question: why I do not get lambda_3?


回答1:


tl;dr: Truncation changes the distribution so different means are expected.


This is expected as truncation itself has changed the distribution and certainly adjusts the mean. You can see this from the experiment below. Notice that for your chosen parameters, this just starts to become noticable around lambda = 0.6.

Similar to the wiki page, this illustrates the difference between E[X] (expectation of X without truncation; fancy word for mean) and E[ X | LBXUB] (expectation of X given it is on interval [LB,UB]). This conditional expectation implies a different distribution than the unconditional distribution of X (~Poisson(lambda)).

% MATLAB R2018b
% Setup
LB = 0;   % lowerbound 
UB = 5;   % upperbound

% Simple test to compare theoretical means with and without truncation
TestLam = 0.2:0.01:1.5;
Gap = zeros(size(TestLam(:)));
for jj = 1:length(TestLam)
    TrueMean = mean(makedist('Poisson','Lambda',TestLam(jj)));
    TruncatedMean = mean(truncate(makedist('Poisson','Lambda',TestLam(jj)),LB,UB));
    Gap(jj) = TrueMean-TruncatedMean;
end

plot(TestLam,Gap)

Notice the gap with these truncation bounds and a lambda of 0.6 is still small and is negligible as lambda approaches zero.

lam = 0.6;    %  <---- try different values   (must be greater than 0)
pd = makedist('Poisson','Lambda',lam)
pdt = truncate(pd,LB,UB)
mean(pd)                         % 0.6
mean(pdt)                        % 0.5998

Other Resources:
1. Wiki for Truncated Distributions
2. What is a Truncated Distribution
3. MATLAB documentation for truncate(), makedist()
4. MATLAB: Working with Probability Distribution (Objects)



来源:https://stackoverflow.com/questions/58565042/truncating-poisson-distribution-on-desired-support-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!