code: def test_ar_estimator():
      # More or less a smoke test
      rng = np.random.RandomState(20110903)
      N = 100
      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)
      are = AREstimator(my_model, 2)
      rhos = are(results)
      assert rhos.shape == (2,)
      assert np.all(np.abs(rhos <= 1))
      rhos2 = ar_bias_correct(results, 2)
      assert_array_almost_equal(rhos, rhos2, 8)
      invM = ar_bias_corrector(my_model.design, my_model.calc_beta, 2)
      rhos3 = ar_bias_correct(results, 2, invM)
      assert_array_almost_equal(rhos2, rhos3)
      # Check orders 1 and 3
      rhos = ar_bias_correct(results, 1)
      assert rhos.shape == ()
      assert abs(rhos) <= 1
      rhos = ar_bias_correct(results, 3)
      assert rhos.shape == (3,)
      assert np.all(np.abs(rhos) <= 1)
      # Make a 2D Y and try that
      Y = rng.normal(size=(N, 12)) * 10 + 100
      results = my_model.fit(Y)
      rhos = are(results)
      assert rhos.shape == (2, 12)
      assert np.all(np.abs(rhos <= 1))
      rhos2 = ar_bias_correct(results, 2)
      assert_array_almost_equal(rhos, rhos2, 8)
      rhos3 = ar_bias_correct(results, 2, invM)
      assert_array_almost_equal(rhos2, rhos3)
      # Passing in a simple array
      rhos4 = ar_bias_correct(results.resid, 2, invM)
      assert_array_almost_equal(rhos3, rhos4)
      # Check orders 1 and 3
      rhos = ar_bias_correct(results, 1)
      assert rhos.shape == (12,)
      assert np.all(np.abs(rhos) <= 1)
      rhos = ar_bias_correct(results, 3)
      assert rhos.shape == (3, 12)
      assert np.all(np.abs(rhos) <= 1)
      # Try reshaping to 3D
      results.resid = results.resid.reshape((N, 3, 4))
      rhos = ar_bias_correct(results, 2)
      assert_array_almost_equal(rhos, rhos2.reshape((2, 3, 4)))
  
file_path: nipy/nipy/algorithms/statistics/models/tests/test_regression.py
imports: import numpy
  import scipy.linalg
  from numpy.testing import assert_array_almost_equal
  from ..regression import AREstimator, ARModel, OLSModel, ar_bias_correct, ar_bias_corrector, yule_walker
label_desc: Use image node_id 6 for calling a global function with example usage: test_ar_estimator() without return types