class_docstr: A qualitative variable in a regression model
  
  A Factor is similar to R's factor. The levels of the Factor can be
  either strings or ints.
class_docstr_tok: ["A","qualitative","variable","in","a","regression","model","A","Factor","is","similar","to","R","'s","factor",".","The","levels","of","the","Factor","can","be","either","strings","or","ints","."]
docstr: Initialize Factor
  
  Parameters
  ----------
  name : str
  levels : [str or int]
      A sequence of strings or ints.
  char : str, optional
      prefix character for regression coefficients
docstr_tok: ["Initialize","Factor","Parameters","--","--","--","--","--","name",":","str","levels",":","[","str","or","int","]","A","sequence","of","strings","or","ints",".","char",":","str",",","optional","prefix","character","for","regression","coefficients"]
code: def __init__(self, name, levels, char="b"):
      """Initialize Factor
  
      Parameters
      ----------
      name : str
      levels : [str or int]
          A sequence of strings or ints.
      char : str, optional
          prefix character for regression coefficients
      """
      # Check whether they can all be cast to strings or ints without
      # loss.
      levelsarr = np.asarray(levels)
      if levelsarr.ndim == 0 and levelsarr.dtype.kind in "SOU":
          levelsarr = np.asarray(list(levels))
      if (
          levelsarr.dtype.kind not in "SOU"
      ):  # the levels are not strings
          if not np.all(np.equal(levelsarr, np.round(levelsarr))):
              raise ValueError("levels must be strings or ints")
          levelsarr = levelsarr.astype(np.int_)
      elif levelsarr.dtype.kind == "S":  # Byte strings, convert
          levelsarr = levelsarr.astype("U")
      Formula.__init__(
          self, [FactorTerm(name, l) for l in levelsarr], char=char
      )
      self.levels = list(levelsarr)
      self.name = name
  
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 Factor object from inherited base classes: Formula with example: obj = Factor(name, levels, char)