Skip to content

FSolveLadder

Description

FSolveLadder retries FSolve from a series of starting values until it finds coefficients that both converge and give a monotonic transformation (checked with FSolveMonotonic). Newton’s method can otherwise converge to a solution that folds back on itself and puts a spurious extra mode in the simulated distribution.

Used by: MCM(_V), MCM_CI(_V), MCM_error(_V), rerror, rerrorV

Calls: FSolve, FSolveMonotonic

Source Code

FSolveLadder = LAMBDA(
    skew,
    kurt,
    [idx],      // for recursion: index into the d-starting-value ladder
  LET(
    idx0, IF(ISOMITTED(idx), 0, idx),
    ladder, {0,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4},
    d0, INDEX(ladder, 1, idx0 + 1),
    coeffs, FSolve(skew, kurt, , , d0),
    b, INDEX(coeffs, 1, 1),
    c, INDEX(coeffs, 1, 2),
    d, INDEX(coeffs, 1, 3),
    resid, INDEX(coeffs, 1, 5),
    valid, AND(resid < 0.0000001, FSolveMonotonic(b, c, d)),
    IF(
      OR(valid, idx0 >= 8),
      HSTACK(coeffs, IF(valid, 1, 0)),
      FSolveLadder(skew, kurt, idx0 + 1)
    )
  )
);