estim8.profile#

This module implements functionality for profiling likelihoods and likelihood based confidence intervals.

class estim8.profile.ProfileSampler(parameter, mle: float, mle_negll: float, negll_threshold: float, optimizer: Optimization, bounds: List[float], direction: Literal[-1, 1], stepsize=0.02, max_steps: int | None = None)#

Bases: object

Sample points along a profile likelihood curve.

Parameters:
parameterstr

Name of the parameter to profile

mlefloat

Maximum likelihood estimate of the parameter

mle_negllfloat

Negative log-likelihood at the MLE

negll_thresholdfloat

Threshold value for the negative log-likelihood

optimizerOptimization

Optimizer instance to use for likelihood calculations

boundsList[float]

Parameter bounds [lower, upper]

directionLiteral[-1, 1]

Direction to walk the profile (1 for positive, -1 for negative)

stepsizefloat, optional

Relative step size for parameter updates, by default 0.02

max_stepsint, optional

Maximum number of steps to take, by default None, in which case the sampler proceeds until the negll threshold is reached.

Methods

next_pl_sample()

Calculate the next profile likelihood sample point.

next_step()

Take a next fixed step along the profile.

update_optimizer_objective(value)

Update the optimizer's objective function with a new parameter value and set a new task_id.

walk_profile()

Walk the complete profile likelihood curve.

next_pl_sample()#

Calculate the next profile likelihood sample point.

Updates the internal samples array with the new point and checks if the profile likelihood threshold has been exceeded.

next_step()#

Take a next fixed step along the profile.

Returns:
float

The next value of the parameter to evaluate

update_optimizer_objective(value: float)#

Update the optimizer’s objective function with a new parameter value and set a new task_id.

Parameters:
valuefloat

New value for the profiled parameter

walk_profile()#

Walk the complete profile likelihood curve.

Returns:
tuple

Tuple containing: - numpy.ndarray: Array of sample points [(parameter_value, negll), …] - str: Name of the profiled parameter

estim8.profile.approximate_confidence_interval(xvalues, negll_values, threshold)#

Approximate the confidence interval from profile likelihood results.

Parameters:
xvaluesnumpy.ndarray

The parameter values of the profile likelihood curve

negll_valuesnumpy.ndarray

The negative log-likelihood values of the profile likelihood curve

thresholdfloat

The threshold value for the confidence interval

Returns:
tuple

Tuple containing: - float: Lower bound of the confidence interval - float: Upper bound of the confidence interval

Raises:
ValueError

If confidence interval bounds cannot be found

estim8.profile.calculate_negll_thresshold(alpha: float = 0.05, df: int = 1, mle_negll: float = 0)#

Calculate the negative log-likelihood threshold for profile likelihood.

Parameters:
alphafloat, optional

Significance level, by default 0.05

dfint, optional

Degrees of freedom, by default 1

mle_negllfloat, optional

Maximum likelihood estimate of negative log-likelihood, by default 0

Returns:
float

The threshold value for the negative log-likelihood