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/-2logLikelihood= nansum(log( binopdf( y, n, yfit)))
Best Answer