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: Create a new variable, stratified by the levels of a Factor.
  
  Parameters
  ----------
  variable : str or simple sympy expression
      If sympy expression, then string representation must be all lower
      or upper case letters, i.e. it can be interpreted as a name.
  
  Returns
  -------
  formula : Formula
      Formula whose mean has one parameter named variable%d, for each
      level in self.levels
  
  Examples
  --------
  >>> f = Factor('a', ['x','y'])
  >>> sf = f.stratify('theta')
  >>> sf.mean
  _theta0*a_x + _theta1*a_y
docstr_tok: ["Create","a","new","variable",",","stratified","by","the","levels","of","a","Factor",".","Parameters","--","--","--","--","--","variable",":","str","or","simple","sympy","expression","If","sympy","expression",",","then","string","representation","must","be","all","lower","or","upper","case","letters",",","i.e",".","it","can","be","interpreted","as","a","name",".","Returns","--","--","--","-","formula",":","Formula","Formula","whose","mean","has","one","parameter","named","variable","%","d",",","for","each","level","in","self.levels","Examples","--","--","--","--",">",">",">","f","=","Factor","(","'","a","'",",","[","'","x","'",",","'","y","'","]",")",">",">",">","sf","=","f.stratify","(","'theta","'",")",">",">",">","sf.mean","_theta0","*","a_x","+","_theta1","*","a_y"]
code: def stratify(self, variable):
      """Create a new variable, stratified by the levels of a Factor.
  
      Parameters
      ----------
      variable : str or simple sympy expression
          If sympy expression, then string representation must be all lower
          or upper case letters, i.e. it can be interpreted as a name.
  
      Returns
      -------
      formula : Formula
          Formula whose mean has one parameter named variable%d, for each
          level in self.levels
  
      Examples
      --------
      >>> f = Factor('a', ['x','y'])
      >>> sf = f.stratify('theta')
      >>> sf.mean
      _theta0*a_x + _theta1*a_y
      """
      if not set(str(variable)).issubset(ascii_letters + digits):
          raise ValueError(
              "variable should be interpretable as a "
              "name and not have anything but digits "
              "and numbers"
          )
      variable = sympy.sympify(variable)
      f = Formula(self._terms, char=variable)
      f.name = self.name
      return f
  
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 4 for calling the Factor obj's underlying member method code with example usage: obj.stratify(variable) and returns: f