Uses R's optim to find the p_value that minimises
the absolute difference between the simulated metric and the target value.
optim_search_p_value(
target_value,
fit_type,
simulation_function,
method = "Brent",
lower = 0.01,
upper = 5,
hessian = FALSE
)List with fitted p_value and convergence information
Target value (final weight or total consumption)
Type of fitting ("weight" or "consumption")
Function that runs simulation and returns metric
Optimization method ("Brent", "L-BFGS-B", etc.)
Lower bound for p_value search, default 0.01
Upper bound for p_value search, default 5.0
Whether to compute Hessian for standard errors, default FALSE