original_docstring: 
          A helper function to calculate the variance/std. Used to keep
          the decomposition functions cleaner
          
docstring: A helper function to calculate the variance/std. Used to keep
  the decomposition functions cleaner
docstring_tokens: A helper function to calculate the variance / std . Used to keep the decomposition functions cleaner
code: def variance(self, decomp_type, n=5000, conf=0.99):
          """
          A helper function to calculate the variance/std. Used to keep
          the decomposition functions cleaner
          """
          if self.submitted_n is not None:
              n = self.submitted_n
          if self.submitted_conf is not None:
              conf = self.submitted_conf
          if self.submitted_weight is not None:
              submitted_weight = [
                  self.submitted_weight,
                  1 - self.submitted_weight,
              ]
          bi = self.bi
          bifurcate = self.bifurcate
          endow_eff_list = []
          coef_eff_list = []
          int_eff_list = []
          exp_eff_list = []
          unexp_eff_list = []
          for _ in range(0, n):
              endog = np.column_stack((self.bi_col, self.endog))
              exog = self.exog
              amount = len(endog)
  
              samples = np.random.randint(0, high=amount, size=amount)
              endog = endog[samples]
              exog = exog[samples]
              neumark = np.delete(exog, bifurcate, axis=1)
  
              exog_f = exog[np.where(exog[:, bifurcate] == bi[0])]
              exog_s = exog[np.where(exog[:, bifurcate] == bi[1])]
              endog_f = endog[np.where(endog[:, 0] == bi[0])]
              endog_s = endog[np.where(endog[:, 0] == bi[1])]
              exog_f = np.delete(exog_f, bifurcate, axis=1)
              exog_s = np.delete(exog_s, bifurcate, axis=1)
              endog_f = endog_f[:, 1]
              endog_s = endog_s[:, 1]
              endog = endog[:, 1]
  
              two_fold_type = self.two_fold_type
  
              if self.hasconst is False:
                  exog_f = add_constant(exog_f, prepend=False)
                  exog_s = add_constant(exog_s, prepend=False)
                  exog = add_constant(exog, prepend=False)
                  neumark = add_constant(neumark, prepend=False)
  
              _f_model = OLS(endog_f, exog_f).fit(
                  cov_type=self.cov_type, cov_kwds=self.cov_kwds
              )
              _s_model = OLS(endog_s, exog_s).fit(
                  cov_type=self.cov_type, cov_kwds=self.cov_kwds
              )
              exog_f_mean = np.mean(exog_f, axis=0)
              exog_s_mean = np.mean(exog_s, axis=0)
  
              if decomp_type == 3:
                  endow_eff = (exog_f_mean - exog_s_mean) @ _s_model.params
                  coef_eff = exog_s_mean @ (_f_model.params - _s_model.params)
                  int_eff = (exog_f_mean - exog_s_mean) @ (
                      _f_model.params - _s_model.params
                  )
  
                  endow_eff_list.append(endow_eff)
                  coef_eff_list.append(coef_eff)
                  int_eff_list.append(int_eff)
  
              elif decomp_type == 2:
                  len_f = len(exog_f)
                  len_s = len(exog_s)
  
                  if two_fold_type == "cotton":
                      t_params = (len_f / (len_f + len_s) * _f_model.params) + (
                          len_s / (len_f + len_s) * _s_model.params
                      )
  
                  elif two_fold_type == "reimers":
                      t_params = 0.5 * (_f_model.params + _s_model.params)
  
                  elif two_fold_type == "self_submitted":
                      t_params = (
                          submitted_weight[0] * _f_model.params
                          + submitted_weight[1] * _s_model.params
                      )
  
                  elif two_fold_type == "nuemark":
                      _t_model = OLS(endog, neumark).fit(
                          cov_type=self.cov_type, cov_kwds=self.cov_kwds
                      )
                      t_params = _t_model.params
  
                  else:
                      _t_model = OLS(endog, exog).fit(
                          cov_type=self.cov_type, cov_kwds=self.cov_kwds
                      )
                      t_params = np.delete(_t_model.params, bifurcate)
  
                  unexplained = (exog_f_mean @ (_f_model.params - t_params)) + (
                      exog_s_mean @ (t_params - _s_model.params)
                  )
  
                  explained = (exog_f_mean - exog_s_mean) @ t_params
  
                  unexp_eff_list.append(unexplained)
                  exp_eff_list.append(explained)
  
          high, low = int(n * conf), int(n * (1 - conf))
          if decomp_type == 3:
              return [
                  np.std(np.sort(endow_eff_list)[low:high]),
                  np.std(np.sort(coef_eff_list)[low:high]),
                  np.std(np.sort(int_eff_list)[low:high]),
              ]
          elif decomp_type == 2:
              return [
                  np.std(np.sort(unexp_eff_list)[low:high]),
                  np.std(np.sort(exp_eff_list)[low:high]),
              ]
code_tokens: def variance ( self , decomp_type , n = 5000 , conf = 0.99 ) : if self . submitted_n is not None : n = self . submitted_n if self . submitted_conf is not None : conf = self . submitted_conf if self . submitted_weight is not None : submitted_weight = [ self . submitted_weight , 1 - self . submitted_weight , ] bi = self . bi bifurcate = self . bifurcate endow_eff_list = [ ] coef_eff_list = [ ] int_eff_list = [ ] exp_eff_list = [ ] unexp_eff_list = [ ] for _ in range ( 0 , n ) : endog = np . column_stack ( ( self . bi_col , self . endog ) ) exog = self . exog amount = len ( endog ) samples = np . random . randint ( 0 , high = amount , size = amount ) endog = endog [ samples ] exog = exog [ samples ] neumark = np . delete ( exog , bifurcate , axis = 1 ) exog_f = exog [ np . where ( exog [ : , bifurcate ] == bi [ 0 ] ) ] exog_s = exog [ np . where ( exog [ : , bifurcate ] == bi [ 1 ] ) ] endog_f = endog [ np . where ( endog [ : , 0 ] == bi [ 0 ] ) ] endog_s = endog [ np . where ( endog [ : , 0 ] == bi [ 1 ] ) ] exog_f = np . delete ( exog_f , bifurcate , axis = 1 ) exog_s = np . delete ( exog_s , bifurcate , axis = 1 ) endog_f = endog_f [ : , 1 ] endog_s = endog_s [ : , 1 ] endog = endog [ : , 1 ] two_fold_type = self . two_fold_type if self . hasconst is False : exog_f = add_constant ( exog_f , prepend = False ) exog_s = add_constant ( exog_s , prepend = False ) exog = add_constant ( exog , prepend = False ) neumark = add_constant ( neumark , prepend = False ) _f_model = OLS ( endog_f , exog_f ) . fit ( cov_type = self . cov_type , cov_kwds = self . cov_kwds ) _s_model = OLS ( endog_s , exog_s ) . fit ( cov_type = self . cov_type , cov_kwds = self . cov_kwds ) exog_f_mean = np . mean ( exog_f , axis = 0 ) exog_s_mean = np . mean ( exog_s , axis = 0 ) if decomp_type == 3 : endow_eff = ( exog_f_mean - exog_s_mean ) @ _s_model . params coef_eff = exog_s_mean @ ( _f_model . params - _s_model . params ) int_eff = ( exog_f_mean - exog_s_mean ) @ ( _f_model . params - _s_model . params ) endow_eff_list . append ( endow_eff ) coef_eff_list . append ( coef_eff ) int_eff_list . append ( int_eff ) elif decomp_type == 2 : len_f = len ( exog_f ) len_s = len ( exog_s ) if two_fold_type == "cotton" : t_params = ( len_f / ( len_f + len_s ) * _f_model . params ) + ( len_s / ( len_f + len_s ) * _s_model . params ) elif two_fold_type == "reimers" : t_params = 0.5 * ( _f_model . params + _s_model . params ) elif two_fold_type == "self_submitted" : t_params = ( submitted_weight [ 0 ] * _f_model . params + submitted_weight [ 1 ] * _s_model . params ) elif two_fold_type == "nuemark" : _t_model = OLS ( endog , neumark ) . fit ( cov_type = self . cov_type , cov_kwds = self . cov_kwds ) t_params = _t_model . params else : _t_model = OLS ( endog , exog ) . fit ( cov_type = self . cov_type , cov_kwds = self . cov_kwds ) t_params = np . delete ( _t_model . params , bifurcate ) unexplained = ( exog_f_mean @ ( _f_model . params - t_params ) ) + ( exog_s_mean @ ( t_params - _s_model . params ) ) explained = ( exog_f_mean - exog_s_mean ) @ t_params unexp_eff_list . append ( unexplained ) exp_eff_list . append ( explained ) high , low = int ( n * conf ) , int ( n * ( 1 - conf ) ) if decomp_type == 3 : return [ np . std ( np . sort ( endow_eff_list ) [ low : high ] ) , np . std ( np . sort ( coef_eff_list ) [ low : high ] ) , np . std ( np . sort ( int_eff_list ) [ low : high ] ) , ] elif decomp_type == 2 : return [ np . std ( np . sort ( unexp_eff_list ) [ low : high ] ) , np . std ( np . sort ( exp_eff_list ) [ low : high ] ) , ]
short_docstring: A helper function to calculate the variance/std.
short_docstring_tokens: A helper function to calculate the variance / std .
comment: """
          A helper function to calculate the variance/std. Used to keep
          the decomposition functions cleaner
          """