Type: Package
Title: Khmaladze Martingale Transformation Goodness-of-Fit Test
Version: 1.0.0
Description: Consider a goodness-of-fit problem of testing whether a random sample comes from one sample location-scale model where location and scale parameters are unknown. It is well known that Khmaladze-martingale-transformation method proposed by Khmaladze (1981) <doi:10.1137/1126027> provides asymptotic distribution free test. This package provides test statistic and critical value of the test for normal, Cauchy, and logistic distributions. This package used the main algorithm proposed by Kim (2020) <doi:10.1007/s00180-020-00971-7> and tests for other distributions will be available at the later version.
License: GPL-2
Encoding: UTF-8
Depends: R (≥ 3.5)
Imports: Rcpp (≥ 1.0.10), ggplot2, stats, utils, Rsolnp, graphics, gumbel
LinkingTo: Rcpp, RcppArmadillo
NeedsCompilation: yes
Packaged: 2026-04-30 01:49:08 UTC; ji_wo
Author: Jiwoong Kim [aut, cre]
Maintainer: Jiwoong Kim <jwboys26@gmail.com>
Repository: CRAN
Date/Publication: 2026-05-04 19:00:19 UTC

Description

Run the Anderson-Darling (AD) test.

Usage

AD(Z, Distr)

Arguments

Z

a normalized random sample of n observations.

Distr

a null distribution of the GOF test. It should be one of "Normal", "Logistic", "Cauchy", or "Gumbel

Value

A test statistic of the AD test.

Examples


n=10
mu=2
sigma=1

X = rnorm(n, mu, sigma)

muhat = mean(X)
sighat = sd(X)

Z = (X-muhat)/sighat 
null_distr="Normal"
AD_teststat = AD(Z, null_distr)
AD_teststat

Brownian Motion

Description

Get a d-dimension Brownian motion B(t) and its graph

Usage

BM(x = 0, t = 1, n = 10, d = 1)

Arguments

x

a starting point of the Brownian motion, B(0).

t

end of time, that is, 0=t_{0}<t_{1}<...<t_{n}=t

n

the last index of the time, that is, t_{n}=t

d

a dimension of the Brownian motion: 1 or 2.

Value

A list of

tn

t_{n}

Bt1

a vector of the Brownian motion (B_{1}(t_{0},...,B_{1}(t_{n})))

Bt2

a vector of the Brownian motion (B_{2}(t_{0},...,B_{2}(t_{n})))

Examples


#### Generate an 2-dimensional Brownian motion and its graph
x0=c(0,0)
lst = BM(x=x0, t=1, n=10, d=2)


Run other GOF tests

Description

Run the Cramer-von Mises (CvM) and Watson tests.

Usage

CvM(Z, Distr)

Arguments

Z

a normalized random sample of n observations.

Distr

a null distribution of the GOF test. It should be one of "Normal", "Logistic", "Cauchy", or "Gumbel

Value

A vector of the CvM and Watson test statistics.

Examples


n=10
mu=2
sigma=1

X = rnorm(n, mu, sigma)

muhat = mean(X)
sighat = sd(X)

Z = (X-muhat)/sighat 
null_distr="Normal"
Vec = CvM(Z, null_distr)
CvM_teststat = Vec[1]
Watson_teststat = Vec[2]

CvM_teststat;Watson_teststat



Information of distribution

Description

Obtain all details regarding the null distribution such as c1(x).

Usage

Distr_Information(x, strDistr)

Arguments

x

a real number

strDistr

a null distribution: "Normal", "Logistic", "Cauchy"

Value

a list of the following values:

fl

f(x)

Fl

F(x)

re

r(x). Logistic only

Re

R(x). Logistic only

phix

\phi(x)

v0

v_{0}

v1

v_{1}(x)

v2

v_{2}(x)

c0

c_{0}(x)

c1

c_{1}(x)

c2

c_{2}(x)

Gamma

\Gamma(x)

s1

s_{1}(x)

s2

s_{2}(x)

s3

s_{3}(x)

S1

S_{1}(x)

S2

S_{2}(x)

S3

S_{3}(x)

Examples

data(Normal_table)
x = 1.2
lst= Distr_Information(x, "Normal")
phix = lst$phix 
phix
c0 = lst$c0    
c0

Implementing visual inspection of the KMT test statistic

Description

Draw the graph of |U[n](z)|.

Usage

DrawUnz(
  X,
  strDistr,
  type = "l",
  lty = 1,
  lwd = 1.5,
  col = "red",
  xlim = c(NA, NA),
  ylim = c(NA, NA),
  margin_x = 0.1,
  margin_y = 0.5,
  dGap = 0.01,
  b_abline = FALSE
)

Arguments

X

a random sample of n observations

strDistr

a null distribution for the hypothesis test: Normal, Cauchy, Logistic, or Gumbel.

type

a type of plot. A default is a line.

lty

a line type. The default value is a solid.

lwd

a line width.

col

a line color.

xlim

a limit for the x-axis.

ylim

a limit for the y-axis.

margin_x

a margin of graph in the x-axis.

margin_y

a margin of graph in the y-axis.

dGap

a length of subintervals of the x-axis.

b_abline

a logical value for drawing vertical lines where the discontinuities of the graph happen.

Value

A list of the following values:

gObj

plot of the graph of the supremand of the KMT test statistic, that is, |U[n](z)|

References

[1] Khmaladze, E.V., Koul, H.L. (2004). Martingale transforms goodness-of-fit tests in regression models. Ann. Statist., 32. 995-1034

[2] E.V. Khmaladze, H.L. Koul (2009). Goodness-of-fit problem for errors in nonparametric regression: distribution free approach. Ann. Statist., 37(6A) 3165-3185.

[3] Kim, Jiwoong (2020). Implementation of a goodness-of-fit test through Khmaladze martingale transformation. Comp. Stat., 35(4): 1993-2017

Examples

####################
n=20
mu0=2
sigma0=1
X = rnorm(n, mu0, sigma0)
strDistr="Normal"
DrawUnz(X, strDistr, type="l", lty=1, lwd=1.5, col="red",
                   xlim = c(-5,5), ylim = c(NA,NA),
                   margin_x=0.1, margin_y=0.5, dGap=0.01, b_abline=TRUE)


Run other GOF tests

Description

Run the Kolmogorov-Smirnov (KS) and Kuiper tests.

Usage

KS(Z, Distr)

Arguments

Z

a normalized random sample of n observations.

Distr

a null distribution of the GOF test. It should be one of "Normal", "Logistic", "Cauchy", or "Gumbel

Value

A vector of the KS and Kuiper test statistics.

Examples


n=10
mu=2
sigma=1

X = rnorm(n, mu, sigma)

muhat = mean(X)
sighat = sd(X)

Z = (X-muhat)/sighat 
null_distr="Normal"
Vec = KS(Z, null_distr)
KS_teststat = Vec[1]
Kuiper_teststat = Vec[2]

KS_teststat;Kuiper_teststat



Implementing Khmaladze Martingale Transformation.

Description

Performs goodness-of-fit test through Khmaladze matringale transformation

Usage

Run_KMT(
  X,
  strDistr = "Normal",
  bEstimation = FALSE,
  bFast_Estimation = FALSE,
  bParallel = FALSE,
  nThreads = 16
)

Arguments

X

a random sample of n observations

strDistr

a null distribution for the hypothesis test: Normal, Cauchy, Logistic, or Gumbel.

bEstimation

a logical value which specifies whether or not to estimate parameters. The default value is TRUE. For FALSE, (\mu) and (\sigma) will be set as 0 and 1, respectively.

bFast_Estimation

a logical value which specifies whether or not to use the maximum likelihood estimator (\hat{\theta}) for the location and scale parameters The default value is FALSE.

bParallel

a logical value which specifies whether or not to use the parallel computing. The default value is FALSE.

nThreads

the number of threads when bParallel is TRUE. The default value is 16.

Value

A list of the following values:

opt_x

opt.x is the value of x where the optimum of the objective function - which is also the test statistic - occurs.

test_stat

test.stat is the test statistic obtained through Khmaladze martingale transformation.

mu

the point estimate for the location parameter mu

sigma

the point estimate for the scale parameter sigma

References

[1] Khmaladze, E.V., Koul, H.L. (2004). Martingale transforms goodness-of-fit tests in regression models. Ann. Statist., 32. 995-1034

[2] E.V. Khmaladze, H.L. Koul (2009). Goodness-of-fit problem for errors in nonparametric regression: distribution free approach. Ann. Statist., 37(6A) 3165-3185.

[3] Kim, Jiwoong (2020). Implementation of a goodness-of-fit test through Khmaladze martingale transformation. Comp. Stat., 35(4): 1993-2017

Examples

####################
n=20
mu0=2; sigma0=1
X = rnorm(n, mu0, sigma0)


Run_KMT(X, strDistr="Normal")