class_docstr: Specification of model class.
  
  Parameters
  ----------
  formula : str or bambi.formula.Formula
      A model description written using the formula syntax from the ``formulae`` library.
  data : pandas.DataFrame
      A pandas dataframe containing the data on which the model will be fit, with column
      names matching variables defined in the formula.
  family : str or bambi.families.Family
      A specification of the model family (analogous to the family object in R). Either
      a string, or an instance of class ``bambi.families.Family``. If a string is passed, a
      family with the corresponding name must be defined in the defaults loaded at ``Model``
      initialization. Valid pre-defined families are ``"bernoulli"``, ``"beta"``,
      ``"binomial"``, ``"categorical"``, ``"gamma"``, ``"gaussian"``, ``"negativebinomial"``,
      ``"poisson"``, ``"t"``, and ``"wald"``. Defaults to ``"gaussian"``.
  priors : dict
      Optional specification of priors for one or more terms. A dictionary where the keys are
      the names of terms in the model, "common," or "group_specific" and the values are
      instances of class ``Prior``. If priors are unset, uses automatic priors inspired by
      the R rstanarm library.
  link : str or Dict[str, str]
      The name of the link function to use. Valid names are ``"cloglog"``, ``"identity"``,
      ``"inverse_squared"``, ``"inverse"``, ``"log"``, ``"logit"``, ``"probit"``, and
      ``"softmax"``. Not all the link functions can be used with all the families.
      If a dictionary, keys are the names of the target parameters and the values are the names
      of the link functions.
  categorical : str or list
      The names of any variables to treat as categorical. Can be either a single variable
      name, or a list of names. If categorical is ``None``, the data type of the columns in
      the ``data`` will be used to infer handling. In cases where numeric columns are
      to be treated as categorical (e.g., group specific factors coded as numerical IDs),
      explicitly passing variable names via this argument is recommended.
  potentials : A list of 2-tuples.
      Optional specification of potentials. A potential is an arbitrary expression added to the
      likelihood, this is generally useful to add constrains to models, that are difficult to
      express otherwise. The first term of a 2-tuple is the name of a variable in the model, the
      second a lambda function expressing the desired constraint.
      If a constraint involves n variables, you can pass n 2-tuples or pass a tuple which first
      element is a n-tuple and second element is a lambda function with n arguments. The number
      and order of the lambda function has to match the number and order of the variables names.
  dropna : bool
      When ``True``, rows with any missing values in either the predictors or outcome are
      automatically dropped from the dataset in a listwise manner.
  auto_scale : bool
      If ``True`` (default), priors are automatically rescaled to the data
      (to be weakly informative) any time default priors are used. Note that any priors
      explicitly set by the user will always take precedence over default priors.
  noncentered : bool
      If ``True`` (default), uses a non-centered parameterization for normal hyperpriors on
      grouped parameters. If ``False``, naive (centered) parameterization is used.
  center_predictors : bool
      If ``True`` (default), and if there is an intercept in the common terms, the data is
      centered by subtracting the mean. The centering is undone after sampling to provide
      the actual intercept in all distributional components that have an intercept. Note
      that this changes the interpretation of the prior on the intercept because it refers
      to the intercept of the centered data.
  extra_namespace : dict, optional
      Additional user supplied variables with transformations or data to include in the
      environment where the formula is evaluated. Defaults to `None`.
docstr: Fit the model using PyMC.
  
  Parameters
  ----------
  draws: int
      The number of samples to draw from the posterior distribution. Defaults to 1000.
  tune : int
      Number of iterations to tune. Defaults to 1000. Samplers adjust the step sizes,
      scalings or similar during tuning. These tuning samples are be drawn in addition to the
      number specified in the ``draws`` argument, and will be discarded unless
      ``discard_tuned_samples`` is set to ``False``.
  discard_tuned_samples : bool
      Whether to discard posterior samples of the tune interval. Defaults to ``True``.
  omit_offsets : bool
      Omits offset terms in the ``InferenceData`` object returned when the model includes
      group specific effects. Defaults to ``True``.
  include_mean : bool
      Compute the posterior of the mean response. Defaults to ``False``.
  inference_method : str
      The method to use for fitting the model. By default, ``"mcmc"``. This automatically
      assigns a MCMC method best suited for each kind of variables, like NUTS for continuous
      variables and Metropolis for non-binary discrete ones. Alternatively, ``"vi"``, in
      which case the model will be fitted using variational inference as implemented in PyMC
      using the ``fit`` function.
      Finally, ``"laplace"``, in which case a Laplace approximation is used and is not
      recommended other than for pedagogical use.
      To use the PyMC numpyro and blackjax samplers, use ``nuts_numpyro`` or ``nuts_blackjax``
      respectively. Both methods will only work if you can use NUTS sampling, so your model
      must be differentiable.
  init : str
      Initialization method. Defaults to ``"auto"``. The available methods are:
      * auto: Use ``"jitter+adapt_diag"`` and if this method fails it uses ``"adapt_diag"``.
      * adapt_diag: Start with a identity mass matrix and then adapt a diagonal based on the
      variance of the tuning samples. All chains use the test value (usually the prior mean)
      as starting point.
      * jitter+adapt_diag: Same as ``"adapt_diag"``, but use test value plus a uniform jitter
      in [-1, 1] as starting point in each chain.
      * advi+adapt_diag: Run ADVI and then adapt the resulting diagonal mass matrix based on
      the sample variance of the tuning samples.
      * advi+adapt_diag_grad: Run ADVI and then adapt the resulting diagonal mass matrix based
      on the variance of the gradients during tuning. This is **experimental** and might be
      removed in a future release.
      * advi: Run ADVI to estimate posterior mean and diagonal mass matrix.
      * advi_map: Initialize ADVI with MAP and use MAP as starting point.
      * map: Use the MAP as starting point. This is strongly discouraged.
      * adapt_full: Adapt a dense mass matrix using the sample covariances. All chains use the
      test value (usually the prior mean) as starting point.
      * jitter+adapt_full: Same as ``"adapt_full"``, but use test value plus a uniform jitter
      in [-1, 1] as starting point in each chain.
  n_init : int
      Number of initialization iterations. Only works for ``"advi"`` init methods.
  chains : int
      The number of chains to sample. Running independent chains is important for some
      convergence statistics and can also reveal multiple modes in the posterior. If ``None``,
      then set to either ``cores`` or 2, whichever is larger.
  cores : int
      The number of chains to run in parallel. If ``None``, it is equal to the number of CPUs
      in the system unless there are more than 4 CPUs, in which case it is set to 4.
  random_seed : int or list of ints
      A list is accepted if cores is greater than one.
  **kwargs :
      For other kwargs see the documentation for ``PyMC.sample()``.
  
  Returns
  -------
  An ArviZ ``InferenceData`` instance if inference_method is  ``"mcmc"`` (default),
  "nuts_numpyro", "nuts_blackjax" or "laplace".
  An ``Approximation`` object if  ``"vi"``.
docstr_tok: ["Fit","the","model","using","PyMC",".","Parameters","--","--","--","--","--","draws",":","int","The","number","of","samples","to","draw","from","the","posterior","distribution",".","Defaults","to","1000.","tune",":","int","Number","of","iterations","to","tune",".","Defaults","to","1000",".","Samplers","adjust","the","step","sizes",",","scalings","or","similar","during","tuning",".","These","tuning","samples","are","be","drawn","in","addition","to","the","number","specified","in","the","``","draws","``","argument",",","and","will","be","discarded","unless","``","discard_tuned_samples","``","is","set","to","``","False","``",".","discard_tuned_samples",":","bool","Whether","to","discard","posterior","samples","of","the","tune","interval",".","Defaults","to","``","True","``",".","omit_offsets",":","bool","Omits","offset","terms","in","the","``","InferenceData","``","object","returned","when","the","model","includes","group","specific","effects",".","Defaults","to","``","True","``",".","include_mean",":","bool","Compute","the","posterior","of","the","mean","response",".","Defaults","to","``","False","``",".","inference_method",":","str","The","method","to","use","for","fitting","the","model",".","By","default",",","``","``","mcmc","''","``",".","This","automatically","assigns","a","MCMC","method","best","suited","for","each","kind","of","variables",",","like","NUTS","for","continuous","variables","and","Metropolis","for","non-binary","discrete","ones",".","Alternatively",",","``","``","vi","''","``",",","in","which","case","the","model","will","be","fitted","using","variational","inference","as","implemented","in","PyMC","using","the","``","fit","``","function",".","Finally",",","``","``","laplace","''","``",",","in","which","case","a","Laplace","approximation","is","used","and","is","not","recommended","other","than","for","pedagogical","use",".","To","use","the","PyMC","numpyro","and","blackjax","samplers",",","use","``","nuts_numpyro","``","or","``","nuts_blackjax","``","respectively",".","Both","methods","will","only","work","if","you","can","use","NUTS","sampling",",","so","your","model","must","be","differentiable",".","init",":","str","Initialization","method",".","Defaults","to","``","``","auto","''","``",".","The","available","methods","are",":","*","auto",":","Use","``","``","jitter+adapt_diag","''","``","and","if","this","method","fails","it","uses","``","``","adapt_diag","''","``",".","*","adapt_diag",":","Start","with","a","identity","mass","matrix","and","then","adapt","a","diagonal","based","on","the","variance","of","the","tuning","samples",".","All","chains","use","the","test","value","(","usually","the","prior","mean",")","as","starting","point",".","*","jitter+adapt_diag",":","Same","as","``","``","adapt_diag","''","``",",","but","use","test","value","plus","a","uniform","jitter","in","[","-1",",","1","]","as","starting","point","in","each","chain",".","*","advi+adapt_diag",":","Run","ADVI","and","then","adapt","the","resulting","diagonal","mass","matrix","based","on","the","sample","variance","of","the","tuning","samples",".","*","advi+adapt_diag_grad",":","Run","ADVI","and","then","adapt","the","resulting","diagonal","mass","matrix","based","on","the","variance","of","the","gradients","during","tuning",".","This","is","*","*","experimental","*","*","and","might","be","removed","in","a","future","release",".","*","advi",":","Run","ADVI","to","estimate","posterior","mean","and","diagonal","mass","matrix",".","*","advi_map",":","Initialize","ADVI","with","MAP","and","use","MAP","as","starting","point",".","*","map",":","Use","the","MAP","as","starting","point",".","This","is","strongly","discouraged",".","*","adapt_full",":","Adapt","a","dense","mass","matrix","using","the","sample","covariances",".","All","chains","use","the","test","value","(","usually","the","prior","mean",")","as","starting","point",".","*","jitter+adapt_full",":","Same","as","``","``","adapt_full","''","``",",","but","use","test","value","plus","a","uniform","jitter","in","[","-1",",","1","]","as","starting","point","in","each","chain",".","n_init",":","int","Number","of","initialization","iterations",".","Only","works","for","``","``","advi","''","``","init","methods",".","chains",":","int","The","number","of","chains","to","sample",".","Running","independent","chains","is","important","for","some","convergence","statistics","and","can","also","reveal","multiple","modes","in","the","posterior",".","If","``","None","``",",","then","set","to","either","``","cores","``","or","2",",","whichever","is","larger",".","cores",":","int","The","number","of","chains","to","run","in","parallel",".","If","``","None","``",",","it","is","equal","to","the","number","of","CPUs","in","the","system","unless","there","are","more","than","4","CPUs",",","in","which","case","it","is","set","to","4.","random_seed",":","int","or","list","of","ints","A","list","is","accepted","if","cores","is","greater","than","one",".","*","*","kwargs",":","For","other","kwargs","see","the","documentation","for","``","PyMC.sample","(",")","``",".","Returns","--","--","--","-","An","ArviZ","``","InferenceData","``","instance","if","inference_method","is","``","``","mcmc","''","``","(","default",")",",","''","nuts_numpyro","''",",","``","nuts_blackjax","''","or","``","laplace","''",".","An","``","Approximation","``","object","if","``","``","vi","''","``","."]
code: def fit(
      self,
      draws=1000,
      tune=1000,
      discard_tuned_samples=True,
      omit_offsets=True,
      include_mean=False,
      inference_method="mcmc",
      init="auto",
      n_init=50000,
      chains=None,
      cores=None,
      random_seed=None,
      **kwargs,
  ):
      """Fit the model using PyMC.
  
      Parameters
      ----------
      draws: int
          The number of samples to draw from the posterior distribution. Defaults to 1000.
      tune : int
          Number of iterations to tune. Defaults to 1000. Samplers adjust the step sizes,
          scalings or similar during tuning. These tuning samples are be drawn in addition to the
          number specified in the ``draws`` argument, and will be discarded unless
          ``discard_tuned_samples`` is set to ``False``.
      discard_tuned_samples : bool
          Whether to discard posterior samples of the tune interval. Defaults to ``True``.
      omit_offsets : bool
          Omits offset terms in the ``InferenceData`` object returned when the model includes
          group specific effects. Defaults to ``True``.
      include_mean : bool
          Compute the posterior of the mean response. Defaults to ``False``.
      inference_method : str
          The method to use for fitting the model. By default, ``"mcmc"``. This automatically
          assigns a MCMC method best suited for each kind of variables, like NUTS for continuous
          variables and Metropolis for non-binary discrete ones. Alternatively, ``"vi"``, in
          which case the model will be fitted using variational inference as implemented in PyMC
          using the ``fit`` function.
          Finally, ``"laplace"``, in which case a Laplace approximation is used and is not
          recommended other than for pedagogical use.
          To use the PyMC numpyro and blackjax samplers, use ``nuts_numpyro`` or ``nuts_blackjax``
          respectively. Both methods will only work if you can use NUTS sampling, so your model
          must be differentiable.
      init : str
          Initialization method. Defaults to ``"auto"``. The available methods are:
          * auto: Use ``"jitter+adapt_diag"`` and if this method fails it uses ``"adapt_diag"``.
          * adapt_diag: Start with a identity mass matrix and then adapt a diagonal based on the
          variance of the tuning samples. All chains use the test value (usually the prior mean)
          as starting point.
          * jitter+adapt_diag: Same as ``"adapt_diag"``, but use test value plus a uniform jitter
          in [-1, 1] as starting point in each chain.
          * advi+adapt_diag: Run ADVI and then adapt the resulting diagonal mass matrix based on
          the sample variance of the tuning samples.
          * advi+adapt_diag_grad: Run ADVI and then adapt the resulting diagonal mass matrix based
          on the variance of the gradients during tuning. This is **experimental** and might be
          removed in a future release.
          * advi: Run ADVI to estimate posterior mean and diagonal mass matrix.
          * advi_map: Initialize ADVI with MAP and use MAP as starting point.
          * map: Use the MAP as starting point. This is strongly discouraged.
          * adapt_full: Adapt a dense mass matrix using the sample covariances. All chains use the
          test value (usually the prior mean) as starting point.
          * jitter+adapt_full: Same as ``"adapt_full"``, but use test value plus a uniform jitter
          in [-1, 1] as starting point in each chain.
      n_init : int
          Number of initialization iterations. Only works for ``"advi"`` init methods.
      chains : int
          The number of chains to sample. Running independent chains is important for some
          convergence statistics and can also reveal multiple modes in the posterior. If ``None``,
          then set to either ``cores`` or 2, whichever is larger.
      cores : int
          The number of chains to run in parallel. If ``None``, it is equal to the number of CPUs
          in the system unless there are more than 4 CPUs, in which case it is set to 4.
      random_seed : int or list of ints
          A list is accepted if cores is greater than one.
      **kwargs :
          For other kwargs see the documentation for ``PyMC.sample()``.
  
      Returns
      -------
      An ArviZ ``InferenceData`` instance if inference_method is  ``"mcmc"`` (default),
      "nuts_numpyro", "nuts_blackjax" or "laplace".
      An ``Approximation`` object if  ``"vi"``.
      """
      method = kwargs.pop("method", None)
      if method is not None:
          if inference_method == "vi":
              kwargs["method"] = method
          else:
              warnings.warn(
                  "the method argument has been deprecated, please use inference_method",
                  FutureWarning,
              )
              inference_method = method
  
      if not self.built:
          self.build()
  
      # Tell user which event is being modeled
      if isinstance(self.family, univariate.Bernoulli):
          response = self.components[self.response_name]
          _log.info(
              "Modeling the probability that %s==%s",
              response.response_term.name,
              str(response.response_term.success),
          )
  
      return self.backend.run(
          draws=draws,
          tune=tune,
          discard_tuned_samples=discard_tuned_samples,
          omit_offsets=omit_offsets,
          include_mean=include_mean,
          inference_method=inference_method,
          init=init,
          n_init=n_init,
          chains=chains,
          cores=cores,
          random_seed=random_seed,
          **kwargs,
      )
  
imports: import logging
  import warnings
  from copy import deepcopy
  from importlib.metadata import version
  import formulae
  import pymc
  import pandas
  from arviz.plots import plot_posterior
  from bambi.backend import PyMCModel
  from bambi.defaults import get_builtin_family
  from bambi.model_components import ConstantComponent, DistributionalComponent
  from bambi.families import Family, univariate
  from bambi.formula import Formula, check_ordinal_formula
  from bambi.priors import Prior, PriorScaler
  from bambi.transformations import transformations_namespace
  from bambi.utils import clean_formula_lhs, get_aliased_name, get_auxiliary_parameters, indentify, listify, remove_common_intercept, wrapify
label_desc: Use image node_id 2 for calling the Model obj's underlying member method code with example usage: obj.fit(draws, tune, discard_tuned_samples, omit_offsets, include_mean, inference_method, init, n_init, chains, cores, random_seed) and returns: self