code: def _relimp(S):
      """Relative importance of predictors in multiple regression.
  
      This is an internal function. This function should only be used with a low
      number of predictors. Indeed, the computation time roughly doubles for each
      additional predictor.
  
      Parameters
      ----------
      S : pd.DataFrame
          Covariance matrix. The target variable MUST be the FIRST column,
          followed by the predictors (excluding the intercept).
      """
      assert isinstance(S, pd.DataFrame)
      cols = S.columns.tolist()
  
      # Define indices of columns: .iloc is faster than .loc
      predictors = cols[1:]
      npred = len(predictors)
      target_int = 0
      predictors_int = np.arange(1, npred + 1)
  
      # Calculate total sum of squares and beta coefficients
      # Note that the R^2 that we calculate below is always the R^2 of the model
      # INCLUDING the intercept!
      ss_tot = S.iat[target_int, target_int]
      betas = (
          np.linalg.pinv(S.iloc[predictors_int, predictors_int])
          @ S.iloc[predictors_int, target_int]
      )
      r2_full = betas @ S.iloc[target_int, predictors_int] / ss_tot
  
      # Pre-computed SSreg dictionnary
      ss_reg_precomp = {}
  
      # Start looping over predictors
      all_preds = []
      for pred in predictors_int:
          loo = np.setdiff1d(predictors_int, pred)
          r2_seq_mean = []
          # Loop over number of predictors
          for k in np.arange(0, npred - 1):
              r2_seq = []
              # Loop over combinations of predictors
              for p in itertools.combinations(loo, int(k)):
                  p = list(p)
                  p_with = p + [pred]
  
                  # To avoid calculating several times the same values
                  # we use a trick here: we save the first calculation
                  # to a dictionnary where the key is the sorted string
                  # (hence the order does not matter)
                  if str(sorted(p)) in ss_reg_precomp.keys():
                      ss_reg_without = ss_reg_precomp[str(sorted(p))]
                  else:
                      S_without = S.iloc[p, target_int]
                      ss_reg_without = (
                          np.linalg.pinv(S.iloc[p, p])
                          @ S_without
                          @ S_without
                      )
                      ss_reg_precomp[str(sorted(p))] = ss_reg_without
  
                  S_with = S.iloc[p_with, target_int]
                  ss_reg_with = (
                      pinvh(S.iloc[p_with, p_with]) @ S_with @ S_with
                  )
                  ss_reg_precomp[str(sorted(p_with))] = ss_reg_with
  
                  # Calculate R^2
                  r2_diff = (ss_reg_with - ss_reg_without) / ss_tot
                  # Append the difference
                  r2_seq.append(r2_diff)
  
              # First averaging
              r2_seq_mean.append(np.mean(r2_seq))
  
          # When Sk(r) = S
          S_without = S.iloc[loo, target_int]
          ss_reg = (
              np.linalg.pinv(S.iloc[loo, loo]) @ S_without @ S_without
          )
          r2_without = ss_reg / ss_tot
          r2_seq = r2_full - r2_without
          r2_seq_mean.append(r2_seq)
          all_preds.append(np.mean(r2_seq_mean))
  
      stats_relimp = {
          "names": predictors,
          "relimp": all_preds,
          "relimp_perc": all_preds / sum(all_preds) * 100,
      }
  
      return stats_relimp
  
file_path: pingouin/pingouin/regression.py
imports: import itertools
  import warnings
  import numpy
  import pandas
  import pandas_flavor
  from scipy.stats import t, norm
  from scipy.linalg import pinvh, lstsq
  from pingouin.config import options
  from pingouin.utils import remove_na
  from pingouin.utils import _flatten_list
  from pingouin.utils import _postprocess_dataframe
label_desc: Use image node_id 2 for calling a global function with example usage: _relimp(S) and returns: stats_relimp