2 * Copyright Nick Thompson, 2019
3 * Use, modification and distribution are subject to the
4 * Boost Software License, Version 1.0. (See accompanying file
5 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #include "math_unit_test.hpp"
12 #include <boost/math/statistics/ljung_box.hpp>
14 using boost::math::statistics::ljung_box;
22 // > Box.test(v, lag=1, "Ljung")
25 // X-squared = 2, df = 1, p-value = 0.1573
27 std::vector<Real> v{1,2};
29 double expected_statistic = 2;
30 double expected_pvalue = 0.15729920705028455;
32 auto [computed_statistic, computed_pvalue] = ljung_box(v, 1);
33 CHECK_ULP_CLOSE(expected_statistic, computed_statistic, 10);
34 CHECK_ULP_CLOSE(expected_pvalue, computed_pvalue, 30);
38 void test_agreement_with_mathematica()
40 std::vector<double> v{0.7739928761039216,-0.4468259278452086,0.98287381303903,-0.3943029116201079,0.6569015496559457};
41 double expected_statistic = 10.2076093223439;
42 double expected_pvalue = 0.00607359458123835072;
44 auto [computed_statistic, computed_pvalue] = ljung_box(v);
45 CHECK_ULP_CLOSE(expected_statistic, computed_statistic, 3);
46 CHECK_ULP_CLOSE(expected_pvalue, computed_pvalue, 3);
51 test_trivial<double>();
52 test_agreement_with_mathematica();
53 return boost::math::test::report_errors();