Fast.independence.test: Atoms based distribution-free test of independence

Description Usage Arguments Details Value Author(s) References Examples

View source: R/HHG_univariate.R

Description

Performs the atoms based distribution-free test for independence of two univariate random variables, which is computationally efficient for large data sets (recommended for sample size greater than 100).

Usage

1
2
3
4
Fast.independence.test(X,Y,NullTable=NULL,mmin=2,
mmax=min(10,length(X)), variant='ADP-EQP-ML',nr.atoms = min(40,length(X)),
combining.type='MinP',score.type='LikelihoodRatio',nr.perm=200,
compress=T, compress.p0=0.001, compress.p=0.99, compress.p1=0.000001)

Arguments

X

a numeric vector with observed X values.

Y

a numeric vector with observed Y values.

NullTable

The null table of the statistic, which can be downloaded from the software website or computed by the function Fast.independence.test.nulltable.

mmin

The minimum partition size of the ranked observations, default value is 2. Ignored if NullTable is non-null.

mmax

The maximum partition size of the ranked observations, default value is the minimum between 10 and the data size.

variant

a character string specifying the partition type, must be one of "ADP-EQP" or "ADP-EQP-ML" (default). Ignored if NullTable is non-null.

nr.atoms

the number of atoms (i.e., possible split points in the data). Ignored if NullTable is non-null. The default value is the minimum between n and 40.

combining.type

a character string specifying the combining type, must be one of "MinP" (default), "Fisher", or "both".

score.type

a character string specifying the score type, must be one of "LikelihoodRatio" (default), "Pearson", or "both". Ignored if NullTable is non-null.

nr.perm

The number of permutations for the null distribution. Ignored if NullTable is non-null.

compress

a logical variable indicating whether you want to compress the null tables. If TRUE, null tables are compressed: The lower compress.p part of the null statistics is kept at a compress.p0 resolution, while the upper part is kept at a compress.p1 resolution (which is finer).

compress.p0

Parameter for compression. This is the resolution for the lower compress.p part of the null distribution.

compress.p

Parameter for compression. Part of the null distribution to compress.

compress.p1

Parameter for compression. This is the resolution for the upper value of the null distribution.

Details

This function is a smart wrapper for the hhg.univariate.ind.combined.test function, with parameters optimized for a large number of observations. The function first calls hhg.univariate.ind.stat to compute the vector of test statistics. Test statistics are the sum of log-likelihood scores, for All Derived Partitions (ADP) of the data (computed as explained in Heller et al. (2014)).

For the 'ADP-EQP-ML' variant, the base test statistics are:

S_{2X2}, S_{2X3} ,S_{3X2}, ... ,S_{mmax X mmax}.

For the 'ADP-EQP' varint, only the sum of symmetric tables (same number of cell on both axis) is considered:

S_{2X2}, S_{3X3} ,S_{4X4}, ... ,S_{mmax X mmax}

Other variant are described in hhg.univariate.ind.combined.test. The above varaiants are the ones to be used for a large number of observations (n>100).

Test functions are capable of handling large datasets by attempting a split only every N/nr.atoms observations. An atom is a sequence of observations which cannot be split when performing a partition of the data (i.e. setting nr.atoms, the number of sequences which cannot be split, sets the number of equidistant partition points). For the above variants, 'EQP' stands for equipartition over atoms. Brill (2016) suggests a minimum of 40 atoms, with an increase of up to 60 for alternatives which are more difficult to detect (on the expense of computational complexity. Algorithm complexity is O(nr.atoms^4)). Very few alternatives require over 80 atoms.

The vector of S_{mXl} statistics is then combined according to the method suggested in Heller et al. (2014). The default combining type in the minimum p-value, so the test statistic is the minimum p-value over the range of partition sizes m from mmin to mmax, where the p-value for a fixed partition size m is defined by the aggregation type and score type. The combination is done over the statistics computed by hhg.univariate.ind.stat. The second type of combination method for statistics, is via a Fisher type statistic, -Σ log(p_m) (with the sum going from mmin to mmax). The returned result may include the test statistic for the MinP combination, the Fisher combination, or both (see comb.type).

If the argument NullTable is supplied with a proper null table (constructed using

Fast.independence.test.nulltable or hhg.univariate.ind.nulltable, for the data sample size), test parameters are taken from NullTable ( mmax, mmin, variant, score.type, nr.atoms ,...). If NullTable is left NULL, a null table is generated by a call to Fast.independence.test.nulltable using the arguments supplied to this function. Null table is generated with nr.perm repetitions. It is stored in the returned object, under generated_null_table. When testing for multiple hypotheses, one may generate only one null table (using this function or Fast.independence.test.nulltable), and use it many times (thus, substantially reducing computation time). Generated null tables hold the distribution of statistics for both combination types, (comb.type=='MinP' and comb.type=='Fisher').

Null tables may be compressed, using the compress argument. For each of the partition sizes (i.e. m or mXm), the null distribution is held at a compress.p0 resolution up to the compress.p percentile. Beyond that value, the distribution is held at a finer resolution defined by compress.p1 (since higher values are attained when a relation exists in the data, this is required for computing the p-value accurately.)

Value

Returns a UnivariateStatistic class object, with the following entries:

MinP

The test statistic when the combining type is "MinP".

MinP.pvalue

The p-value when the combining type is "MinP".

MinP.m.chosen

The partition size m for which the p-value was the smallest.

Fisher

The test statistic when the combining type is "Fisher".

Fisher.pvalue

The p-value when the combining type is "Fisher".

m.stats

The statistic for each m in the range mmin to mmax.

pvalues.of.single.m

The p-values for each m in the range mmin to mmax.

generated_null_table

The null table object. Null if NullTable is non-null.

stat.type

"Independence-Combined"

variant

a character string specifying the partition type used in the test, one of "ADP" or "DDP".

aggregation.type

"sum" or the aggregation type used by NullTable

score.type

a character string specifying the score typeused in the test, one of "LikelihoodRatio" or "Pearson".

mmax

The maximum partition size of the ranked observations used for MinP or Fisher test statistic.

mmin

The minimum partition size of the ranked observations used for MinP or Fisher test statistic.

w.sum

The minimum number of observations in a partition, only relevant for type="Independence", aggregation.type="Sum" and score.type="Pearson".

w.max

The minimum number of observations in a partition, only relevant for type="Independence", aggregation.type="Max" and score.type="Pearson".

nr.atoms

The input nr.atoms.

Author(s)

Barak Brill

References

Heller, R., Heller, Y., Kaufman S., Brill B, & Gorfine, M. (2016). Consistent Distribution-Free K-Sample and Independence Tests for Univariate Random Variables, JMLR 17(29):1-54 https://www.jmlr.org/papers/volume17/14-441/14-441.pdf

Brill B., Heller Y., and Heller R. (2018) Nonparametric Independence Tests and k-sample Tests for Large Sample Sizes Using Package HHG, R Journal 10.1 https://journal.r-project.org/archive/2018/RJ-2018-008/RJ-2018-008.pdf

Brill B. (2016) Scalable Non-Parametric Tests of Independence (master's thesis) http://primage.tau.ac.il/libraries/theses/exeng/free/2899741.pdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## Not run: 

N_Large = 1000
data_Large = hhg.example.datagen(N_Large, 'W')
X_Large = data_Large[1,]
Y_Large = data_Large[2,]
plot(X_Large,Y_Large)

NullTable_for_N_Large_MXL_tables = Fast.independence.test.nulltable(N_Large,
variant = 'ADP-EQP-ML', nr.atoms = 30,nr.perm=200)

ADP_EQP_ML_Result = Fast.independence.test(X_Large,Y_Large,
NullTable_for_N_Large_MXL_tables)

ADP_EQP_ML_Result

#the null distribution depends only on the sample size, so the same
#null table can be used for testing different hypotheses with the same sample size.
#For example, for another data set with N_Large sample size:
data_Large = hhg.example.datagen(N_Large, 'Circle')
X_Large = data_Large[1,]
Y_Large = data_Large[2,]
plot(X_Large,Y_Large)

#The MinP combining method p-values may be reported:
ADP_EQP_ML_Result = Fast.independence.test(X_Large,Y_Large,
NullTable_for_N_Large_MXL_tables,
  combining.type='MinP')
ADP_EQP_ML_Result

#or both MinP and Fisher combining methods p-values:
ADP_EQP_ML_Result = Fast.independence.test(X_Large,Y_Large,
NullTable_for_N_Large_MXL_tables,
  combining.type='Both')
ADP_EQP_ML_Result



## End(Not run)

HHG documentation built on May 15, 2021, 9:06 a.m.