class_docstr: Computes predictive differences and their uncertainty intervals for
  'comparisons' and 'slopes' effects and returns a summary dataframe of the
  results.
  
  Parameters
  ----------
  model : Model
      Bambi model object.
  preds_data : pd.DataFrame
      Dataframe used to generate predictions.
  variable : VariableInfo
      Variable of interest with its name and values.
  conditional : ConditionalInfo
      Conditional covariates with their names and values (if any).
  response : ResponseInfo
      Response variable with its name and target.
  use_hdi : bool
      Whether to use the highest density interval (HDI) (True) or quantiles (False).
  kind : str
      Type of effect to compute. Either 'comparisons' or 'slopes'.
  
  Returns
  -------
  summary_df : pd.DataFrame
      Dataframe with the data used to generate predictions, the effect kind
      and type, variable of interest name and value, and the mean and uncertainty
      intervals of the predictive difference estimate.
docstr: Uses the original 'summary_df' to perform a marginal (if 'variable=True')
  or group by average if covariate(s) are passed.
  
  Parameters
  ----------
  variable : Union[bool, str]
      If 'True', then average over all covariates. If a string
      is passed, then a group by average is performed.
  
  Returns
  -------
  pd.DataFrame
      A dataframe containing the marginal or group by average.
docstr_tok: ["Uses","the","original","'summary_df","'","to","perform","a","marginal","(","if","'variable=True","'",")","or","group","by","average","if","covariate","(","s",")","are","passed",".","Parameters","--","--","--","--","--","variable",":","Union","[","bool",",","str","]","If","'True","'",",","then","average","over","all","covariates",".","If","a","string","is","passed",",","then","a","group","by","average","is","performed",".","Returns","--","--","--","-","pd.DataFrame","A","dataframe","containing","the","marginal","or","group","by","average","."]
code: def average_by(self, variable: Union[bool, str]) -> pd.DataFrame:
      """Uses the original 'summary_df' to perform a marginal (if 'variable=True')
      or group by average if covariate(s) are passed.
  
      Parameters
      ----------
      variable : Union[bool, str]
          If 'True', then average over all covariates. If a string
          is passed, then a group by average is performed.
  
      Returns
      -------
      pd.DataFrame
          A dataframe containing the marginal or group by average.
      """
      if variable is True:
          contrast_df_avg = average_over(self.summary_df, "all")
          contrast_df_avg.insert(0, "term", self.variable.name)
          contrast_df_avg.insert(1, "estimate_type", self.estimate_name)
          if self.kind != "slopes" and len(self.variable.values) < 3:
              contrast_df_avg.insert(2, "value", self.contrast_values)
      else:
          contrast_df_avg = average_over(self.summary_df, variable)
          contrast_df_avg.insert(0, "term", self.variable.name)
          contrast_df_avg.insert(1, "estimate_type", self.estimate_name)
          if self.kind != "slopes" and len(self.variable.values) < 3:
              contrast_df_avg.insert(2, "value", self.contrast_values)
  
      return contrast_df_avg.reset_index(drop=True)
  
imports: from dataclasses import dataclass, field
  import itertools
  from typing import Dict, Union
  import arviz
  import numpy
  import pandas
  from pandas.api.types import is_categorical_dtype, is_string_dtype
  import xarray
  from bambi.models import Model
  from bambi.interpret.create_data import create_differences_data, create_predictions_data
  from bambi.interpret.utils import average_over, ConditionalInfo, enforce_dtypes, identity, merge, VariableInfo
  from bambi.utils import get_aliased_name
label_desc: Use image node_id 5 for calling the PredictiveDifferences obj's underlying member method code with example usage: obj.average_by(variable) and returns: contrast_df_avg