Skip to content

Instantly share code, notes, and snippets.

@k-barton
Last active December 8, 2022 15:33
Show Gist options
  • Save k-barton/c1df2e6b59bf947bbdd25cb410163e4f to your computer and use it in GitHub Desktop.
Save k-barton/c1df2e6b59bf947bbdd25cb410163e4f to your computer and use it in GitHub Desktop.
Standard methods for `phylo[g]lm` and `pglmm_compare` needed to use these model types with MuMIn functions.
local({
family.phylolm <-
function (object, ...) {
stop("???")
}
logLik.pglmm_compare <-
function (object, ...) {
rval <- object$logLik
attr(rval, "nobs") <- nrow(object$X)
attr(rval, "df") <- object$logLik + object$AIC / 2
class(rval) <- "logLik"
rval
}
nobs.pglmm_compare <-
function (object, ...) {
nrow(object$X)
}
family.pglmm_compare <-
function (object, ...) {
switch(object$family, gaussian = , binomial =, poisson =
get(object$family, asNamespace("stats"))(),
stop(paste("family", sQuote(object$family), "not supported yet"))
)
}
registerS3method("logLik", "phyloglm", function (object, ...) {
rval <- object$logLik
attr(rval, "nobs") <- object$n
attr(rval, "df") <- object$d + 1
class(rval) <- "logLik"
rval
})
registerS3method("logLik", "pglmm_compare", logLik.pglmm_compare)
registerS3method("nobs", "phyloglm", MuMIn:::nobs.phylolm)
registerS3method("nobs", "pglmm_compare", nobs.pglmm_compare)
registerS3method("family", "pglmm_compare", family.pglmm_compare)
registerS3method("family", "phylolm", family.phylolm)
registerS3method("family", "phyloglm", family.phylolm)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment