class_docstr: Class derived from the generic permutation_test class.
  Inherits the calibrate method
class_docstr_tok: ["Class","derived","from","the","generic","permutation_test","class",".","Inherits","the","calibrate","method"]
docstr: Initialize permutation_test_twosample instance,
  compute statistic values in each voxel and under permutation
  In:  data1, data2        data arrays
       XYZ                 voxels coordinates
           axis    <int>       Subject axis in data
       vardata1, vardata2  variance (same shape as data)
                   optional (if None, mfx statistics cannot be used)
       stat_id <char>      choice of test statistic
                           (see onesample.stats for a list of possible stats)
       niter   <int>       number of iterations of EM algorithm
       ndraws  <int>       Number of generated random t values
  Out:
       self.Tvalues        voxelwise test statistic values
       self.random_Tvalues sorted statistic values in random voxels and under random
                           sign permutation
docstr_tok: ["Initialize","permutation_test_twosample","instance",",","compute","statistic","values","in","each","voxel","and","under","permutation","In",":","data1",",","data2","data","arrays","XYZ","voxels","coordinates","axis","<","int",">","Subject","axis","in","data","vardata1",",","vardata2","variance","(","same","shape","as","data",")","optional","(","if","None",",","mfx","statistics","can","not","be","used",")","stat_id","<","char",">","choice","of","test","statistic","(","see","onesample.stats","for","a","list","of","possible","stats",")","niter","<","int",">","number","of","iterations","of","EM","algorithm","ndraws","<","int",">","Number","of","generated","random","t","values","Out",":","self.Tvalues","voxelwise","test","statistic","values","self.random_Tvalues","sorted","statistic","values","in","random","voxels","and","under","random","sign","permutation"]
code: def __init__(
      self,
      data1,
      data2,
      XYZ,
      axis=0,
      vardata1=None,
      vardata2=None,
      stat_id=DEF_STAT_TWOSAMPLE,
      niter=DEF_NITER,
      ndraws=DEF_NDRAWS,
  ):
      """
      Initialize permutation_test_twosample instance,
      compute statistic values in each voxel and under permutation
      In:  data1, data2        data arrays
           XYZ                 voxels coordinates
               axis    <int>       Subject axis in data
           vardata1, vardata2  variance (same shape as data)
                       optional (if None, mfx statistics cannot be used)
           stat_id <char>      choice of test statistic
                               (see onesample.stats for a list of possible stats)
           niter   <int>       number of iterations of EM algorithm
           ndraws  <int>       Number of generated random t values
      Out:
           self.Tvalues        voxelwise test statistic values
           self.random_Tvalues sorted statistic values in random voxels and under random
                               sign permutation
      """
      # Create data fields
      n1, p = data1.shape[axis], data1.shape[1 - axis]
      n2 = data2.shape[axis]
      self.data1 = data1
      self.data2 = data2
      self.stat_id = stat_id
      self.XYZ = XYZ
      self.axis = axis
      self.vardata1 = vardata1
      self.vardata2 = vardata2
      self.niter = niter
      self.ndraws = ndraws
      self.Tvalues = twosample_stat(
          data1,
          vardata1,
          data2,
          vardata2,
          stat_id,
          axis,
          Magics=None,
          niter=niter,
      ).squeeze()
      self.nsamples = 2
      # Compute statistic values in random voxels and under random permutations
      # Use a self.verbose flag for this output?
      # print "Computing average null distribution of test statistic..."
      self.random_Tvalues = np.zeros(ndraws, float)
      # Random voxel selection
      I = np.random.randint(0, p, size=ndraws)
      if axis == 0:
          perm_data = np.zeros((n1 + n2, ndraws), float)
          perm_data[:n1] = data1[:, I]
          perm_data[n1:] = data2[:, I]
          if vardata1 is not None:
              perm_vardata = np.zeros((n1 + n2, ndraws), float)
              perm_vardata[:n1] = vardata1[:, I]
              perm_vardata[n1:] = vardata2[:, I]
      else:
          perm_data = np.zeros((ndraws, n1 + n2), float)
          perm_data[:, :n1] = data1[I]
          perm_data[:, n1:] = data2[I]
          if vardata1 is not None:
              perm_vardata = np.zeros((ndraws, n1 + n2), float)
              perm_vardata[:, :n1] = vardata1[I]
              perm_vardata[:, n1:] = vardata2[I]
      rand_perm = np.array(
          [
              np.random.permutation(np.arange(n1 + n2))
              for i in range(ndraws)
          ]
      ).transpose()
      ravel_rand_perm = rand_perm * ndraws + np.arange(ndraws).reshape(
          1, ndraws
      )
      if axis == 0:
          perm_data = perm_data.ravel()[
              ravel_rand_perm.ravel()
          ].reshape(n1 + n2, ndraws)
          if vardata1 is not None:
              perm_vardata = perm_vardata.ravel()[
                  ravel_rand_perm.ravel()
              ].reshape(n1 + n2, ndraws)
      else:
          perm_data = (
              perm_data.transpose()
              .ravel()[ravel_rand_perm.ravel()]
              .reshape(n1 + n2, ndraws)
          ).transpose()
          if vardata1 is not None:
              perm_vardata = (
                  perm_vardata.transpose()
                  .ravel()[ravel_rand_perm.ravel()]
                  .reshape(n1 + n2, ndraws)
              ).transpose()
      perm_data1 = perm_data[:n1]
      perm_data2 = perm_data[n1:]
      if vardata1 is None:
          perm_vardata1 = None
          perm_vardata2 = None
      else:
          perm_vardata1 = perm_vardata[:n1]
          perm_vardata2 = perm_vardata[n1:]
      self.random_Tvalues = twosample_stat(
          perm_data1,
          perm_vardata1,
          perm_data2,
          perm_vardata2,
          stat_id,
          axis,
      ).squeeze()
      self.random_Tvalues.sort()
  
imports: import numpy
  import warnings
  from nipy.algorithms.graph import wgraph_from_3d_grid
  from nipy.algorithms.graph.field import Field, field_from_graph_and_data
  from ..utils import zscore
  from .onesample import stat
  from .onesample import stat_mfx
  from .twosample import stat
  from .twosample import stat_mfx
label_desc: Use image node_id 1 to create a new permutation_test_twosample object from inherited base classes: permutation_test with example: obj = permutation_test_twosample(data1, data2, XYZ, axis, vardata1, vardata2, stat_id, niter, ndraws)