Closed andrechalom closed 6 years ago
I don't know why this restriction is here in the first place! I was going to blame it on previous code again, but it seems to be my fault.
My inclination is to remove it entirely and let the results fall back to stats:::AIC.default
; I might spend a little more time thinking about why I did it this way in the first place/what might go wrong?
dd <- data.frame(y=rpois(10,lambda=2))
> m1 <- glm(y~1,data=dd, family=poisson)
> m2 <- mle2(y~dpois(exp(logmu)),data=dd,start=list(logmu=0))
> AIC(m1,m2)
df AIC
m1 1 35.46634
m2 1 35.46634
> AIC(m2,m1)
Error in AIC(m2, m1) : all objects in list must be class mle2
> stats:::AIC.default(m2,m1)
df AIC
m2 1 35.46634
m1 1 35.46634
That's a fair point. I thought that this was in place to prevent errors like AIC(m1, m2, 2)
instead of AIC(m1, m2, k=2)
, but that fails with a reasonably informative message anyway:
> AIC(m1, m2, 2)
Error in UseMethod("logLik") :
no applicable method for 'logLik' applied to an object of class "c('double', 'numeric')"
this seems to be OK now. Close, or is a more fundamental fix necessary/useful?
Yes, I've just tested the development version of our package sads against the development version of bbmle, everything works as intended. I was waiting your input on "why I did it this way in the first place/what might go wrong?".
sads
package defines two classes that inherit frommle2
. Most methods work flawlessly onfitsad
andfitrad
classes, as method dispatching is done considering inheritance. However, the internal code forbbmle::AIC
checks if all objects passed are of classmle2
, which causes the following code to fail:This can be fixed by changing the code in AIC to