[R] problem with logLik and offsets
Jarrod Hadfield
j.hadfield at sheffield.ac.uk
Wed Jan 3 19:39:18 CET 2007
Hi,
I'm trying to compare models, one of which has all parameters fixed
using offsets. The log-likelihoods seem reasonble in all cases except
the model in which there are no free parameters (model3 in the toy
example below). Any help would be appreciated.
Cheers,
Jarrod
x<-rnorm(100)
y<-rnorm(100, 1+x)
model1<-lm(y~x)
logLik(model1)
sum(dnorm(y, predict(model1), summary(model1)$sigma,log=TRUE))
# no offset - in agreement
model2<-lm(y~offset(rep(1,100))+x-1)
logLik(model2)
sum(dnorm(y, predict(model2),summary(model2)$sigma,log=TRUE))
# offset and free parameters - in agreement
model3<-lm(y~offset(rep(1,100))+offset(x)-1)
logLik(model3)
sum(dnorm(y, predict(model3),summary(model3)$sigma,log=TRUE))
# offset only - discrepancy
sum(predict(model3)-c(1+x))
# yet predict is correct
More information about the R-help
mailing list