pvalue: Compute the pvalue of generalized Kolmogorov-Smirnov test...

GKSPvalueR Documentation

Compute the pvalue of generalized Kolmogorov-Smirnov test statistics

Description

Compute the pvalue of generalized Kolmogorov-Smirnov test statistics, see details on how to use the function.

Usage

GKSPvalue(
  stat = NULL,
  n = NULL,
  index = NULL,
  indexL = NULL,
  indexU = NULL,
  x = NULL,
  statName = NULL
)

Arguments

stat

a generalKSStat object or numeric, the statistic that the p-value is computed for. If stat is a generalKSStat object, all other parameters will be ignored. Otherwise, this parameter will be suppressed if the parameter x is not null. If a numeric value is provided to the parameter stat, you must at least specify the sample size n.

n

Integer, the sample size of the data.

index

Integer, controlling which ordered samples will be used in the statistics, see details.

indexL

Integer, controlling which ordered samples will be used in the statistics, see details.

indexU

Integer, controlling which ordered samples will be used in the statistics, see details.

x

Numeric, the sample data.

statName

Character, the name of the statistic that will be computed. The default is "KS".

Details

statistics definitions

The function compute the test statistics which aggregate the significant signal from the order statistics of the samples, that is, if T is a statistic and X_1,X_2,...,X_n are the samples, the value of T is purely based on the value of X_(1),X_(2),...,X_(n), where X_(i) is the ith ascending sorted samples of X1,X2,...,Xn. Moreover, the rejection region of the statistic T can be written as a set of rejection regions of the ordered samples X_(1),X_(2),...,X_(n). In other words, there exist two sequences {l_i} and {u_i} for i=1,...,n and the statistic T is rejected if and only if there exist one i such that X_(i) < l_i or X_(i) > u_i.

The most well-known statistic which takes this form is the Kolmogorov-Smirnov statistic. Other statistics like Berk-Jones or the higher criticism also have similar formulas but define different sets of {l_i} and {u_i}.

alpha0, index, indexL and indexU

As mentioned previouly, the rejection of a test can be determined by the sequences of {l_i} and {u_i}. Therefore, the parameter alpha0, index indexL and indexU. provide a way to control which l_i and u_i will be considered in the test procedure. If no argument is provided, all l_is and u_is will be compared with their corresponding sorted sample X_(i). This yields the traditional test statistics. If alpha0 is used, only the data X_(1),...X_(k) will be used in the test where k is the nearest integer of alpha0*n. If index is provided, only X_(i) for i in index will be considered in the test. If indexL and/or indexU is not NULL, only l_i for i in indexL and u_i for i in indexU will be used as the rejection boundary for the test. These can be used to generate an one-sided version of the test statistic. For example, if indexL is from 1 to the length of x and indexU is NULL, this will yield a test specifically sensitive to smaller samples. The test statistics like KS+, HC+ and BJ+ are implemented by calling GKSStat(..., indexU = NULL), where indexU is always NULL.

Value

A numeric value representing the pvalue

Examples

## Generate samples
x <- rbeta(10, 1, 2)


## Perform KS test
ks_res <- GKSStat(x = x, statName = "KS")

## Compute the pvalue for the KS test
GKSPvalue(stat = ks_res)

## For any observed statistic
GKSPvalue(stat = 0.2, n = 10, statName = "KS")

## Change the detection range of the KS test
## to test only the first 3 ordered samples
## All gives the same result
GKSPvalue(stat = 0.2, n = 10, alpha0 = 0.3, statName = "KS")
GKSPvalue(stat = 0.2, n = 10, index = 1:3, statName = "KS")
GKSPvalue(stat = 0.2, n = 10, indexL = 1:3, indexU = 1:3, statName = "KS")




Jiefei-Wang/exceedance documentation built on May 11, 2022, 1:43 a.m.