Why do I get different results from poisspdf and computing the probability myself?

5 ビュー (過去 30 日間)
I'm writing a maximum likelihood estimator for the Poisson distribution, and I get different results from using poisspdf versus computing the probability myself with the formula (which is listed on the help page for poisspdf). I'm taking the log-likelihood, and here's my code:
n = 40;
d = 10;
X = poissrnd(30, [d n]);
mlearray = zeros(100,1);
mlearray2 = zeros(100,1);
mlearray3 = zeros(100,1);
for lambda = 1:100
mlearray(lambda) = sum(sum(log(poisspdf(lambda, X))));
mlearray2(lambda) = sum(sum(X*log(lambda)-lambda-log(factorial(X))));
mlearray3(lambda) = sum(sum(log(lambda.^X*exp(-lambda)./factorial(X))));
end
plot(mlearray)
hold on
plot(mlearray2,'r')
plot(mlearray3,'g:')
axis([20 40 min(mlearray(20:40)) max(mlearray)])
hold off
mlearray2 and mlearray3 give the same result, as expected (and the correct result I might add, with a peak at 30), while mlearray peaks at 29. This difference persists regardless of n and d. It doesn't appear to be an off-by-one error, since adding or subtracting a one here and there fails to fix the peak without distortion of the curve.
EDIT: minor code tweak unrelated to the issue.

採用された回答

Yu Jiang
Yu Jiang 2014 年 9 月 5 日
編集済み: Yu Jiang 2014 年 9 月 5 日
Hi Daniel
I think you need to change
poisspdf(lambda, X)
to
poisspdf(X,lambda)
This is according to the documentation at the following link
- Yu
  1 件のコメント
Daniel LeJeune
Daniel LeJeune 2014 年 9 月 5 日
編集済み: Daniel LeJeune 2014 年 9 月 5 日
Thanks, that was it. I must have overlooked that. I guess it makes sense that they would be close since the expectation of X is lambda, but I wonder why it's off by one.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by