As you mentioned, the deviance does not always reduce to: D = -2(loglikelihood(model))
It does for ungrouped data, such as for binary logistic regression. So let's stick with the original definition. In this case, we need the log-likelihood for the saturated model. x = rnorm(10) y = rpois(10,lam=exp(1 + 2*x)) test = glm(formula = y ~ x, family = poisson) sm <- glm(y ~ factor(1:10),family=poisson) mydev <- as.numeric(2*(logLik(sm)-logLik(test))) mydev deviance(test) On Fri, Apr 15, 2011 at 7:00 AM, Jeffrey Pollock <jpoll...@williamhill.co.uk> wrote: > It has always been my understanding that deviance for GLMs is defined > by; > > > > D = -2(loglikelihood(model) - loglikelihood(saturated model)) > > > > and this can be calculated by (or at least usually is); > > > > D = -2(loglikelihood(model)) > > > > As is done so in the code for 'polr' by Brian Ripley (in the package > 'MASS') where the -loglikehood is minimised using optim; > > > > res <- optim(s0, fmin, gmin, method = "BFGS", hessian = Hess, ...) > > . > > . > > . > > deviance <- 2 * res$value > > > > If so, why is it that; > > > >> x = rnorm(10) > >> y = rpois(10,lam=exp(1 + 2*x)) > >> test = glm(formula = y ~ x, family = poisson) > >> deviance(test) > > [1] 5.483484 > >> -2*logLik(test) > > [1] 36.86335 > > > > I'm clearly not understanding something here, can anyone shed any light? > Why is; > > > > -2*logLik(test) =/= deviance(test) ??? > > > > I think this is something that is poorly understood all over the > internet (at least from my google searches anyway!) > > > > Thanks, > > > > Jeff > > > > ----------------------------------------- > ********************************************** Confidentiality: The contents > of this e-mail and any attachments transmitted with it are intended to be > confidential to the intended recipient; and may be privileged or otherwise > protected from disclosure. If you are not an intended recipient of this > e-mail, do not duplicate or redistribute it by any means. Please delete it > and any attachments and notify the sender that you have received it in error. > This e-mail is sent by a William Hill PLC group company. The William Hill > group companies include, among others, William Hill PLC (registered number > 4212563), William Hill Organization Limited (registered number 278208), > William Hill Credit Limited (registered number 413846), WHG (International) > Limited (registered number 99191) and WHG Trading Limited (registered number > 101439). Each of William Hill PLC, William Hill Organization Limited and > William Hill Credit Limited is registered in Engl! > and and Wales and has its registered office at Greenside House, 50 Station > Road, Wood Green, London N22 7TP. Each of WHG (International) Limited and WHG > Trading Limited is registered in Gibraltar and has its registered office at > 6/1 Waterport Place, Gibraltar. Unless specifically indicated otherwise, the > contents of this e-mail are subject to contract; and are not an official > statement, and do not necessarily represent the views, of William Hill PLC, > its subsidiaries or affiliated companies. Please note that neither William > Hill PLC, nor its subsidiaries and affiliated companies can accept any > responsibility for any viruses contained within this e-mail and it is your > responsibility to scan any emails and their attachments. William Hill PLC, > its subsidiaries and affiliated companies may monitor e-mail traffic data and > also the content of e-mails for effective operation of the e-mail system, or > for security, purposes. ********************************************* > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.