1[section:nag_library Comparison with C, R, FORTRAN-style Free Functions] 2 3You are probably familiar with a statistics library that has free functions, 4for example the classic [@http://nag.com/numeric/CL/CLdescription.asp NAG C library] 5and matching [@http://nag.com/numeric/FL/FLdescription.asp NAG FORTRAN Library], 6[@http://office.microsoft.com/en-us/excel/HP052090051033.aspx Microsoft Excel BINOMDIST(number_s,trials,probability_s,cumulative)], 7[@http://www.r-project.org/ R], [@http://www.ptc.com/products/mathcad/mathcad14/mathcad_func_chart.htm MathCAD pbinom] 8and many others. 9 10If so, you may find 'Distributions as Objects' unfamiliar, if not alien. 11 12However, *do not panic*, both definition and usage are not really very different. 13 14A very simple example of generating the same values as the 15[@http://nag.com/numeric/CL/CLdescription.asp NAG C library] 16for the binomial distribution follows. 17(If you find slightly different values, the Boost C++ version, using double or better, 18is very likely to be the more accurate. 19Of course, accuracy is not usually a concern for most applications of this function). 20 21The [@http://www.nag.co.uk/numeric/cl/manual/pdf/G01/g01bjc.pdf NAG function specification] is 22 23 void nag_binomial_dist(Integer n, double p, Integer k, 24 double *plek, double *pgtk, double *peqk, NagError *fail) 25 26and is called 27 28 g01bjc(n, p, k, &plek, &pgtk, &peqk, NAGERR_DEFAULT); 29 30The equivalent using this Boost C++ library is: 31 32 using namespace boost::math; // Using declaration avoids very long names. 33 binomial my_dist(4, 0.5); // c.f. NAG n = 4, p = 0.5 34 35and values can be output thus: 36 37 cout 38 << my_dist.trials() << " " // Echo the NAG input n = 4 trials. 39 << my_dist.success_fraction() << " " // Echo the NAG input p = 0.5 40 << cdf(my_dist, 2) << " " // NAG plek with k = 2 41 << cdf(complement(my_dist, 2)) << " " // NAG pgtk with k = 2 42 << pdf(my_dist, 2) << endl; // NAG peqk with k = 2 43 44`cdf(dist, k)` is equivalent to NAG library `plek`, lower tail probability of <= k 45 46`cdf(complement(dist, k))` is equivalent to NAG library `pgtk`, upper tail probability of > k 47 48`pdf(dist, k)` is equivalent to NAG library `peqk`, point probability of == k 49 50See [@../../example/binomial_example_nag.cpp binomial_example_nag.cpp] for details. 51 52[endsect] [/section:nag_library Comparison with C, R, FORTRAN-style Free Functions] 53 54[/ 55 Copyright 2006 John Maddock and Paul A. Bristow. 56 Distributed under the Boost Software License, Version 1.0. 57 (See accompanying file LICENSE_1_0.txt or copy at 58 http://www.boost.org/LICENSE_1_0.txt). 59] 60 61