class_docstr: Class used to calculate the confidence interval.
class_docstr_tok: ["Class","used","to","calculate","the","confidence","interval","."]
docstr: Find a value for given parameter so that prob(val) > sigmas.
docstr_tok: ["Find","a","value","for","given","parameter","so","that","prob","(","val",")",">","sigmas","."]
code: def find_limit(self, para, direction):
      """Find a value for given parameter so that prob(val) > sigmas."""
      if self.verbose:
          print(f"Calculating CI for {para.name}")
      self.reset_vals()
  
      # determine starting step
      if para.stderr > 0 and para.stderr < abs(para.value):
          step = para.stderr
      else:
          step = max(abs(para.value) * 0.2, 0.001)
      para.vary = False
      start_val = para.value
  
      old_prob = 0
      limit = start_val
      i = 0
      bound_reached = False
      max_prob = max(self.probs)
  
      while old_prob < max_prob:
          i += 1
          limit += step * direction
          if limit > para.max:
              limit = para.max
              bound_reached = True
          elif limit < para.min:
              limit = para.min
              bound_reached = True
  
          new_prob = self.calc_prob(para, limit)
          rel_change = (new_prob - old_prob) / max(
              new_prob, old_prob, 1e-12
          )
          old_prob = new_prob
          if self.verbose:
              print(
                  f"P({para.name}={limit}) = {new_prob}, "
                  f"max. prob={max_prob}"
              )
  
          # check for convergence
          if bound_reached and new_prob < max(self.probs):
              errmsg = (
                  f"Bound reached with prob({para.name}={limit}) "
                  f"= {new_prob} < max(sigmas)"
              )
              warn(errmsg)
              break
  
          if i > self.maxiter:
              errmsg = (
                  f"maxiter={self.maxiter} reached and prob("
                  f"{para.name}={limit}) = {new_prob} < max(sigmas)"
              )
              warn(errmsg)
              break
  
          if rel_change < self.min_rel_change:
              errmsg = (
                  f"rel_change={rel_change} < {self.min_rel_change} "
                  f"at iteration {i} and prob({para.name}={limit}) = "
                  f"{new_prob} < max(sigmas)"
              )
              warn(errmsg)
              break
  
      self.reset_vals()
  
      return limit, new_prob
  
file_path: lmfit-py/lmfit/confidence.py
imports: from warnings import warn
  import numpy
  from scipy.optimize import root_scalar
  from scipy.special import erf
  from scipy.stats import f
  from .minimizer import MinimizerException
label_desc: Use image node_id 5 for calling the ConfidenceInterval obj's underlying member method code with example usage: obj.find_limit(para, direction) and returns: limit,  new_prob