Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
glmfit loglikelihood?

Subject: glmfit loglikelihood?

From: Phillip Maskala

Date: 11 May, 2011 07:34:04

Message: 1 of 3

Hello,

im using glmfit and im wondering how can i get the log-likelihood?
i've read the forums and saw that you can calculate it after you get the results from glmfit, but they did it for a logistics regression while im doing a poisson regression and a normal regression, so im not confident enough that i understodd how to do it well.

Can anyone give me a hint on how to calculate it for both?
i do need the loglikelihood although it's mostly for consistency reasons in my reports.

Thanks in advance

Subject: glmfit loglikelihood?

From: Phillip Maskala

Date: 13 May, 2011 01:05:21

Message: 2 of 3

ANyone? ;(

Subject: glmfit loglikelihood?

From: Tom Lane

Date: 16 May, 2011 17:40:43

Message: 3 of 3

> im using glmfit and im wondering how can i get the log-likelihood? i've
> read the forums and saw that you can calculate it after you get the
> results from glmfit, but they did it for a logistics regression while im
> doing a poisson regression and a normal regression, so im not confident
> enough that i understodd how to do it well.
>
> Can anyone give me a hint on how to calculate it for both?

Though it's not available directly from glmfit or glmval, you can compute
the likelihood easily. First you use the estimated coefficients to get the
distribution parameters, which are "fitted" values. Then you compute the
density at the response values using those parameters. Then sum their logs,
and take the negative if you like.

Here's an example with the default (log) link for the Poisson distribution.

x = 10*rand(200,1);
y = poissrnd(exp(-2+x/4));
p = glmfit(x,y,'poisson')
mu = glmval(p,x,'log');
nlogl = -sum(log(poisspdf(y,mu)))

-- Tom

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us