필터 지우기
필터 지우기

Why deviance returned by GLMFIT is not = -2*LogLikelihood?

조회 수: 3 (최근 30일)
Francisco de Castro
Francisco de Castro 2012년 3월 6일
댓글: David Nielsen 2017년 3월 4일
I'm working with GLM models using glmfit. After fitting the model I need to calculate the LogLikelihood (which is not returned directly by glmfit). I've seen in many sources that deviance (which IS returned by glmfit) is equal to -2*LogLikelihood. However, if I calculate the LogLikelihood separately (see example below with binomial distribution) I get totally different answers. Any idea what I'm doing wrong? I took the example data from MATLAB doc. on glmfit
x = [2100 2300 2500 2700 2900 3100 3300 3500 3700 3900 4100 4300]';
n = [48 42 31 34 31 21 23 23 21 16 17 21]';
y = [1 2 0 3 8 8 14 17 19 15 17 21]';
[b,dev,stats]= glmfit(x,[y n],'binomial');
yfit= glmval(b, x,'logit','size',n);
dev/-2
logLikelihood= nansum(log( binopdf( y, n, yfit)))

채택된 답변

Tom Lane
Tom Lane 2012년 3월 6일
Two things. First, the last argument to binopdf should be the fitted probability, not the fitted counts. Second, the deviance is defined with respect to a "full" model that has a separate fitted value for every observation. So -dev/2 reproduces this value:
sum(log(binopdf(y,n,yfit./n))) - sum(log(binopdf(y,n,y./n)))
If you need the log likelihood value, your way of computing it is fine, once you correct the binopdf input.
  댓글 수: 2
Marris Atwood
Marris Atwood 2015년 6월 9일
So you mean the saturated model's log likelihood, i.e., sum(log(binopdf(y,n,y./n))), is not necessarily always 0, right? That is acceptable, but how I should know if that is 0?
David Nielsen
David Nielsen 2017년 3월 4일
Would this not be the log likelihood ratio, i.e. the ratio of the log likelihood of the fitted model and the saturated model?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by