algorithms.covtest

Module: algorithms.covtest

This module includes covtest that computes either the exponential approximation from covTest the exact form of the covariance test described in Spacings.

The covariance test itself is asymptotically exponential (under certain conditions) and is described in covTest.

Both tests mentioned above require knowledge (or a good estimate) of sigma, the noise variance.

This module also includes a second exact test called `selected_covtest`_ that can use sigma but does not need it.

Functions

selectinf.algorithms.covtest.covtest(X, Y, sigma=1, exact=True, covariance=None)[source]

The exact and approximate form of the covariance test, described in the covTest, Kac Rice and Spacings papers.

Parameters

X : np.float((n,p))

Y : np.float(n)

sigma : float (optional)

Defaults to 1, but Type I error will be off if incorrect sigma is used.

exact : bool (optional)

If True, use the first spacings test, else use the exponential approximation.

covariance : np.array (optional)

If None, defaults to identity.

Returns

con : `selection.affine.constraints`_

The constraint based on conditioning on the sign and location of the maximizer.

pvalue : float

Exact or approximate covariance test p-value.

idx : int

Variable achieving \(\lambda_1\)

sign : int

Sign of \(X^Ty\) for variable achieving \(\lambda_1\).

selectinf.algorithms.covtest.selected_covtest(X, Y, ndraw=5000, burnin=2000, sigma=None, covariance=None)[source]

An exact test that is more powerful than covtest but that requires sampling for the null distribution.

This test does not require knowledge of sigma.

Parameters

X : np.float((n,p))

Y : np.float(n)

burnin : int

How many iterations until we start recording samples?

ndraw : int

How many samples should we return?

sigma : float (optional)

If provided, this value is used for the Gibbs sampler.

covariance : np.float (optional)

Optional covariance for cone constraint. Will be scaled by sigma if it is not None.

Returns

con : `selection.affine.constraints`_

The constraint based on conditioning on the sign and location of the maximizer.

pvalue : float

Exact p-value.

idx : int

Variable achieving \(\lambda_1\)

sign : int

Sign of \(X^Ty\) for variable achieving \(\lambda_1\).