From 3013bf11b93fdf76fb00e1785e73bafd1226379d Mon Sep 17 00:00:00 2001 From: Madiyar Date: Thu, 13 Apr 2023 13:17:34 +0100 Subject: [PATCH 1/2] Fix fisher_f mode The mode for F-distribution is defined when `df1 > 2` according to https://en.wikipedia.org/wiki/F-distribution. It is also reasonable since `df2 * (df1 - 2) / (df1 * (df2 + 2))` becomes zero or negative when `df1 <= 2` --- include/boost/math/distributions/fisher_f.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/math/distributions/fisher_f.hpp b/include/boost/math/distributions/fisher_f.hpp index cec79eccd6..fdf7627d2f 100644 --- a/include/boost/math/distributions/fisher_f.hpp +++ b/include/boost/math/distributions/fisher_f.hpp @@ -306,10 +306,10 @@ inline RealType mode(const fisher_f_distribution& dist) && detail::check_df( function, df2, &error_result, Policy())) return error_result; - if(df2 <= 2) + if(df1 <= 2) { return policies::raise_domain_error( - function, "Second degree of freedom was %1% but must be > 2 in order for the distribution to have a mode.", df2, Policy()); + function, "First degree of freedom was %1% but must be > 2 in order for the distribution to have a mode.", df2, Policy()); } return df2 * (df1 - 2) / (df1 * (df2 + 2)); } From 3b97cc2c8430edc2cd8a29e9c7f24eb1118dc64a Mon Sep 17 00:00:00 2001 From: Madiyar Date: Thu, 13 Apr 2023 13:26:48 +0100 Subject: [PATCH 2/2] Update include/boost/math/distributions/fisher_f.hpp Co-authored-by: Matt Borland --- include/boost/math/distributions/fisher_f.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/math/distributions/fisher_f.hpp b/include/boost/math/distributions/fisher_f.hpp index fdf7627d2f..e22cdf50ae 100644 --- a/include/boost/math/distributions/fisher_f.hpp +++ b/include/boost/math/distributions/fisher_f.hpp @@ -309,7 +309,7 @@ inline RealType mode(const fisher_f_distribution& dist) if(df1 <= 2) { return policies::raise_domain_error( - function, "First degree of freedom was %1% but must be > 2 in order for the distribution to have a mode.", df2, Policy()); + function, "First degree of freedom was %1% but must be > 2 in order for the distribution to have a mode.", df1, Policy()); } return df2 * (df1 - 2) / (df1 * (df2 + 2)); }