Log-Likelihood
A robust function to compute the log-likelihood of a model, as well as individual log-likelihoods (for each observation) whenever possible. Can be used as a replacement for stats::logLik()
out of the box, as the returned object is of the same class (and it gives the same results by default).
get_loglikelihood(x, ...) loglikelihood(x, ...) ## S3 method for class 'lm' get_loglikelihood(x, estimator = "ML", REML = FALSE, verbose = TRUE, ...)
x |
A model. |
... |
Passed down to |
estimator |
Corresponds to the different estimators for the standard deviation of the errors. If |
REML |
Only for linear models. This argument is present for compatibility with |
verbose |
Toggle warnings and messages. |
An object of class "logLik"
, also containing the log-likelihoods for each observation as a per_observation
attribute (attributes(get_loglikelihood(x))$per_observation
) when possible. The code was partly inspired from the nonnest2 package.
x <- lm(Sepal.Length ~ Petal.Width + Species, data = iris) get_loglikelihood(x, estimator = "ML") # Equivalent to stats::logLik(x) get_loglikelihood(x, estimator = "REML") # Equivalent to stats::logLik(x, REML=TRUE) get_loglikelihood(x, estimator = "OLS")
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.