class_docstr: A regression model with an AR(p) covariance structure.
  
  In terms of a LikelihoodModel, the parameters
  are beta, the usual regression parameters,
  and sigma, a scalar nuisance parameter that
  shows up as multiplier in front of the AR(p) covariance.
  
  The linear autoregressive process of order p--AR(p)--is defined as:
      TODO
  
  Examples
  --------
  >>> from nipy.algorithms.statistics.api import Term, Formula
  >>> data = np.rec.fromarrays(([1,3,4,5,8,10,9], range(1,8)),
  ...                          names=('Y', 'X'))
  >>> f = Formula([Term("X"), 1])
  >>> dmtx = f.design(data, return_float=True)
  >>> model = ARModel(dmtx, 2)
  
  We go through the ``model.iterative_fit`` procedure long-hand:
  
  >>> for i in range(6):
  ...     results = model.fit(data['Y'])
  ...     print("AR coefficients:", model.rho)
  ...     rho, sigma = yule_walker(data["Y"] - results.predicted,
  ...                              order=2,
  ...                              df=model.df_resid)
  ...     model = ARModel(model.design, rho) #doctest: +FLOAT_CMP
  ...
  AR coefficients: [ 0.  0.]
  AR coefficients: [-0.61530877 -1.01542645]
  AR coefficients: [-0.72660832 -1.06201457]
  AR coefficients: [-0.7220361  -1.05365352]
  AR coefficients: [-0.72229201 -1.05408193]
  AR coefficients: [-0.722278   -1.05405838]
  >>> results.theta #doctest: +FLOAT_CMP
  array([ 1.59564228, -0.58562172])
  >>> results.t() #doctest: +FLOAT_CMP
  array([ 38.0890515 ,  -3.45429252])
  >>> print(results.Tcontrast([0,1]))  #doctest: +FLOAT_CMP
  <T contrast: effect=-0.58562172384377043, sd=0.16953449108110835,
  t=-3.4542925165805847, df_den=5>
  >>> print(results.Fcontrast(np.identity(2)))  #doctest: +FLOAT_CMP
  <F contrast: F=4216.810299725842, df_den=5, df_num=2>
  
  Reinitialize the model, and do the automated iterative fit
  
  >>> model.rho = np.array([0,0])
  >>> model.iterative_fit(data['Y'], niter=3)
  >>> print(model.rho)  #doctest: +FLOAT_CMP
  [-0.7220361  -1.05365352]
class_docstr_tok: ["A","regression","model","with","an","AR","(","p",")","covariance","structure",".","In","terms","of","a","LikelihoodModel",",","the","parameters","are","beta",",","the","usual","regression","parameters",",","and","sigma",",","a","scalar","nuisance","parameter","that","shows","up","as","multiplier","in","front","of","the","AR","(","p",")","covariance",".","The","linear","autoregressive","process","of","order","p","--","AR","(","p",")","--","is","defined","as",":","TODO","Examples","--","--","--","--",">",">",">","from","nipy.algorithms.statistics.api","import","Term",",","Formula",">",">",">","data","=","np.rec.fromarrays","(","(","[","1,3,4,5,8,10,9","]",",","range","(","1,8",")",")",",","...","names=","(","'","Y","'",",","'","X","'",")",")",">",">",">","f","=","Formula","(","[","Term","(","``","X","''",")",",","1","]",")",">",">",">","dmtx","=","f.design","(","data",",","return_float=True",")",">",">",">","model","=","ARModel","(","dmtx",",","2",")","We","go","through","the","``","model.iterative_fit","``","procedure","long-hand",":",">",">",">","for","i","in","range","(","6",")",":","...","results","=","model.fit","(","data","[","'","Y","'","]",")","...","print","(","``","AR","coefficients",":","''",",","model.rho",")","...","rho",",","sigma","=","yule_walker","(","data","[","``","Y","''","]","-","results.predicted",",","...","order=2",",","...","df=model.df_resid",")","...","model","=","ARModel","(","model.design",",","rho",")","#","doctest",":","+FLOAT_CMP","...","AR","coefficients",":","[","0",".","0",".","]","AR","coefficients",":","[","-0.61530877","-1.01542645","]","AR","coefficients",":","[","-0.72660832","-1.06201457","]","AR","coefficients",":","[","-0.7220361","-1.05365352","]","AR","coefficients",":","[","-0.72229201","-1.05408193","]","AR","coefficients",":","[","-0.722278","-1.05405838","]",">",">",">","results.theta","#","doctest",":","+FLOAT_CMP","array","(","[","1.59564228",",","-0.58562172","]",")",">",">",">","results.t","(",")","#","doctest",":","+FLOAT_CMP","array","(","[","38.0890515",",","-3.45429252","]",")",">",">",">","print","(","results.Tcontrast","(","[","0,1","]",")",")","#","doctest",":","+FLOAT_CMP","<","T","contrast",":","effect=-0.58562172384377043",",","sd=0.16953449108110835",",","t=-3.4542925165805847",",","df_den=5",">",">",">",">","print","(","results.Fcontrast","(","np.identity","(","2",")",")",")","#","doctest",":","+FLOAT_CMP","<","F","contrast",":","F=4216.810299725842",",","df_den=5",",","df_num=2",">","Reinitialize","the","model",",","and","do","the","automated","iterative","fit",">",">",">","model.rho","=","np.array","(","[","0,0","]",")",">",">",">","model.iterative_fit","(","data","[","'","Y","'","]",",","niter=3",")",">",">",">","print","(","model.rho",")","#","doctest",":","+FLOAT_CMP","[","-0.7220361","-1.05365352","]"]
docstr: Whiten a series of columns according to AR(p) covariance structure
  
  Parameters
  ----------
  X : array-like of shape (n_features)
      array to whiten
  
  Returns
  -------
  wX : ndarray
      X whitened with order self.order AR
code: def whiten(self, X):
      """Whiten a series of columns according to AR(p) covariance structure
  
      Parameters
      ----------
      X : array-like of shape (n_features)
          array to whiten
  
      Returns
      -------
      wX : ndarray
          X whitened with order self.order AR
      """
      X = np.asarray(X, np.float64)
      _X = X.copy()
      for i in range(self.order):
          _X[(i + 1) :] = _X[(i + 1) :] - self.rho[i] * X[0 : -(i + 1)]
      return _X
  
imports: import warnings
  import numpy
  import numpy.linalg
  import scipy.linalg
  from nibabel.onetime import auto_attr
  from scipy import stats
  from nipy.algorithms.utils.matrices import matrix_rank, pos_recipr
  from .model import LikelihoodModel, LikelihoodModelResults
label_desc: Use image node_id 3 for calling the ARModel obj's underlying member method code with example usage: obj.whiten(X) and returns: _X