class_docstr: A specification of model family.
  
  Parameters
  ----------
  name : str
      The name of the family. It can be any string.
  likelihood : Likelihood
      A ``bambi.families.Likelihood`` instance specifying the model likelihood function.
  link : Union[str, Dict[str, Union[str, Link]]]
      The link function that's used for every parameter in the likelihood function.
      Keys are the names of the parameters and values are the link functions.
      These can be a ``str`` with a name or a ``bambi.families.Link`` instance.
      The link function transforms the linear predictors.
  
  Examples
  --------
  >>> import bambi as bmb
  
  Replicate the Gaussian built-in family.
  
  >>> sigma_prior = bmb.Prior("HalfNormal", sigma=1)
  >>> likelihood = bmb.Likelihood("Gaussian", params=["mu", "sigma"], parent="mu")
  >>> family = bmb.Family("gaussian", likelihood, "identity")
  >>> bmb.Model("y ~ x", data, family=family, priors={"sigma": sigma_prior})
  
  Replicate the Bernoulli built-in family.
  
  >>> likelihood = bmb.Likelihood("Bernoulli", parent="p")
  >>> family = bmb.Family("bernoulli", likelihood, "logit")
  >>> bmb.Model("y ~ x", data, family=family)
class_docstr_tok: ["A","specification","of","model","family",".","Parameters","--","--","--","--","--","name",":","str","The","name","of","the","family",".","It","can","be","any","string",".","likelihood",":","Likelihood","A","``","bambi.families.Likelihood","``","instance","specifying","the","model","likelihood","function",".","link",":","Union","[","str",",","Dict","[","str",",","Union","[","str",",","Link","]","]","]","The","link","function","that","'s","used","for","every","parameter","in","the","likelihood","function",".","Keys","are","the","names","of","the","parameters","and","values","are","the","link","functions",".","These","can","be","a","``","str","``","with","a","name","or","a","``","bambi.families.Link","``","instance",".","The","link","function","transforms","the","linear","predictors",".","Examples","--","--","--","--",">",">",">","import","bambi","as","bmb","Replicate","the","Gaussian","built-in","family",".",">",">",">","sigma_prior","=","bmb.Prior","(","``","HalfNormal","''",",","sigma=1",")",">",">",">","likelihood","=","bmb.Likelihood","(","``","Gaussian","''",",","params=","[","``","mu","''",",","``","sigma","''","]",",","parent=","''","mu","''",")",">",">",">","family","=","bmb.Family","(","``","gaussian","''",",","likelihood",",","``","identity","''",")",">",">",">","bmb.Model","(","``","y","~","x","''",",","data",",","family=family",",","priors=","{","``","sigma","''",":","sigma_prior","}",")","Replicate","the","Bernoulli","built-in","family",".",">",">",">","likelihood","=","bmb.Likelihood","(","``","Bernoulli","''",",","parent=","''","p","''",")",">",">",">","family","=","bmb.Family","(","``","bernoulli","''",",","likelihood",",","``","logit","''",")",">",">",">","bmb.Model","(","``","y","~","x","''",",","data",",","family=family",")"]
docstr: Get draws from the posterior predictive distribution
  
  This function works for almost all the families. It grabs the draws for the parameters
  needed in the response distribution, and then gets samples from the posterior predictive
  distribution using `pm.draw()`. It won't work when the response distribution requires
  parameters that are not available in `posterior`.
  
  Parameters
  ----------
  model : bambi.Model
      The model
  posterior : xr.Dataset
      The xarray dataset that contains the draws for all the parameters in the posterior.
      It must contain the parameters that are needed in the distribution of the response, or
      the parameters that allow to derive them.
  kwargs :
      Parameters that are used to get draws but do not appear in the posterior object or
      other configuration parameters.
      For instance, the 'n' in binomial models and multinomial models.
  
  Returns
  -------
  xr.DataArray
      A data array with the draws from the posterior predictive distribution
docstr_tok: ["Get","draws","from","the","posterior","predictive","distribution","This","function","works","for","almost","all","the","families",".","It","grabs","the","draws","for","the","parameters","needed","in","the","response","distribution",",","and","then","gets","samples","from","the","posterior","predictive","distribution","using","`","pm.draw","(",")","`",".","It","wo","n't","work","when","the","response","distribution","requires","parameters","that","are","not","available","in","`","posterior","`",".","Parameters","--","--","--","--","--","model",":","bambi.Model","The","model","posterior",":","xr.Dataset","The","xarray","dataset","that","contains","the","draws","for","all","the","parameters","in","the","posterior",".","It","must","contain","the","parameters","that","are","needed","in","the","distribution","of","the","response",",","or","the","parameters","that","allow","to","derive","them",".","kwargs",":","Parameters","that","are","used","to","get","draws","but","do","not","appear","in","the","posterior","object","or","other","configuration","parameters",".","For","instance",",","the","'n","'","in","binomial","models","and","multinomial","models",".","Returns","--","--","--","-","xr.DataArray","A","data","array","with","the","draws","from","the","posterior","predictive","distribution"]
code: def posterior_predictive(self, model, posterior, **kwargs):
      """Get draws from the posterior predictive distribution
  
      This function works for almost all the families. It grabs the draws for the parameters
      needed in the response distribution, and then gets samples from the posterior predictive
      distribution using `pm.draw()`. It won't work when the response distribution requires
      parameters that are not available in `posterior`.
  
      Parameters
      ----------
      model : bambi.Model
          The model
      posterior : xr.Dataset
          The xarray dataset that contains the draws for all the parameters in the posterior.
          It must contain the parameters that are needed in the distribution of the response, or
          the parameters that allow to derive them.
      kwargs :
          Parameters that are used to get draws but do not appear in the posterior object or
          other configuration parameters.
          For instance, the 'n' in binomial models and multinomial models.
  
      Returns
      -------
      xr.DataArray
          A data array with the draws from the posterior predictive distribution
      """
      response_dist = get_response_dist(model.family)
      response_term = model.response_component.response_term
      params = model.family.likelihood.params
      response_aliased_name = get_aliased_name(response_term)
  
      kwargs.pop("data", None)  # Remove the 'data' kwarg
      dont_reshape = kwargs.pop("dont_reshape", [])
      output_dataset_list = []
  
      # In the posterior xr.Dataset we need to consider aliases,
      # but we don't use aliases when passing kwargs to the PyMC distribution.
      for param in params:
          # Extract posterior draws for the parent parameter
          if param == model.family.likelihood.parent:
              component = model.components[model.response_name]
              var_name = response_aliased_name + "_mean"
              kwargs[param] = posterior[var_name].to_numpy()
              output_dataset_list.append(posterior[var_name])
          else:
              # Extract posterior draws for non-parent parameters
              component = model.components[param]
              if component.alias:
                  var_name = component.alias
              else:
                  var_name = f"{response_aliased_name}_{param}"
  
              if var_name in posterior:
                  kwargs[param] = posterior[var_name].to_numpy()
                  output_dataset_list.append(posterior[var_name])
              elif hasattr(component, "prior") and isinstance(
                  component.prior, (int, float)
              ):
                  kwargs[param] = np.asarray(component.prior)
              else:
                  raise ValueError(
                      "Non-parent parameter not found in posterior."
                      "This error shouldn't have happened!"
                  )
  
      # Determine the array with largest number of dimensions
      ndims_max = max(x.ndim for x in kwargs.values())
  
      # Append a dimension when needed. Required to make `pm.draw()` work.
      # However, some distributions like Multinomial, require some parameters to be of a smaller
      # dimension than others (n.ndim <= p.ndim - 1) so we don't reshape those.
      for key, values in kwargs.items():
          if key in dont_reshape:
              continue
          kwargs[key] = expand_array(values, ndims_max)
  
      if hasattr(model.family, "transform_kwargs"):
          kwargs = model.family.transform_kwargs(kwargs)
  
      # Handle constrained responses
      if response_term.is_constrained:
          # Bounds are scalars, we can safely pick them from the first row
          lower, upper = response_term.data[0, 1:]
          lower = lower if lower != -np.inf else None
          upper = upper if upper != np.inf else None
          output_array = pm.draw(
              pm.Truncated.dist(
                  response_dist.dist(**kwargs), lower=lower, upper=upper
              )
          )
      else:
          output_array = pm.draw(response_dist.dist(**kwargs))
  
      output_coords_all = xr.merge(output_dataset_list).coords
  
      coord_names = ["chain", "draw", response_aliased_name + "_obs"]
      is_multivariate = (
          hasattr(model.family, "KIND")
          and model.family.KIND == "Multivariate"
      )
  
      if is_multivariate:
          coord_names.append(response_aliased_name + "_dim")
      elif hasattr(model.family, "create_extra_pps_coord"):
          new_coords = model.family.create_extra_pps_coord()
          coord_names.append(response_aliased_name + "_dim")
          output_coords_all[response_aliased_name + "_dim"] = new_coords
  
      output_coords = {}
      for coord_name in coord_names:
          output_coords[coord_name] = output_coords_all[coord_name]
      return xr.DataArray(output_array, coords=output_coords)
  
file_path: bambi/bambi/families/family.py
imports: from typing import Dict, Union
  import numpy
  import pymc
  import xarray
  from bambi.families.link import Link
  from bambi.utils import get_auxiliary_parameters, get_aliased_name
label_desc: Use image node_id 6 for calling the Family obj's underlying member method code with example usage: obj.posterior_predictive(model, posterior) and returns: xr