MultiFIT: Multiscale Fisher’s Independence Test for Multivariate Dependence

S. Gorsky and L. Ma

The MultiFit package includes several functions, of which the most important are:
  1. MultiFit: the function that runs the test of independence of two random vectors, the algorithm comprising of multiscale \(2\times2\) univariate tests of discretized margins and multiple testing adjustments. At each resolution, recursively, tests whose p-values are below a pre-set threshold are chosen and smaller portions of the sample space that correspond to those are explored in higher resolutions. The function returns a list object that contains details of the performed tests, p-values corrected according to the selected multiple testing procedure for all tests, and global p-values for the null hypothesis that the two random vectors are independent.
  2. multiSummary: a function that returns and plots the most significant \(2\times2\) univariate tests of discretized margins.
  3. multiTree: a function that generates a directed acyclic graph where nodes are \(2\times2\) univariate tests of discretized margins. An edge from one test to another indicates the the latter test is performed on half the portion of the sample space on which the former was perofrmed.

Examples

First Example:

Run the Test:

##            H   Hcorrected           MH 
## 2.800233e-05 1.937348e-05 1.267042e-05

In order to get a better sense of the workings of the function, choose verbose=TRUE:

## Applying rank transformation
## Testing and computing mid-p corrected p-values:
## Resolution 0/4: performing 4 tests
## Resolution 1/4: scanning 16 cuboids, performing 32 tests
## Resolution 2/4: scanning 4 cuboids, performing 16 tests
## Resolution 3/4: scanning 16 cuboids, performing 56 tests
## Resolution 4/4: scanning 12 cuboids, performing 48 tests
## No potential parents in resolution 4 have p-values below threshold.
## Time difference of 0.02850723 secs
## Individual tests completed, post-processing...
## H: Computing all adjusted p-values...
## Hcorrected: Computing all adjusted p-values...
## MH: Computing CDF...
## MH: Computing all adjusted p-values...
## Time difference of 0.0009000301 secs
## 
## Fisher's Exact Tests:
## Mean of -log(p-values): 1.62688
## Mean of top 4 -log(p-values): 9.83994
## Mean of -log(p-values with mid-p correction): 1.82527
## Mean of top 4 -log(p-values with mid-p correction): 10.2949
## 
## Global p-value, Holm on p-values: 2.80023e-05
## Global p-value, Holm on p-values with mid-p correction: 1.93735e-05
## Global p-value, Modified Holm step-down: 1.26704e-05
The output details the number of tests performed at each resolution. The default testing method for the marginal \(2\times2\) contingency tables is Fisher’s exact test. Several global test statistics are reported:
  • Mean of \(-log(\text{p-values})\)
  • Mean of top 4 \(-log(\text{p-values})\)
  • Mean of \(-log(\text{p-values with mid-p correction})\)
  • Mean of top 4 \(-log(\text{p-values with mid-p correction})\)).

These are not associated with p-values until we genrate a permutation null distribution for them using permNullTest. The default multiple testing adjustments methods we use are Holm’s method on the original p-values (H), Holm’s method on the mid-p corrected p-values (Hcorrected) and a Modified Holm (MH)1. The p-value for the global null hypothesis that \(\mathbf{x}\) is independent of \(\mathbf{y}\) is reported for each adjustment method.

Summarize Results (1):

In order to get a sense of the specific marginal tests that are significant at the alpha=0.005 level, we may use the function multiSummary:

## 
## The following tests had a p-value of less than 0.05:
## Ranked #1, Test 32: x2 and y2 | 0<=x2<0.46 (p-value=1.267042e-05)
## Ranked #2, Test 44: x2 and y2 | 0.22<=x2<0.46 (p-value=0.005794476)
## Ranked #3, Test 48: x2 and y2 | 0<=x2<0.46, -2.39<=y2<0.22 (p-value=0.01074775)

In grey and orange are all data points outside the cuboid we are testing. In orange are the points that were in the cuboid if we were not to condition on the margins that are visible in the plot. In red are the points that are inside the cuboid after we condition on all the margins, including those that are visible in a plot. The blue lines delineate the quadrants along which the discretization was performed: we count the number of red points in each quadrant, treat these four numbers as a \(2\times2\) contingency table and perform a 1-degree of freedom test of independence on it (default test: Fisher’s exact test).

Summarize Results (2):

We may also draw a directed acyclic graph where nodes represent tests as demonstrated above in the multiSummary output. An edge from one test to another indicates that the latter test is performed on half the portion of the sample space on which the former was performed. Larger nodes correspond to more extreme p-values for the test depicted in it (storing the output as a pdf file):

## Registered S3 methods overwritten by 'huge':
##   method    from   
##   plot.sim  BDgraph
##   print.sim BDgraph
## Output stored in /tmp/RtmpqAoTDq/Rbuild24f06b3e9379/MultiFit/vignettes/first_example.pdf

We see that, in agreement with the output of the multiSummary function, nodes 32, 44 and 48 (which correspond to tests 32, 44 and 48) are the largest compared to the other nodes.

Test More Cuboids:

In the default setting, p_star, the fixed threshold for \(p\)-values of tests that will be further explored in higher resolutions, is set to \((D_x\cdot D_y\cdot \log_2(n))^{-1}\). We may choose, e.g., p_star=0.1, which takes longer. In this case the MultiFit identifies more tables with adjusted p-values that are below alpha=0.005. However, the global adjusted p-values are less extreme than when performing the MultiFit with fewer tests:

## Applying rank transformation
## Testing and computing mid-p corrected p-values:
## Resolution 0/4: performing 4 tests
## Resolution 1/4: scanning 16 cuboids, performing 32 tests
## Resolution 2/4: scanning 20 cuboids, performing 76 tests
## Resolution 3/4: scanning 68 cuboids, performing 196 tests
## Resolution 4/4: scanning 88 cuboids, performing 284 tests
## No potential parents in resolution 4 have p-values below threshold.
## Time difference of 0.04033327 secs
## Individual tests completed, post-processing...
## H: Computing all adjusted p-values...
## Hcorrected: Computing all adjusted p-values...
## MH: Computing CDF...
## MH: Computing all adjusted p-values...
## Time difference of 0.001901627 secs
## 
## Fisher's Exact Tests:
## Mean of -log(p-values): 1.31104
## Mean of top 4 -log(p-values): 16.4356
## Mean of -log(p-values with mid-p correction): 1.52395
## Mean of top 4 -log(p-values with mid-p correction): 16.9313
## 
## Global p-value, Holm on p-values: 9.60421e-13
## Global p-value, Holm on p-values with mid-p correction: 4.81733e-13
## Global p-value, Modified Holm step-down: 1.3204e-13
## 
## The following tests had a p-value of less than 0.005:
## Ranked #1, Test 100: x2 and y2 | 0.46<=x2<0.74 (p-value=1.320403e-13)
## Ranked #2, Test 32: x2 and y2 | 0<=x2<0.46 (p-value=2.925387e-05)

In order to perform the test even more exhaustively, one may:

A Local Signal:

MultiFit excels in locating very localized signals.

Search for It and Summarize the Results:

Truly local signals may not be visible to our algorithm in resolutions that are lower than the one that the signal is embedded in. In order to cover all possible tests up to a given resolution (here: resolution 4), we use the parameter R_star=4 (from resolution 5 onwards, only tables with \(p\)_values below p_star will be further tested):

## Applying rank transformation
## Testing and computing mid-p corrected p-values:
## Resolution 0/6: performing 4 tests
## Resolution 1/6: scanning 16 cuboids, performing 32 tests
## Resolution 2/6: scanning 128 cuboids, performing 160 tests
## Resolution 3/6: scanning 640 cuboids, performing 640 tests
## Resolution 4/6: scanning 2560 cuboids, performing 2240 tests
## Resolution 5/6: scanning 140 cuboids, performing 524 tests
## Resolution 6/6: scanning 16 cuboids, performing 64 tests
## No pairs of margins in resolution 6 had enough observations to be tested.
## Time difference of 0.1804612 secs
## Individual tests completed, post-processing...
## H: Computing all adjusted p-values...
## Hcorrected: Computing all adjusted p-values...
## MH: Computing CDF...
## MH: Computing all adjusted p-values...
## Time difference of 0.02168202 secs
## 
## Fisher's Exact Tests:
## Mean of -log(p-values): 0.815441
## Mean of top 4 -log(p-values): 9.83624
## Mean of -log(p-values with mid-p correction): 0.999486
## Mean of top 4 -log(p-values with mid-p correction): 10.2239
## 
## Global p-value, Holm on p-values: 1.61645e-05
## Global p-value, Holm on p-values with mid-p correction: 8.11708e-06
## Global p-value, Modified Holm step-down: 5.61068e-06
## 
## The following tests had a p-value of less than 0.05:
## Ranked #1, Test 2928: x2 and y2 | -0.06<=x2<0.7, -0.06<=y2<0.62 (p-value=5.610678e-06)

A Signal that is Spread Between More than 2 Margins:

MultiFit also has the potential to identify complex conditional dependencies in multivariate signals.

Generate Data and Examine Margins:

Take \(\mathbf{x}\) and \(\mathbf{y}\) to be each of three dimensions, with 700 data points. We first generate a marginal circle dependency: \(x_1\), \(y_1\), \(x_2\), and \(y_2\) are all i.i.d standard normals. Take \(x_3=\cos(\theta)+\epsilon\), \(y_3=\sin(\theta)+\epsilon'\) where \(\epsilon\) and \(\epsilon'\) are i.i.d \(\mathrm{N}(0,(1/10)^2)\) and \(\theta\sim \mathrm{Uniform}(-\pi,\pi)\). I.e., the original dependency is between \(x_3\) and \(y_3\).

Next, rotate the circle in \(\pi/4\) degrees in the \(x_2\)-\(x_3\)-\(y_3\) space by applying:

\(\left[\begin{matrix}\cos(\pi/4) & -sin(\pi/4) & 0\\\sin(\pi/4) & cos(\pi/4) & 0\\ 0 & 0 & 1\end{matrix}\right]\left[\begin{matrix}| & | & |\\X_2 & X_3 & Y_3\\| & | & |\end{matrix}\right]\)

I.e., once rotated the signal is ‘spread’ between \(x_2\), \(x_3\) and \(y_3\), and harder to see through the marginal plots.

Run the Test and Summarize the Data:

Choose R_star to be 2 to cover exhaustively all resolutions up to 2, and rnd=FALSE to consider all tests whose \(p\)-value is below p_star.

## Applying rank transformation
## Testing and computing mid-p corrected p-values:
## Resolution 0/6: performing 9 tests
## Resolution 1/6: scanning 36 cuboids, performing 108 tests
## Resolution 2/6: scanning 432 cuboids, performing 756 tests
## Resolution 3/6: scanning 76 cuboids, performing 549 tests
## Resolution 4/6: scanning 56 cuboids, performing 450 tests
## Resolution 5/6: scanning 48 cuboids, performing 387 tests
## Resolution 6/6: scanning 8 cuboids, performing 72 tests
## No pairs of margins in resolution 6 had enough observations to be tested.
## Time difference of 0.1101279 secs
## Individual tests completed, post-processing...
## H: Computing all adjusted p-values...
## Hcorrected: Computing all adjusted p-values...
## MH: Computing CDF...
## MH: Computing all adjusted p-values...
## Time difference of 0.02711082 secs
## 
## Fisher's Exact Tests:
## Mean of -log(p-values): 1.00888
## Mean of top 4 -log(p-values): 19.4372
## Mean of -log(p-values with mid-p correction): 1.1468
## Mean of top 4 -log(p-values with mid-p correction): 19.9051
## 
## Global p-value, Holm on p-values: 2.76779e-07
## Global p-value, Holm on p-values with mid-p correction: 1.98468e-07
## Global p-value, Modified Holm step-down: 1.28572e-07
## 
## The following tests had a p-value of less than 0.001:
## Ranked #1, Test 684: x3 and y3 | -2.7<=x2<-0.07, -1.23<=y3<-0.11 (p-value=1.285722e-07)
## Ranked #2, Test 1746: x3 and y3 | -0.65<=x2<-0.07, -2.91<=x3<0.01, -0.11<=y3<1.23 (p-value=8.617062e-07)
## Ranked #3, Test 1206: x3 and y3 | 0.6<=x2<2.76, -1.23<=y3<-0.11 (p-value=3.014417e-05)
## Ranked #4, Test 708: x2 and y3 | 0.01<=x3<3.01, -1.23<=y3<-0.11 (p-value=4.012281e-05)
## Ranked #5, Test 738: x3 and y3 | -2.7<=x2<-0.07, -0.11<=y3<1.23 (p-value=6.200025e-05)
## Ranked #6, Test 1779: x2 and y3 | -2.7<=x2<-0.07, -0.59<=x3<0.01, -0.11<=y3<1.23 (p-value=6.512338e-05)
## Ranked #7, Test 1401: x2 and y3 | 0.63<=x3<3.01, -0.11<=y3<1.23 (p-value=0.0001410845)
## Ranked #8, Test 1008: x3 and y3 | -2.7<=x2<-0.07, -3<=y1<0.04, -1.23<=y3<-0.11 (p-value=0.000246823)
## Ranked #9, Test 1239: x2 and y3 | -0.07<=x2<2.76, 0.01<=x3<3.01, -1.23<=y3<-0.11 (p-value=0.0004040133)

Notice how the signal is detected both in the \(x_3\)-\(y_3\) plane and the \(x_2\)-\(y_3\) plane.

A Superimposed Signal:

Here we examine MultiFit’s ability to
  1. detect a signal that is comprised of two sine waves in different frequencies
  2. given a third dimension that determines which data points belong to which wave, to see if our algorithm successfully identifies this relation.

We take \(\mathbf{x}\) to be a two dimensional random variable and \(\mathbf{y}\) to be one dimensional, all with 550 data points. Define \(x_1\sim U(0,1)\), \(x_2\sim Beta(0.3,0.3)\) independent of \(x_1\), and define:

\(Y = \begin{cases} \sin(10\cdot x_1) + \epsilon, & \text{if }x_2 > 0.75\\ \sin(40\cdot x_1) + \epsilon, & \text{if }x_2\leq0.75 \end{cases}\)

Test and Summarize:

## Warning in data.table::setDT(W): Some columns are a multi-column type (such
## as a matrix column): [4, 7, 16]. setDT will retain these columns as-is but
## subsequent operations like grouping and joining may fail. Please consider
## as.data.table() instead which will create a new column for each embedded
## column.
## Warning in data.table::setDT(W): Some columns are a multi-column type (such
## as a matrix column): [4, 7, 13, 16]. setDT will retain these columns as-
## is but subsequent operations like grouping and joining may fail. Please
## consider as.data.table() instead which will create a new column for each
## embedded column.

## Warning in data.table::setDT(W): Some columns are a multi-column type (such
## as a matrix column): [4, 7, 13, 16]. setDT will retain these columns as-
## is but subsequent operations like grouping and joining may fail. Please
## consider as.data.table() instead which will create a new column for each
## embedded column.

## Warning in data.table::setDT(W): Some columns are a multi-column type (such
## as a matrix column): [4, 7, 13, 16]. setDT will retain these columns as-
## is but subsequent operations like grouping and joining may fail. Please
## consider as.data.table() instead which will create a new column for each
## embedded column.

## Warning in data.table::setDT(W): Some columns are a multi-column type (such
## as a matrix column): [4, 7, 13, 16]. setDT will retain these columns as-
## is but subsequent operations like grouping and joining may fail. Please
## consider as.data.table() instead which will create a new column for each
## embedded column.
## 
## The following tests had a p-value of less than 1e-04:
## Ranked #1, Test 3: x1 and y1 | 0<=x1<0.48 (p-value=5.400447e-14)
## Ranked #2, Test 95: x1 and y1 | 0.48<=x1<0.76, 0.51<=x2<1 (p-value=9.52744e-13)
## Ranked #3, Test 23: x1 and y1 | 0.48<=x1<0.76 (p-value=4.474281e-07)
## Ranked #4, Test 85: x1 and y1 | 0.76<=x1<1, 0.51<=x2<1 (p-value=5.850135e-07)
## Ranked #5, Test 25: x1 and y1 | 0.76<=x1<1 (p-value=1.070613e-06)
## Ranked #6, Test 127: x1 and y1 | 0.24<=x1<0.48, 0.51<=x2<1, -1.64<=y1<0.18 (p-value=3.418641e-06)
## Ranked #7, Test 195: x1 and y1 | 0.88<=x1<1, 0<=x2<0.51 (p-value=7.041063e-06)
## Ranked #8, Test 16: x2 and y1 | 0<=x1<0.24 (p-value=8.934898e-06)

Notice how the separate signals are identified in the 2\(^{nd}\), 4\(^{th}\), 6\(^{th}\) and 7\(^{th}\) ranking tests.

A Univariate Example:

In the univariate case, Ma and Mao (2017) show that the p-values for Fisher’s exact test are mutually independent under the null hypothesis of independence. Thus, we may also generate approximate and theoretical null distributions for the global test statistics that are much faster to compute, compared to the permutation null distribution.

Test:

## Applying rank transformation
## Testing and computing mid-p corrected p-values:
## Resolution 0/4: performing 1 tests
## Resolution 1/4: scanning 4 cuboids
## Warning in data.table::setDT(W): Some columns are a multi-column type (such
## as a matrix column): [2, 3, 4, 5, 11, 12]. setDT will retain these columns
## as-is but subsequent operations like grouping and joining may fail. Please
## consider as.data.table() instead which will create a new column for each
## embedded column.
## , performing 4 tests
## Resolution 2/4: scanning 4 cuboids
## Warning in data.table::setDT(W): Some columns are a multi-column type (such
## as a matrix column): [2, 3, 4, 5, 9, 10, 11, 12]. setDT will retain these
## columns as-is but subsequent operations like grouping and joining may fail.
## Please consider as.data.table() instead which will create a new column for
## each embedded column.
## , performing 4 tests
## Resolution 3/4: scanning 4 cuboids
## Warning in data.table::setDT(W): Some columns are a multi-column type (such
## as a matrix column): [2, 3, 4, 5, 9, 10, 11, 12]. setDT will retain these
## columns as-is but subsequent operations like grouping and joining may fail.
## Please consider as.data.table() instead which will create a new column for
## each embedded column.
## , performing 4 tests
## No potential parents in resolution 3 have p-values below threshold.
## Time difference of 0.008395672 secs
## Individual tests completed, post-processing...
## H: Computing all adjusted p-values...
## Hcorrected: Computing all adjusted p-values...
## MH: Computing CDF...
## MH: Computing all adjusted p-values...
## Time difference of 0.0004005432 secs
## Simulating an approximate null distribution...
## Time difference of 0.2118592 secs
## Simulating from the theoretical null distribution...
## Time difference of 0.7392795 secs
## 
## Fisher's Exact Tests:
## Mean of -log(p-values): 1.31783
## Mean of top 4 -log(p-values): 3.04394
## Mean of -log(p-values with mid-p correction): 1.48881
## Mean of top 4 -log(p-values with mid-p correction): 3.26622
## 
## Global p-value, theoretical null, mean -log(p-values with mid-p correction): 0.0224
## Global p-value, theoretical null, mean top 4 -log(p-values with mid-p correction): 0.0139
## 
## Global p-value, approximate null, mean -log(p-values with mid-p correction): 0.0647
## Global p-value, approximate null, mean top 4 -log(p-values with mid-p correction): 0.0286
## 
## Global p-value, Holm on p-values: 0.00659055
## Global p-value, Holm on p-values with mid-p correction: 0.00507617
## Global p-value, Modified Holm step-down: 0.00480701

Important Parameters for MultiFit:


  1. The latter is the most powerful and computationaly intense of the three