Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method max_abs_deviation in stan/mcmc/chainset should be *median* not max #3316

Closed
mitzimorris opened this issue Nov 22, 2024 · 3 comments
Closed

Comments

@mitzimorris
Copy link
Member

Summary:

Naming mistake during implementation - assumed the "M" in "MAD" was "max". Wrong - it's "median".

Description:

The name of this function is inaccurate. The code shows what's going on:

  /**
   * Compute maximum absolute deviation (mad) for specified parameter.
   *
   * Follows R implementation:  constant * median(abs(x - center))
   * where the value of center is median(x) and the constant is 1.4826,
   * a scale factor for asymptotically normal consistency: `1/qnorm(3/4)`.
   * (R stats version 3.6.2)
   *
   * @param index parameter index
   * @return sample mad
   */
  double max_abs_deviation(const int index) const {
    Eigen::MatrixXd draws = samples(index);
    auto center = median(index);
    Eigen::MatrixXd abs_dev = (draws.array() - center).abs();
    Eigen::Map<Eigen::VectorXd> map(abs_dev.data(), abs_dev.size());
    return 1.4826 * stan::math::quantile(map, 0.5);
  }

Current Version:

v2.35.0

@mitzimorris
Copy link
Member Author

fixing this requires changing the function name (everywhere, including CmdStan's stansummary utility) and the docstring.
it won't actually change the code. worth doing before the release?

@bob-carpenter
Copy link
Contributor

If not before the release, then soon after. This kind of thing is super confusing if you leave it around.

@WardBrian
Copy link
Member

#3319

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants