Bug 16008 - logLik.glm when some weights are zero gives -Inf and df includes the zero weighted rows. Different than logLik.lm.
Summary: logLik.glm when some weights are zero gives -Inf and df includes the zero wei...
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Models (show other bugs)
Version: R 3.1.1
Hardware: Other Other
: P5 normal
Assignee: R-core
Depends on:
Reported: 2014-10-03 22:32 UTC by Bill Dunlap
Modified: 2014-10-03 22:32 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Bill Dunlap 2014-10-03 22:32:26 UTC
If some prior weights are zero, then logLik(glm(..., weights=weights)) and logLik(lm(..., weights=weights)) differ.  The glm version gives a log likelihood of -Inf and a nobs attribute that includes the zero-weighted cases.  The lm version omits the zero-weighted cases before calculating the log likelihood and nobs.  Is this expected behavior?  Or should people be using subset=weights>0 with glm?

> gfit <- glm(y ~ x, data=data.frame(x=1:10,y=sin((1:10)/3)), weights=as.numeric(x>1.5))
> nobs(gfit)
[1] 9
> str(unclass(logLik(gfit))) # nobs(gfit) != nobs(logLik(gfit)), logLik is -Inf
 atomic [1:1] -Inf
 - attr(*, "nobs")= int 10
 - attr(*, "df")= num 3

> lfit <- lm(y ~ x, data=data.frame(x=1:10,y=sin((1:10)/3)), weights=as.numeric(x>1.5))
> nobs(lfit)
[1] 9
> str(unclass(logLik(lfit))) # nobs(lfit) == nobs(logLik(lfit)), logLik finite
 atomic [1:1] -0.471
 - attr(*, "nall")= int 9
 - attr(*, "nobs")= int 9
 - attr(*, "df")= num 3