logLik.gkwfit: Extract Log-Likelihood from a gkwfit Object

logLik.gkwfitR Documentation

Extract Log-Likelihood from a gkwfit Object

Description

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.

Usage

## S3 method for class 'gkwfit'
logLik(object, ...)

Arguments

object

An object of class "gkwfit", typically the result of a call to gkwfit.

...

Additional arguments (currently ignored).

Details

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).

Value

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).

Author(s)

Lopes, J. E.

See Also

gkwfit, AIC, BIC, logLik

Examples


# 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")



gkwreg documentation built on April 16, 2025, 1:10 a.m.