def f_regression_cov(X, y, C):
    'Univariate linear regression tests\n\n    Quick linear model for testing the effect of a single regressor,\n    sequentially for many regressors.\n\n    This is done in 3 steps:\n    1. the regressor of interest and the data are orthogonalized\n    wrt constant regressors\n    2. the cross correlation between data and regressors is computed\n    3. it is converted to an F score then to a p-value\n\n    Parameters\n    ----------\n    X : {array-like, sparse matrix}  shape = (n_samples, n_features)\n        The set of regressors that will tested sequentially.\n\n    y : array of shape(n_samples).\n        The data matrix\n\n    c : {array-like, sparse matrix}  shape = (n_samples, n_covariates)\n        The set of covariates.\n\n\n    Returns\n    -------\n    F : array, shape=(n_features,)\n        F values of features.\n\n    pval : array, shape=(n_features,)\n        p-values of F-scores.\n    '
    X = check_array(X, dtype=np.float)
    C = check_array(C, dtype=np.float)
    y = check_array(y, dtype=np.float)
    y = y.ravel()
    assert (C.shape[1] < C.shape[0])
    cpinv = np.linalg.pinv(C)
    X -= np.dot(C, np.dot(cpinv, X))
    y -= np.dot(C, np.dot(cpinv, y))
    corr = np.dot(y, X)
    corr /= np.asarray(np.sqrt(safe_sqr(X).sum(axis=0))).ravel()
    corr /= np.asarray(np.sqrt(safe_sqr(y).sum())).ravel()
    dof = (((X.shape[0] - 1) - C.shape[1]) / 1)
    F = (((corr ** 2) / (1 - (corr ** 2))) * dof)
    pv = stats.f.sf(F, 1, dof)
    return (F, pv)
Univariate linear regression tests

Quick linear model for testing the effect of a single regressor,
sequentially for many regressors.

This is done in 3 steps:
1. the regressor of interest and the data are orthogonalized
wrt constant regressors
2. the cross correlation between data and regressors is computed
3. it is converted to an F score then to a p-value

Parameters
----------
X : {array-like, sparse matrix}  shape = (n_samples, n_features)
    The set of regressors that will tested sequentially.

y : array of shape(n_samples).
    The data matrix

c : {array-like, sparse matrix}  shape = (n_samples, n_covariates)
    The set of covariates.


Returns
-------
F : array, shape=(n_features,)
    F values of features.

pval : array, shape=(n_features,)
    p-values of F-scores.
def f_regression_cov(X, y, C):
    'Univariate linear regression tests\n\n    Quick linear model for testing the effect of a single regressor,\n    sequentially for many regressors.\n\n    This is done in 3 steps:\n    1. the regressor of interest and the data are orthogonalized\n    wrt constant regressors\n    2. the cross correlation between data and regressors is computed\n    3. it is converted to an F score then to a p-value\n\n    Parameters\n    ----------\n    X : {array-like, sparse matrix}  shape = (n_samples, n_features)\n        The set of regressors that will tested sequentially.\n\n    y : array of shape(n_samples).\n        The data matrix\n\n    c : {array-like, sparse matrix}  shape = (n_samples, n_covariates)\n        The set of covariates.\n\n\n    Returns\n    -------\n    F : array, shape=(n_features,)\n        F values of features.\n\n    pval : array, shape=(n_features,)\n        p-values of F-scores.\n    '
    X = check_array(X, dtype=np.float)
    C = check_array(C, dtype=np.float)
    y = check_array(y, dtype=np.float)
    y = y.ravel()
    assert (C.shape[1] < C.shape[0])
    cpinv = np.linalg.pinv(C)
    X -= np.dot(C, np.dot(cpinv, X))
    y -= np.dot(C, np.dot(cpinv, y))
    corr = np.dot(y, X)
    corr /= np.asarray(np.sqrt(safe_sqr(X).sum(axis=0))).ravel()
    corr /= np.asarray(np.sqrt(safe_sqr(y).sum())).ravel()
    dof = (((X.shape[0] - 1) - C.shape[1]) / 1)
    F = (((corr ** 2) / (1 - (corr ** 2))) * dof)
    pv = stats.f.sf(F, 1, dof)
    return (F, pv)