Learn R Programming

NeuDist (version 1.0.1)

gofic: Generic Goodness-of-Fit(GoF) and Model Diagnostics Function

Description

Computes log-likelihood, information criteria (AIC, BIC, AICC, HQIC) and classical goodness-of-fit statistics (Kolmogorov–Smirnov, Cramér–von Mises, Anderson–Darling) for a given numeric data vector and user-supplied density and distribution functions.

Usage

gofic(x, params, dfun, pfun, plot = TRUE, verbose = FALSE)

Value

An object of class "gofic" containing:

  • logLik Numeric; log-likelihood value.

  • AIC Akaike Information Criterion.

  • BIC Bayesian Information Criterion.

  • AICC Corrected Akaike Information Criterion.

  • HQIC Hannan–Quinn Information Criterion.

  • KS Object returned by stats::ks.test().

  • CVM Object returned by goftest::cvm.test().

  • AD Object returned by goftest::ad.test().

  • n Sample size.

  • params Model parameters supplied.

The object is returned invisibly.

Arguments

x

Numeric vector of observed data. Must contain at least two values.

params

Named list of model parameters passed to dfun and pfun.

dfun

A probability density function with signature dfun(x, ...) returning numeric densities.

pfun

A cumulative distribution function with signature pfun(q, ...) returning cumulative probabilities.

plot

Logical; if TRUE, plots empirical vs theoretical CDF. Default is TRUE.

verbose

Logical; if TRUE, prints the output object. Default is FALSE.

Details

Optionally plots the empirical cumulative distribution function (ECDF) against the theoretical cumulative distribution function.

The supplied dfun and pfun must accept arguments x and q respectively, followed by named model parameters. Density values must be finite and positive; non-positive densities trigger a warning but computation proceeds.

See Also

print.gofic, ks.test, cvm.test, ad.test

Examples

Run this code
# Example 1 with built-in Weibull distribution
# \donttest{
set.seed(123)
x <- rweibull(100, shape = 2, scale = 1)
out <- gofic(x, params = list(shape = 2, scale = 1),
      dfun = dweibull, pfun = pweibull, plot=FALSE)
out
# }

# Example 2: For a user defined distribution
# Goodness-of-Fit(GoF) and Model Diagnostics for Chen-Exponential distribution
#Data
x <- stress
#ML Estimates    
params = list(alpha=2.5462, beta=0.0537, lambda=87.6028)
# Display plot and print numerical summary
gofic(x, params = params,
        dfun = dchen.exp, pfun = pchen.exp, plot = TRUE, verbose = TRUE)

# Display plot only (no numerical summary)
gofic(x, params = params,
        dfun = dchen.exp, pfun = pchen.exp, plot = TRUE, verbose = FALSE)

# Print numerical summary only (no plot)
gofic(x, params = params,
        dfun = dchen.exp, pfun = pchen.exp, plot = FALSE, verbose = TRUE)

# Display plot; numerical summary stored in 'out'
out <- gofic(x, params = params,
              dfun = dchen.exp, pfun = pchen.exp, plot = TRUE, verbose = FALSE)
print.gofic(out)

# Neither plot nor console output; results stored in 'out'
out <- gofic(x, params = params,
               dfun = dchen.exp, pfun = pchen.exp, plot = FALSE, verbose = FALSE)
print.gofic(out)

Run the code above in your browser using DataLab