Learn R Programming

fb4package (version 2.0.0)

optim_search_p_value: Optimization using optim() for optimal p_value

Description

Uses R's optim to find the p_value that minimises the absolute difference between the simulated metric and the target value.

Usage

optim_search_p_value(
  target_value,
  fit_type,
  simulation_function,
  method = "Brent",
  lower = 0.01,
  upper = 5,
  hessian = FALSE
)

Value

List with fitted p_value and convergence information

Arguments

target_value

Target value (final weight or total consumption)

fit_type

Type of fitting ("weight" or "consumption")

simulation_function

Function that runs simulation and returns metric

method

Optimization method ("Brent", "L-BFGS-B", etc.)

lower

Lower bound for p_value search, default 0.01

upper

Upper bound for p_value search, default 5.0

hessian

Whether to compute Hessian for standard errors, default FALSE