logLik.gkwfit | R Documentation |
Extracts the maximized log-likelihood value from a model fitted by gkwfit
.
It returns an object of class "logLik"
, which includes attributes for the
degrees of freedom ("df"
) and the number of observations ("nobs"
) used in the fit.
## S3 method for class 'gkwfit'
logLik(object, ...)
object |
An object of class |
... |
Additional arguments (currently ignored). |
This method provides compatibility with standard R functions that operate on
log-likelihood values, such as AIC
, BIC
,
and likelihood ratio tests. It retrieves the log-likelihood stored during the
model fitting process (in object$loglik
) and attaches the required
attributes (object$df
for the number of estimated parameters and
object$nobs
for the number of observations).
An object of class "logLik"
. This is the numeric log-likelihood value
with the following attributes:
df |
The number of estimated parameters in the model (integer). |
nobs |
The number of observations used for fitting the model (integer). |
Lopes, J. E.
gkwfit
, AIC
, BIC
, logLik
# Generate data and fit two models
set.seed(2203)
y <- rgkw(50, alpha = 2, beta = 3, gamma = 1, delta = 0, lambda = 1.5)
fit1 <- gkwfit(data = y, family = "kkw", plot = FALSE) # KKw model
fit2 <- gkwfit(data = y, family = "ekw", plot = FALSE) # EKw model
# Extract log-likelihood values
ll1 <- logLik(fit1)
ll2 <- logLik(fit2)
print(ll1)
print(ll2)
# Use for likelihood ratio test
lr_stat <- -2 * (as.numeric(ll1) - as.numeric(ll2))
df_diff <- attr(ll1, "df") - attr(ll2, "df")
p_value <- pchisq(lr_stat, df = abs(df_diff), lower.tail = FALSE)
cat("LR statistic:", lr_stat, "\n")
cat("df:", df_diff, "\n")
cat("p-value:", p_value, "\n")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.