code: def test_yule_walker_R():
      # Test YW implementation against R results
      Y = np.array([1, 3, 4, 5, 8, 9, 10])
      N = len(Y)
      X = np.ones((N, 2))
      X[:, 0] = np.arange(1, 8)
      pX = spl.pinv(X)
      betas = np.dot(pX, Y)
      Yhat = Y - np.dot(X, betas)
  
      # R results obtained from:
      # >>> np.savetxt('yhat.csv', Yhat)
      # > yhat = read.table('yhat.csv')
      # > ar.yw(yhat$V1, aic=FALSE, order.max=2)
      def r_fudge(sigma, order):
          # Reverse fudge in ar.R calculation labeled as splus compatibility fix
          return sigma**2 * N / (N - order - 1)
  
      rhos, sd = yule_walker(Yhat, 1, "mle")
      assert_array_almost_equal(rhos, [-0.3004], 4)
      assert_array_almost_equal(r_fudge(sd, 1), 0.2534, 4)
      rhos, sd = yule_walker(Yhat, 2, "mle")
      assert_array_almost_equal(rhos, [-0.5113, -0.7021], 4)
      assert_array_almost_equal(r_fudge(sd, 2), 0.1606, 4)
      rhos, sd = yule_walker(Yhat, 3, "mle")
      assert_array_almost_equal(rhos, [-0.6737, -0.8204, -0.2313], 4)
      assert_array_almost_equal(r_fudge(sd, 3), 0.2027, 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 5 for calling a global function with example usage: test_yule_walker_R() and returns: unknown