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: Initialize AR model instance
  
  Parameters
  ----------
  design : ndarray
      2D array with design matrix
  rho : int or array-like
      If int, gives order of model, and initializes rho to zeros.  If
      ndarray, gives initial estimate of rho. Be careful as ``ARModel(X,
      1) != ARModel(X, 1.0)``.
code: def __init__(self, design, rho):
      """Initialize AR model instance
  
      Parameters
      ----------
      design : ndarray
          2D array with design matrix
      rho : int or array-like
          If int, gives order of model, and initializes rho to zeros.  If
          ndarray, gives initial estimate of rho. Be careful as ``ARModel(X,
          1) != ARModel(X, 1.0)``.
      """
      if type(rho) is int:
          self.order = rho
          self.rho = np.zeros(self.order, np.float64)
      else:
          self.rho = np.squeeze(np.asarray(rho))
          if len(self.rho.shape) not in [0, 1]:
              raise ValueError(
                  "AR parameters must be a scalar or a vector"
              )
          if self.rho.shape == ():
              self.rho.shape = (1,)
          self.order = self.rho.shape[0]
      super().__init__(design)
  
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 1 to create a new ARModel object from inherited base classes: OLSModel with example: obj = ARModel(design, rho)