Package {PBGoF}


Type: Package
Title: Parametric Bootstrap Tests for the Skew-Normal Distribution
Version: 0.1.0
Date: 2026-09-23
Maintainer: Hongxiang Li <hxli@ynnu.edu.cn>
Depends: R (≥ 4.1)
Description: Provides goodness-of-fit tests for the skew-normal distribution with estimated parameters. Implements Kolmogorov-Smirnov and Cramér-von Mises tests using parametric bootstrap or precomputed simulation quantiles, together with robust parameter estimation procedures. Package methods and documentation are described by Li and Khang (2026) https://github.com/Divo-Lee/PBGoF.
Imports: methods, sn
Suggests: knitr, rmarkdown
VignetteBuilder: knitr
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
Encoding: UTF-8
Config/roxygen2/version: 8.0.0
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-09-23 06:56:25 UTC; chels
Author: Hongxiang Li [aut, cre], Tsung Fei Khang [aut]
Repository: CRAN
Date/Publication: 2026-10-02 12:10:09 UTC

Fast Skew-Normal Goodness-of-Fit Tests Using Precomputed Quantiles

Description

Computes a skew-normal goodness-of-fit statistic and obtains an approximate p-value from a precomputed 100,000-replicate quantile table.

Usage

PBGoF_ks_test(data, ks_table = NULL)

PBGoF_cvm_test(data, cvm_table = NULL)

Arguments

data

A numeric vector whose length is represented in the table.

ks_table, cvm_table

Optional custom quantile tables. If NULL, the corresponding table bundled with PBGoF is used.

Details

The fitted absolute CP skewness is rounded to two decimal places and truncated to [0.01, 0.99]. P-values are conservative step-function approximations between 0.01 and 0.99. No interpolation is performed.

If the fitted gamma1 is negative, table lookup uses abs(gamma1). Reflection of a skew-normal variable changes the signs of the DP shape parameter and CP skewness, but the null distributions of the EDF statistics are invariant to this sign change (Mateu-Figueras et al., 2007). The bundled tables therefore require only non-negative skewness values.

For samples larger than 500, all observations remain in the fit and empirical distribution function, while the external statistic multiplier and table row use n_used = 500.

Value

A list containing statistic, actual sample size n, lookup and scaling sample size n_used, gamma1_hat, gamma1_used, and p.value.

References

Mateu-Figueras, G., Puig, P., and Pewsey, A. (2007). Goodness-of-fit tests for the skew-normal distribution when the parameters are estimated from the data. Communications in Statistics—Theory and Methods, 36(9), 1735–1755. doi:10.1080/03610920601126217

Examples


set.seed(123)
x <- sn::rsn(50, xi = 0, omega = 1, alpha = 3)
PBGoF_ks_test(x)
PBGoF_cvm_test(x)


Parametric Bootstrap Goodness-of-Fit Tests for a Skew-Normal Distribution

Description

Tests skew-normal goodness of fit using a parametric bootstrap, re-estimating the model in each bootstrap sample with sn.fit.robust().

Usage

sn.para.bootstrap.ks.test(data = NULL, B = 1000L, seed = 103L,
  verbose = FALSE)

sn.para.bootstrap.cvm.test(data = NULL, B = 1000L, seed = 103L,
  verbose = FALSE)

Arguments

data

A numeric vector containing at least 10 finite observations.

B

A positive integer giving the number of bootstrap samples.

seed

A single integer, or NULL to use the current random-number stream. The caller's random-number state is restored on exit.

verbose

Logical; whether to print a short summary.

Details

The KS function uses \sqrt{n}D; the CvM function uses the Cramér–von Mises statistic. Failed fits are excluded and the p-value uses the finite-simulation correction (1 + \sum I(T_b >= T_0))/(B_{valid}+1). The names ending in .1 are compatibility aliases.

Value

A single numeric bootstrap p-value with attributes statistic, B, valid, and failed.

Examples


set.seed(123)
x <- sn::rsn(50, xi = 0, omega = 1, alpha = 3)
sn.para.bootstrap.ks.test(x, B = 99)
sn.para.bootstrap.cvm.test(x, B = 99)


Numerically Robust Fitting of the Skew-Normal Distribution

Description

Fits a skew-normal distribution by MLE, then falls back to default penalized MLE and matching-prior penalized MLE when necessary.

Usage

sn.fit.robust(data = NULL, para_form = c("DP", "CP"))

Arguments

data

A numeric vector containing at least 10 finite observations.

para_form

Parameterization of the result: "DP" for direct parameters or "CP" for centered parameters.

Details

Robustness here concerns numerical fitting failures, not resistance to outliers or model contamination.

Value

A named numeric vector containing parameter estimates and standard errors. If all fitting procedures fail, all entries are NA.

Examples


set.seed(123)
x <- sn::rsn(100, xi = 0, omega = 1, alpha = 5)
sn.fit.robust(x, "DP")
sn.fit.robust(x, "CP")


Graphical Check of a Fitted Skew-Normal Distribution

Description

Draws a density-scale histogram of the observed data and overlays a skew-normal density fitted by sn.fit.robust().

Usage

sn.plot.check(
  data,
  breaks = "FD",
  col = "grey85",
  border = "white",
  curve_col = "#6CC6C6",
  lwd = 2,
  main = NULL,
  xlab = "Values",
  add_rug = TRUE,
  ...
)

Arguments

data

A numeric vector containing at least 10 finite observations.

breaks

Histogram breaks passed to graphics::hist().

col

Fill color for the histogram.

border

Border color for histogram bars.

curve_col

Color of the fitted skew-normal density curve.

lwd

Line width of the fitted density curve.

main

Main plot title.

xlab

Label for the horizontal axis.

add_rug

Logical; whether to add observations as a rug plot.

...

Additional graphical arguments passed to graphics::hist().

Details

This visual model check complements, but does not replace, the formal goodness-of-fit tests provided by PBGoF.

Value

Invisibly returns a list containing the fitted DP parameters, histogram object, and coordinates of the fitted density curve.

Examples

set.seed(123)
x <- sn::rsn(100, xi = 0, omega = 1, alpha = 4)
sn.plot.check(x)