class_docstr: Covariance matrices for common random effects analyses.
  
  Examples
  --------
  Two subjects (here named 2 and 3):
  
  >>> subj = make_recarray([2,2,2,3,3], 's')
  >>> subj_factor = Factor('s', [2,3])
  
  By default the covariance matrix is symbolic.  The display differs a little
  between sympy versions (hence we don't check it in the doctests):
  
  >>> c = RandomEffects(subj_factor.terms)
  >>> c.cov(subj) #doctest: +IGNORE_OUTPUT
  array([[_s2_0, _s2_0, _s2_0, 0, 0],
         [_s2_0, _s2_0, _s2_0, 0, 0],
         [_s2_0, _s2_0, _s2_0, 0, 0],
         [0, 0, 0, _s2_1, _s2_1],
         [0, 0, 0, _s2_1, _s2_1]], dtype=object)
  
  With a numeric `sigma`, you get a numeric array:
  
  >>> c = RandomEffects(subj_factor.terms, sigma=np.array([[4,1],[1,6]]))
  >>> c.cov(subj)
  array([[ 4.,  4.,  4.,  1.,  1.],
         [ 4.,  4.,  4.,  1.,  1.],
         [ 4.,  4.,  4.,  1.,  1.],
         [ 1.,  1.,  1.,  6.,  6.],
         [ 1.,  1.,  1.,  6.,  6.]])
class_docstr_tok: ["Covariance","matrices","for","common","random","effects","analyses",".","Examples","--","--","--","--","Two","subjects","(","here","named","2","and","3",")",":",">",">",">","subj","=","make_recarray","(","[","2,2,2,3,3","]",",","'s","'",")",">",">",">","subj_factor","=","Factor","(","'s","'",",","[","2,3","]",")","By","default","the","covariance","matrix","is","symbolic",".","The","display","differs","a","little","between","sympy","versions","(","hence","we","do","n't","check","it","in","the","doctests",")",":",">",">",">","c","=","RandomEffects","(","subj_factor.terms",")",">",">",">","c.cov","(","subj",")","#","doctest",":","+IGNORE_OUTPUT","array","(","[","[","_s2_0",",","_s2_0",",","_s2_0",",","0",",","0","]",",","[","_s2_0",",","_s2_0",",","_s2_0",",","0",",","0","]",",","[","_s2_0",",","_s2_0",",","_s2_0",",","0",",","0","]",",","[","0",",","0",",","0",",","_s2_1",",","_s2_1","]",",","[","0",",","0",",","0",",","_s2_1",",","_s2_1","]","]",",","dtype=object",")","With","a","numeric","`","sigma","`",",","you","get","a","numeric","array",":",">",">",">","c","=","RandomEffects","(","subj_factor.terms",",","sigma=np.array","(","[","[","4,1","]",",","[","1,6","]","]",")",")",">",">",">","c.cov","(","subj",")","array","(","[","[","4.",",","4.",",","4.",",","1.",",","1",".","]",",","[","4.",",","4.",",","4.",",","1.",",","1",".","]",",","[","4.",",","4.",",","4.",",","1.",",","1",".","]",",","[","1.",",","1.",",","1.",",","6.",",","6",".","]",",","[","1.",",","1.",",","1.",",","6.",",","6",".","]","]",")"]
docstr: Initialize random effects instance
  
  Parameters
  ----------
  seq : [``sympy.Basic``]
  sigma : ndarray
       Covariance of the random effects. Defaults
       to a diagonal with entries for each random
       effect.
  char : character for regression coefficient
docstr_tok: ["Initialize","random","effects","instance","Parameters","--","--","--","--","--","seq",":","[","``","sympy.Basic","``","]","sigma",":","ndarray","Covariance","of","the","random","effects",".","Defaults","to","a","diagonal","with","entries","for","each","random","effect",".","char",":","character","for","regression","coefficient"]
code: def __init__(self, seq, sigma=None, char="e"):
      """Initialize random effects instance
  
      Parameters
      ----------
      seq : [``sympy.Basic``]
      sigma : ndarray
           Covariance of the random effects. Defaults
           to a diagonal with entries for each random
           effect.
      char : character for regression coefficient
      """
  
      self._terms = np.asarray(seq)
      q = self._terms.shape[0]
  
      self._counter = 0
      if sigma is None:
          self.sigma = np.diag([Dummy("s2_%d" % i) for i in range(q)])
      else:
          self.sigma = sigma
      if self.sigma.shape != (q, q):
          raise ValueError(
              "incorrect shape for covariance "
              "of random effects, "
              f"should have shape {q!r}"
          )
      self.char = char
  
imports: import itertools
  import warnings
  from string import ascii_letters, digits
  import numpy
  import sympy
  from scipy.linalg import pinv
  from sympy import Dummy, default_sort_key
  from sympy.utilities.lambdify import implemented_function, lambdify
  from nipy.algorithms.utils.matrices import full_rank, matrix_rank
  from nipy.utils import VisibleDeprecationWarning, _NoValue
label_desc: Use image node_id 1 to create a new RandomEffects object from inherited base classes: Formula with example: obj = RandomEffects(seq, sigma, char)