nag_library.qbk 2.6 KB

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