-
Notifications
You must be signed in to change notification settings - Fork 0
/
logLik.R
37 lines (36 loc) · 1012 Bytes
/
logLik.R
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
#' Extract log-likelihood
#'
#' @description Find the log-likelihood of a fitted model when \code{estmethod}
#' is \code{"ml"} or \code{"reml"}.
#'
#' @param object A fitted model object from [splm()], [spautor()], [spglm()], or [spgautor()] where \code{estmethod}
#' is \code{"ml"} or \code{"reml"}.
#' @param ... Other arguments. Not used (needed for generic consistency).
#'
#' @return The log-likelihood.
#'
#' @name logLik.spmodel
#' @method logLik splm
#' @order 1
#' @export
#'
#' @examples
#' spmod <- splm(z ~ water + tarp,
#' data = caribou,
#' spcov_type = "exponential", xcoord = x, ycoord = y
#' )
#' logLik(spmod)
logLik.splm <- function(object, ...) {
if (object$estmethod %in% c("reml", "ml")) {
minus2loglik <- object$optim$value
loglik <- -1 / 2 * minus2loglik
return(loglik)
} else {
stop("log likelihood is only defined for the reml or ml estimation")
}
}
#' @rdname logLik.spmodel
#' @method logLik spautor
#' @order 2
#' @export
logLik.spautor <- logLik.splm