Re: likelihood estimates of glmfit results?
- From: "Gabriel Diaz" <eyeballjunk@xxxxxxxxx>
- Date: Mon, 8 Jun 2009 22:15:02 +0000 (UTC)
This doesn't seem to work for me. Here's a simple toy problem for which I know the LL and AIC....
x = predictor values
y = responses
n = number of stimulus presentations
I'm trying to calculate AIC for a binomial logistic regression, but my LL is incorrect. I've verified the correct log likelihood using two other statistics / computation packages. To be clear, I'm not suggesting that matlab is bugged. More reasonably, my own calculations are bugged!
Any advice with that log likelihood calculation?
****************
clear all
x = [ 53 57 58 63 66 67 68 69 70 72 73 75 76 78 79 81 ]';
y = [ 1 1 1 1 0 0 0 0 2 0 0 1 0 0 0 0 ]';
n = [ 1 1 1 1 1 3 1 1 4 1 1 2 2 1 1 1 ]';
[betas dev stats]= glmfit(x,[y n],'binomial', 'link', 'logit');
fitted = glmval(betas,x,'logit');
%% LL should be -10.1576
logLikelihood = sum(log( binopdf( y, n,fitted)))
%% AIC should be 24.3152
AIC = -2*logLikelihood + 2*numel(betas)
- gD
Peter Perkins <Peter.Perkins@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message <gt9qnu$7qm$1@xxxxxxxxxxxxxxxxxx>...
C F wrote:.
I'm trying to find the AIC as well, and it seems I need the fitted log likelihood function value. I understand deviance is the difference between LL of the fitted model and max possible log-likelihood. But I'm looking for the actual LL as I'm comparing this to another non-GLM model and have access only to the fitted LL in that model. Thus, if there is a way to either recover the max possible LL or directly recoverd the fitted LL that would be very helpful.
You don't say what kind of GLM you're fitting, but generally speaking: Use GLMVAL to compute fitted values for each observation. Then use the appropriate PDF function to compute individual likelihoods, then log and sum. So for a binomial GLM (e.g. logistic regression),
betaHat = glmfit(X,[y,n],'binomial');
pFitted = glmval(betaHat,X,'logistic','size',n);
LL = sum(log(binopdf(y,n,pFitted)));
For a GLM with an estimated dispersion parameter, you'll have to use that in the PDF function call.
(also, i'm sure this is wrong, but isn't the LL of the fitted model in fact the "maximum" possible LL? i know its not, but why?)
The maximum possible likelihood is the likelihood for a model where each fitted value is the observed value -- in effect one parameter for each observation. Not a very useful model.
Hope this helps.
- Follow-Ups:
- Re: likelihood estimates of glmfit results?
- From: Tom Lane
- Re: likelihood estimates of glmfit results?
- Prev by Date: Re: Overriding property accessors
- Next by Date: clearing text files
- Previous by thread: Callback help when using uimenu
- Next by thread: Re: likelihood estimates of glmfit results?
- Index(es):
Relevant Pages
|