def f_regression_cov_alt(X, y, C):
    '\n    Implementation as derived in tex document\n\n    See pg 12 of following document for definition of F-statistic\n    http://www-stat.stanford.edu/~jtaylo/courses/stats191/notes/simple_diagnostics.pdf\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    '
    old_flag_X = X.flags.writeable
    old_flag_C = C.flags.writeable
    old_flag_y = y.flags.writeable
    X.flags.writeable = False
    C.flags.writeable = False
    y.flags.writeable = False
    y = y.ravel()
    X = X.copy(order='F')
    y = y.copy()
    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))
    yS = safe_sqr(y.T.dot(X))
    X *= X
    denom = ((X.sum(0) * y.T.dot(y)) - yS)
    F = (yS / denom)
    dof = (((X.shape[0] - 1) - C.shape[1]) / 1)
    F *= dof
    pv = stats.f.sf(F, 1, dof)
    X.flags.writeable = old_flag_X
    C.flags.writeable = old_flag_C
    y.flags.writeable = old_flag_y
    return (F, pv)
Implementation as derived in tex document

See pg 12 of following document for definition of F-statistic
http://www-stat.stanford.edu/~jtaylo/courses/stats191/notes/simple_diagnostics.pdf

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_alt(X, y, C):
    '\n    Implementation as derived in tex document\n\n    See pg 12 of following document for definition of F-statistic\n    http://www-stat.stanford.edu/~jtaylo/courses/stats191/notes/simple_diagnostics.pdf\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    '
    old_flag_X = X.flags.writeable
    old_flag_C = C.flags.writeable
    old_flag_y = y.flags.writeable
    X.flags.writeable = False
    C.flags.writeable = False
    y.flags.writeable = False
    y = y.ravel()
    X = X.copy(order='F')
    y = y.copy()
    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))
    yS = safe_sqr(y.T.dot(X))
    X *= X
    denom = ((X.sum(0) * y.T.dot(y)) - yS)
    F = (yS / denom)
    dof = (((X.shape[0] - 1) - C.shape[1]) / 1)
    F *= dof
    pv = stats.f.sf(F, 1, dof)
    X.flags.writeable = old_flag_X
    C.flags.writeable = old_flag_C
    y.flags.writeable = old_flag_y
    return (F, pv)