code: def altprotocol(d, design_type, *hrfs):
      """Create an object that can evaluate the FIAC.
  
      Subclass of formulae.Formula, but not necessary.
  
      Parameters
      ----------
      d : np.recarray
         recarray defining design in terms of time, sentence speaker
  
      design_type : str in ['event', 'block']
          Handles how the 'begin' term is handled.
          For 'block', the first event of each block
          is put in this group. For the 'event',
          only the first event is put in this group.
  
          The 'begin' events are convolved with hrf.glover.
  
      hrfs: symbolic HRFs
          Each event type ('SSt_SSp','SSt_DSp','DSt_SSp','DSt_DSp')
          is convolved with each of these HRFs in order.
  
      """
      if design_type == "block":
          keep = np.not_equal((np.arange(d.time.shape[0])) % 6, 0)
      else:
          keep = np.greater(np.arange(d.time.shape[0]), 0)
  
      # This first frame was used to model out a potentially
      # 'bad' first frame....
  
      _begin = d.time[~keep]
      d = d[keep]
  
      termdict = {}
      termdict["begin"] = utils.define(
          "begin", utils.events(_begin, f=hrf.glover)
      )
      drift = formulae.natural_spline(
          utils.T, knots=[N_ROWS / 2.0 + 1.25], intercept=True
      )
      for i, t in enumerate(drift.terms):
          termdict["drift%d" % i] = t
  
      # Now, specify the experimental conditions
      # The elements of termdict are DiracDeltas, rather than HRFs
  
      st = formulae.Factor("sentence", ["DSt", "SSt"])
      sp = formulae.Factor("speaker", ["DSp", "SSp"])
  
      indic = {}
      indic["sentence"] = st.main_effect
      indic["speaker"] = sp.main_effect
      indic["interaction"] = st.main_effect * sp.main_effect
      indic["average"] = formulae.I
  
      for key in indic:
          # The matrix signs will be populated with +- 1's
          # d is the recarray having fields ('time', 'sentence', 'speaker')
          signs = indic[key].design(d, return_float=True)
  
          for l, h in enumerate(hrfs):
              # symb is a sympy expression representing a sum
              # of [h(t-_t) for _t in d.time]
              symb = utils.events(d.time, amplitudes=signs, f=h)
  
              # the values of termdict will have keys like
              # 'average0', 'speaker1'
              # and values  that are sympy expressions like average0(t),
              # speaker1(t)
              termdict["%s%d" % (key, l)] = utils.define(
                  "%s%d" % (key, l), symb
              )
  
      f = formulae.Formula(list(termdict.values()))
  
      Tcontrasts = {}
      Tcontrasts["average"] = termdict["average0"]
      Tcontrasts["speaker"] = termdict["speaker0"]
      Tcontrasts["sentence"] = termdict["sentence0"]
      Tcontrasts["interaction"] = termdict["interaction0"]
  
      # F tests
  
      Fcontrasts = {}
      Fcontrasts["overall1"] = formulae.Formula(
          list(Tcontrasts.values())
      )
  
      nhrf = len(hrfs)
      Fcontrasts["averageF"] = formulae.Formula(
          [termdict["average%d" % j] for j in range(nhrf)]
      )
      Fcontrasts["speakerF"] = formulae.Formula(
          [termdict["speaker%d" % j] for j in range(nhrf)]
      )
      Fcontrasts["sentenceF"] = formulae.Formula(
          [termdict["sentence%d" % j] for j in range(nhrf)]
      )
      Fcontrasts["interactionF"] = formulae.Formula(
          [termdict["interaction%d" % j] for j in range(nhrf)]
      )
  
      Fcontrasts["overall2"] = (
          Fcontrasts["averageF"]
          + Fcontrasts["speakerF"]
          + Fcontrasts["sentenceF"]
          + Fcontrasts["interactionF"]
      )
  
      return f, Tcontrasts, Fcontrasts
  
file_path: nipy/nipy/modalities/fmri/fmristat/tests/test_FIAC.py
imports: import numpy
  from nipy.algorithms.statistics.formula import formulae
  from nipy.algorithms.statistics.models.regression import OLSModel
  from nipy.testing import assert_almost_equal
  from ...None import design, hrf, utils
  from ..None import hrf
  from .FIACdesigns import N_ROWS, altdescr, descriptions, fmristat, time_vector
label_desc: Use image node_id 3 for calling a global function with example usage: altprotocol(d, design_type) and returns: f,  Tcontrasts,  Fcontrasts