logLik_lnorm | R Documentation |
Log-likelihood (and by extension AIC and BIC) for log-normal models fit
with stats::lm(log(y) ~ ...)
are computed with stats::dnorm(log(y), ...)
instead of with stats::dlnorm(y, ...)
, which makes comparing different
families difficult. This function is aimed at rectifying this. See examples.
logLik_lnorm(object, REML = FALSE)
AIC_lnorm(object, k = 2, REML = FALSE)
BIC_lnorm(object, REML = FALSE)
object |
A fitted model object. The model must meet all of the following (will throw an error if not met):
|
REML |
Only |
k |
numeric, the penalty per parameter to be used; the
default |
REML
is not (yet) supported. Make sure you are comparing correct
LL/AIC/BIC values.
data("mtcars")
mtcars$mpg <- floor(mtcars$mpg)
model_lnorm <- lm(log(mpg) ~ factor(cyl), mtcars)
model_norm <- lm(mpg ~ factor(cyl), mtcars)
model_pois <- glm(mpg ~ factor(cyl), mtcars, family = poisson())
# No, that first one is wrong...
(aics <- AIC(model_lnorm, model_norm, model_pois))
aics[1, "AIC"] <- AIC_lnorm(model_lnorm)
aics # better!
# Should support any model really... =====================
model_lnorm <- lme4::lmer(log(mpg) ~ factor(cyl) + (1 | gear), mtcars, REML = FALSE)
model_norm <- lme4::lmer(mpg ~ factor(cyl) + (1 | gear), mtcars, REML = FALSE)
model_pois <- lme4::glmer(mpg ~ factor(cyl) + (1 | gear), mtcars, family = poisson())
# No, that first one is wrong...
(aics <- AIC(model_lnorm, model_norm, model_pois))
aics[1, "AIC"] <- AIC_lnorm(model_lnorm)
aics # better!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.