code: def expect_v2(
      self,
      fn=None,
      args=(),
      loc=0,
      scale=1,
      lb=None,
      ub=None,
      conditional=False,
  ):
      """calculate expected value of a function with respect to the distribution
  
      location and scale only tested on a few examples
  
      Parameters
      ----------
          all parameters are keyword parameters
          fn : function (default: identity mapping)
             Function for which integral is calculated. Takes only one argument.
          args : tuple
             argument (parameters) of the distribution
          lb, ub : numbers
             lower and upper bound for integration, default is set using
             quantiles of the distribution, see Notes
          conditional : bool (False)
             If true then the integral is corrected by the conditional probability
             of the integration interval. The return value is the expectation
             of the function, conditional on being in the given interval.
  
      Returns
      -------
          expected value : float
  
      Notes
      -----
      This function has not been checked for it's behavior when the integral is
      not finite. The integration behavior is inherited from scipy.integrate.quad.
  
      The default limits are lb = self.ppf(1e-9, *args), ub = self.ppf(1-1e-9, *args)
  
      For some heavy tailed distributions, 'alpha', 'cauchy', 'halfcauchy',
      'levy', 'levy_l', and for 'ncf', the default limits are not set correctly
      even  when the expectation of the function is finite. In this case, the
      integration limits, lb and ub, should be chosen by the user. For example,
      for the ncf distribution, ub=1000 works in the examples.
  
      There are also problems with numerical integration in some other cases,
      for example if the distribution is very concentrated and the default limits
      are too large.
  
      """
      # changes: 20100809
      # correction and refactoring how loc and scale are handled
      # uses now _pdf
      # needs more testing for distribution with bound support, e.g. genpareto
  
      if fn is None:
  
          def fun(x, *args):
              return (loc + x * scale) * self._pdf(x, *args)
  
      else:
  
          def fun(x, *args):
              return fn(loc + x * scale) * self._pdf(x, *args)
  
      if lb is None:
          # lb = self.a
          try:
              lb = self.ppf(1e-9, *args)  # 1e-14 quad fails for pareto
          except ValueError:
              lb = self.a
      else:
          lb = max(
              self.a, (lb - loc) / (1.0 * scale)
          )  # transform to standardized
      if ub is None:
          # ub = self.b
          try:
              ub = self.ppf(1 - 1e-9, *args)
          except ValueError:
              ub = self.b
      else:
          ub = min(self.b, (ub - loc) / (1.0 * scale))
      if conditional:
          invfac = self._sf(lb, *args) - self._sf(ub, *args)
      else:
          invfac = 1.0
      return (
          integrate.quad(fun, lb, ub, args=args, limit=500)[0] / invfac
      )
  
file_path: statsmodels/statsmodels/sandbox/distributions/sppatch.py
imports: from statsmodels.compat.python import lmap
  import numpy
  from scipy import stats, optimize, integrate
label_desc: Use image node_id 7 for calling a global function with example usage: expect_v2(fn, args, loc, scale, lb, ub, conditional) and returns: unknown, unknown, unknown