code: def ar_bias_corrector(design, calc_beta, order=1):
      """Return bias correcting matrix for `design` and AR order `order`
  
      There is a slight bias in the rho estimates on residuals due to the
      correlations induced in the residuals by fitting a linear model.  See
      [Worsley2002]_.
  
      This routine implements the bias correction described in appendix A.1 of
      [Worsley2002]_.
  
      Parameters
      ----------
      design : array
          Design matrix
      calc_beta : array
          Moore-Penrose pseudoinverse of the (maybe) whitened design matrix.
          This is the matrix that, when applied to the (maybe whitened) data,
          produces the betas.
      order : int, optional
          Order p of AR(p) process
  
      Returns
      -------
      invM : array
          Matrix to bias correct estimated covariance matrix
          in calculating the AR coefficients
  
      References
      ----------
      .. [Worsley2002] K.J. Worsley, C.H. Liao, J. Aston, V. Petre, G.H. Duncan,
         F. Morales, A.C. Evans (2002) A General Statistical Analysis for fMRI
         Data.  Neuroimage 15:1:15
      """
      R = np.eye(design.shape[0]) - np.dot(design, calc_beta)
      M = np.zeros((order + 1,) * 2)
      I = np.eye(R.shape[0])
      for i in range(order + 1):
          Di = np.dot(R, spl.toeplitz(I[i]))
          for j in range(order + 1):
              Dj = np.dot(R, spl.toeplitz(I[j]))
              M[i, j] = np.diag(
                  (np.dot(Di, Dj)) / (1.0 + (i > 0))
              ).sum()
      return spl.inv(M)
  
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 2 for calling a global function with example usage: ar_bias_corrector(design, calc_beta, order) and returns: spl