code: def slopes(
      model: Model,
      idata: az.InferenceData,
      wrt: Union[str, dict],
      conditional: Union[str, dict, list, None] = None,
      average_by: Union[str, list, bool, None] = None,
      eps: float = 1e-4,
      slope: str = "dydx",
      use_hdi: bool = True,
      prob: Union[float, None] = None,
      transforms: Union[dict, None] = None,
      sample_new_groups: bool = False,
  ) -> pd.DataFrame:
      """Compute Conditional Adjusted Slopes
  
      Parameters
      ----------
      model : bambi.Model
          The model for which we want to plot the predictions.
      idata : arviz.InferenceData
          The InferenceData object that contains the samples from the posterior distribution of
          the model.
      wrt : str, dict
          The slope of the regression with respect to (wrt) this predictor will be computed.
      conditional : str, list, dict, optional
          The covariates we would like to condition on. If dict, keys are the covariate names and
          values are the values to condition on.
      average_by: str, list, bool, optional
          The covariates we would like to average by. The passed covariate(s) will marginalize
          over the other covariates in the model. If True, it averages over all covariates
          in the model to obtain the average estimate. Defaults to `None`.
      eps : float, optional
          To compute the slope, 'wrt' is evaluated at wrt +/- 'eps'. The rate of change is then
          computed as the difference between the two values divided by 'eps'. Defaults to 1e-4.
      slope: str, optional
          The type of slope to compute. Defaults to 'dydx'.
          'dydx' represents a unit increase in 'wrt' is associated with an n-unit change in
          the response.
          'eyex' represents a percentage increase in 'wrt' is associated with an n-percent
          change in the response.
          'eydx' represents a unit increase in 'wrt' is associated with an n-percent
          change in the response.
          'dyex' represents a percent change in 'wrt' is associated with a unit increase
          in the response.
      use_hdi : bool, optional
          Whether to compute the highest density interval (defaults to True) or the quantiles.
      prob : float, optional
          The probability for the credibility intervals. Must be between 0 and 1. Defaults to 0.94.
          Changing the global variable `az.rcParams["stats.hdi_prob"]` affects this default.
      transforms : dict, optional
          Transformations that are applied to each of the variables being plotted. The keys are the
          name of the variables, and the values are functions to be applied. Defaults to `None`.
      sample_new_groups : bool, optional
          If the model contains group-level effects, and data is passed for unseen groups, whether
          to sample from the new groups. Defaults to `False`.
  
      Returns
      -------
      pandas.DataFrame
          A dataframe with the comparison values, highest density interval, `wrt` name,
          contrast value, and conditional values.
  
      Raises
      ------
      ValueError
          If length of `wrt` is greater than 1.
          If `conditional` is `None` and `wrt` is passed more than 2 values.
          If `conditional` is `None` and default `wrt` has more than 2 unique values.
          If `conditional` is a list and the length is greater than 3.
          If `slope` is not 'dydx', 'dyex', 'eyex', or 'eydx'.
          If `prob` is not > 0 and < 1.
      """
      wrt_name = wrt
      if isinstance(wrt, dict):
          if len(wrt) > 1:
              raise ValueError(
                  f"Only one predictor can be passed to 'wrt'. {len(wrt)} were passed."
              )
          wrt_name, wrt_values = next(iter(wrt.items()))
          if not isinstance(wrt_values, (list, np.ndarray)):
              wrt_values = [wrt_values]
          if len(wrt_values) > 2 and conditional is None:
              raise ValueError(
                  f"'conditional' must be specified when 'wrt' has more than 2 values. "
                  f"{wrt_name} was passed {len(wrt_values)} values."
              )
  
      if isinstance(conditional, list):
          if len(conditional) > 3:
              raise ValueError(
                  f"Only 3 covariates can be passed to 'conditional'. {len(conditional)} "
                  " were passed. If you would like to pass more than 3 covariates, "
                  "use a dictionary."
              )
  
      if not isinstance(wrt, dict) and conditional is None:
          if is_categorical_dtype(
              model.data[wrt_name]
          ) or is_string_dtype(model.data[wrt_name]):
              num_levels = len(model.data[wrt_name].unique())
              if num_levels > 2:
                  raise ValueError(
                      f"'conditional' must be specified when 'wrt' has more than 2 values. "
                      f"{wrt_name} has {num_levels} unique values."
                  )
  
      if slope not in ("dydx", "dyex", "eyex", "eydx"):
          raise ValueError(
              "'slope' must be one of ('dydx', 'dyex', 'eyex', 'eydx')"
          )
  
      if prob is None:
          prob = az.rcParams["stats.hdi_prob"]
      if not 0 < prob < 1:
          raise ValueError(
              f"'prob' must be greater than 0 and smaller than 1. It is {prob}."
          )
  
      conditional_info = ConditionalInfo(model, conditional)
  
      grid = bool(conditional_info.covariates)
      # if wrt is categorical or string dtype, call 'comparisons' to compute the
      # difference between group means as the slope
      effect_type = "slopes"
      if is_categorical_dtype(model.data[wrt_name]) or is_string_dtype(
          model.data[wrt_name]
      ):
          effect_type = "comparisons"
          eps = None
      wrt_info = VariableInfo(model, wrt, effect_type, grid, eps)
  
      lower_bound = round((1 - prob) / 2, 4)
      upper_bound = 1 - lower_bound
  
      transforms = transforms if transforms is not None else {}
      response_name = get_aliased_name(
          model.response_component.response_term
      )
      response = ResponseInfo(
          response_name, "mean", lower_bound, upper_bound
      )
      response_transform = transforms.get(response_name, identity)
  
      slopes_data = create_differences_data(
          conditional_info, wrt_info, effect_type
      )
      idata = model.predict(
          idata,
          data=slopes_data,
          sample_new_groups=sample_new_groups,
          inplace=False,
      )
  
      # returns empty array if model predictions do not have multiple dimensions
      response_dim_key = response.name + "_dim"
      if response_dim_key in idata.posterior.coords:
          response_dim = idata.posterior.coords[response_dim_key].values
      else:
          response_dim = np.empty(0)
  
      predictive_difference = PredictiveDifferences(
          model,
          slopes_data,
          wrt_info,
          conditional_info,
          response,
          use_hdi,
          kind=effect_type,
      )
      slopes_summary = predictive_difference.get_estimate(
          idata, response_transform, "diff", slope, eps, prob
      ).get_summary_df(response_dim)
  
      if average_by:
          slopes_summary = predictive_difference.average_by(
              variable=average_by
          )
  
      return enforce_dtypes(slopes_data, slopes_summary)
  
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 3 for calling a global function with example usage: slopes(model, idata, wrt, conditional, average_by, eps, slope, use_hdi, prob, transforms, sample_new_groups) and returns: enforce_dtypes