Example #1
0
def test_ar_modeling():
    # Compare against standard routines
    rng = np.random.RandomState(20110903)
    N = 10
    Y = rng.normal(size=(N,1)) * 10 + 100
    X = np.c_[np.linspace(-1,1,N), np.ones((N,))]
    my_model = OLSModel(X)
    results = my_model.fit(Y)
    # fmristat wrapper
    rhos = estimateAR(results.resid, my_model.design, order=2)
    assert_equal(rhos.shape, (2,))
    assert_true(np.all(np.abs(rhos <= 1)))
    # standard routine
    rhos2 = ar_bias_correct(results, 2)
    assert_array_almost_equal(rhos, rhos2, 8)
    # Make 2D and 3D Y
    Y = rng.normal(size=(N,4)) * 10 + 100
    results = my_model.fit(Y)
    rhos = estimateAR(results.resid, my_model.design, order=2)
    assert_equal(rhos.shape, (2,4))
    assert_true(np.all(np.abs(rhos <= 1)))
    rhos2 = ar_bias_correct(results, 2)
    assert_array_almost_equal(rhos, rhos2, 8)
    # 3D
    results.resid = np.reshape(results.resid, (N,2,2))
    rhos = estimateAR(results.resid, my_model.design, order=2)
    assert_equal(rhos.shape, (2,2,2))
    assert_true(np.all(np.abs(rhos <= 1)))
    rhos2 = ar_bias_correct(results, 2)
    assert_array_almost_equal(rhos, rhos2, 8)
Example #2
0
def test_ar_modeling():
    # Compare against standard routines
    rng = np.random.RandomState(20110903)
    N = 10
    Y = rng.normal(size=(N, 1)) * 10 + 100
    X = np.c_[np.linspace(-1, 1, N), np.ones((N, ))]
    my_model = OLSModel(X)
    results = my_model.fit(Y)
    # fmristat wrapper
    rhos = estimateAR(results.resid, my_model.design, order=2)
    assert_equal(rhos.shape, (2, ))
    assert_true(np.all(np.abs(rhos <= 1)))
    # standard routine
    rhos2 = ar_bias_correct(results, 2)
    assert_array_almost_equal(rhos, rhos2, 8)
    # Make 2D and 3D Y
    Y = rng.normal(size=(N, 4)) * 10 + 100
    results = my_model.fit(Y)
    rhos = estimateAR(results.resid, my_model.design, order=2)
    assert_equal(rhos.shape, (2, 4))
    assert_true(np.all(np.abs(rhos <= 1)))
    rhos2 = ar_bias_correct(results, 2)
    assert_array_almost_equal(rhos, rhos2, 8)
    # 3D
    results.resid = np.reshape(results.resid, (N, 2, 2))
    rhos = estimateAR(results.resid, my_model.design, order=2)
    assert_equal(rhos.shape, (2, 2, 2))
    assert_true(np.all(np.abs(rhos <= 1)))
    rhos2 = ar_bias_correct(results, 2)
    assert_array_almost_equal(rhos, rhos2, 8)
Example #3
0
File: model.py Project: Hiccup/nipy
def estimateAR(resid, design, order=1):
    """
    Estimate AR parameters using bias correction from fMRIstat.

    Parameters
    ----------
    resid:  array-like
        residuals from model
    model:  an OLS model used to estimate residuals

    Returns
    -------
    output : array
        shape (order, resid
    """
    invM = ar_bias_corrector(design, spl.pinv(design), order)
    return ar_bias_correct(resid, order, invM)
Example #4
0
def estimateAR(resid, design, order=1):
    """
    Estimate AR parameters using bias correction from fMRIstat.

    Parameters
    ----------
    resid:  array-like
        residuals from model
    model:  an OLS model used to estimate residuals

    Returns
    -------
    output : array
        shape (order, resid
    """
    invM = ar_bias_corrector(design, spl.pinv(design), order)
    return ar_bias_correct(resid, order, invM)