File: get_loglikelihood.Rd

package info (click to toggle)
r-cran-insight 0.19.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,308 kB
  • sloc: sh: 13; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 2,559 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_loglikelihood.R
\name{get_loglikelihood}
\alias{get_loglikelihood}
\alias{loglikelihood}
\alias{get_loglikelihood.lm}
\title{Log-Likelihood}
\usage{
get_loglikelihood(x, ...)

loglikelihood(x, ...)

\method{get_loglikelihood}{lm}(
  x,
  estimator = "ML",
  REML = FALSE,
  check_response = FALSE,
  verbose = TRUE,
  ...
)
}
\arguments{
\item{x}{A model.}

\item{...}{Passed down to \code{logLik()}, if possible.}

\item{estimator}{Corresponds to the different estimators for the standard
deviation of the errors. If \code{estimator="ML"} (default), the scaling is
done by n (the biased ML estimator), which is then equivalent to using
\code{stats::logLik()}. If \code{estimator="OLS"}, it returns the unbiased
OLS estimator. \code{estimator="REML"} will give same results as
\code{logLik(..., REML=TRUE)}.}

\item{REML}{Only for linear models. This argument is present for
compatibility with \code{stats::logLik()}. Setting it to \code{TRUE} will
overwrite the \code{estimator} argument and is thus equivalent to setting
\code{estimator="REML"}. It will give the same results as
\code{stats::logLik(..., REML=TRUE)}. Note that individual log-likelihoods
are not available under REML.}

\item{check_response}{Logical, if \code{TRUE}, checks if the response variable
is transformed (like \code{log()} or \code{sqrt()}), and if so, returns a corrected
log-likelihood. To get back to the original scale, the likelihood of the
model is multiplied by the Jacobian/derivative of the transformation.}

\item{verbose}{Toggle warnings and messages.}
}
\value{
An object of class \code{"logLik"}, also containing the
log-likelihoods for each observation as a \code{per_observation} attribute
(\code{attributes(get_loglikelihood(x))$per_observation}) when possible.
The code was partly inspired from the \CRANpkg{nonnest2} package.
}
\description{
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 \code{stats::logLik()} out of the box, as the
returned object is of the same class (and it gives the same results by
default).
}
\examples{
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")
}