3 <meta http-equiv=
"Content-Type" content=
"text/html; charset=US-ASCII">
4 <title>Comparison with C, R, FORTRAN-style Free Functions
</title>
5 <link rel=
"stylesheet" href=
"../../../math.css" type=
"text/css">
6 <meta name=
"generator" content=
"DocBook XSL Stylesheets V1.77.1">
7 <link rel=
"home" href=
"../../../index.html" title=
"Math Toolkit 2.5.1">
8 <link rel=
"up" href=
"../weg.html" title=
"Worked Examples">
9 <link rel=
"prev" href=
"find_eg/find_mean_and_sd_eg.html" title=
"Find mean and standard deviation example">
10 <link rel=
"next" href=
"c_sharp.html" title=
"Using the Distributions from Within C#">
12 <body bgcolor=
"white" text=
"black" link=
"#0000FF" vlink=
"#840084" alink=
"#0000FF">
13 <table cellpadding=
"2" width=
"100%"><tr>
14 <td valign=
"top"><img alt=
"Boost C++ Libraries" width=
"277" height=
"86" src=
"../../../../../../../boost.png"></td>
15 <td align=
"center"><a href=
"../../../../../../../index.html">Home
</a></td>
16 <td align=
"center"><a href=
"../../../../../../../libs/libraries.htm">Libraries
</a></td>
17 <td align=
"center"><a href=
"http://www.boost.org/users/people.html">People
</a></td>
18 <td align=
"center"><a href=
"http://www.boost.org/users/faq.html">FAQ
</a></td>
19 <td align=
"center"><a href=
"../../../../../../../more/index.htm">More
</a></td>
22 <div class=
"spirit-nav">
23 <a accesskey=
"p" href=
"find_eg/find_mean_and_sd_eg.html"><img src=
"../../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../weg.html"><img src=
"../../../../../../../doc/src/images/up.png" alt=
"Up"></a><a accesskey=
"h" href=
"../../../index.html"><img src=
"../../../../../../../doc/src/images/home.png" alt=
"Home"></a><a accesskey=
"n" href=
"c_sharp.html"><img src=
"../../../../../../../doc/src/images/next.png" alt=
"Next"></a>
26 <div class=
"titlepage"><div><div><h4 class=
"title">
27 <a name=
"math_toolkit.stat_tut.weg.nag_library"></a><a class=
"link" href=
"nag_library.html" title=
"Comparison with C, R, FORTRAN-style Free Functions">Comparison with
28 C, R, FORTRAN-style Free Functions
</a>
29 </h4></div></div></div>
31 You are probably familiar with a statistics library that has free functions,
32 for example the classic
<a href=
"http://nag.com/numeric/CL/CLdescription.asp" target=
"_top">NAG
33 C library
</a> and matching
<a href=
"http://nag.com/numeric/FL/FLdescription.asp" target=
"_top">NAG
34 FORTRAN Library
</a>,
<a href=
"http://office.microsoft.com/en-us/excel/HP052090051033.aspx" target=
"_top">Microsoft
35 Excel BINOMDIST(number_s,trials,probability_s,cumulative)
</a>,
<a href=
"http://www.r-project.org/" target=
"_top">R
</a>,
<a href=
"http://www.ptc.com/products/mathcad/mathcad14/mathcad_func_chart.htm" target=
"_top">MathCAD
36 pbinom
</a> and many others.
39 If so, you may find 'Distributions as Objects' unfamiliar, if not alien.
42 However,
<span class=
"bold"><strong>do not panic
</strong></span>, both definition
43 and usage are not really very different.
46 A very simple example of generating the same values as the
<a href=
"http://nag.com/numeric/CL/CLdescription.asp" target=
"_top">NAG
47 C library
</a> for the binomial distribution follows. (If you find slightly
48 different values, the Boost C++ version, using double or better, is very
49 likely to be the more accurate. Of course, accuracy is not usually a concern
50 for most applications of this function).
53 The
<a href=
"http://www.nag.co.uk/numeric/cl/manual/pdf/G01/g01bjc.pdf" target=
"_top">NAG
54 function specification
</a> is
56 <pre class=
"programlisting"><span class=
"keyword">void
</span> <span class=
"identifier">nag_binomial_dist
</span><span class=
"special">(
</span><span class=
"identifier">Integer
</span> <span class=
"identifier">n
</span><span class=
"special">,
</span> <span class=
"keyword">double
</span> <span class=
"identifier">p
</span><span class=
"special">,
</span> <span class=
"identifier">Integer
</span> <span class=
"identifier">k
</span><span class=
"special">,
</span>
57 <span class=
"keyword">double
</span> <span class=
"special">*
</span><span class=
"identifier">plek
</span><span class=
"special">,
</span> <span class=
"keyword">double
</span> <span class=
"special">*
</span><span class=
"identifier">pgtk
</span><span class=
"special">,
</span> <span class=
"keyword">double
</span> <span class=
"special">*
</span><span class=
"identifier">peqk
</span><span class=
"special">,
</span> <span class=
"identifier">NagError
</span> <span class=
"special">*
</span><span class=
"identifier">fail
</span><span class=
"special">)
</span>
62 <pre class=
"programlisting"><span class=
"identifier">g01bjc
</span><span class=
"special">(
</span><span class=
"identifier">n
</span><span class=
"special">,
</span> <span class=
"identifier">p
</span><span class=
"special">,
</span> <span class=
"identifier">k
</span><span class=
"special">,
</span> <span class=
"special">&</span><span class=
"identifier">plek
</span><span class=
"special">,
</span> <span class=
"special">&</span><span class=
"identifier">pgtk
</span><span class=
"special">,
</span> <span class=
"special">&</span><span class=
"identifier">peqk
</span><span class=
"special">,
</span> <span class=
"identifier">NAGERR_DEFAULT
</span><span class=
"special">);
</span>
65 The equivalent using this Boost C++ library is:
67 <pre class=
"programlisting"><span class=
"keyword">using
</span> <span class=
"keyword">namespace
</span> <span class=
"identifier">boost
</span><span class=
"special">::
</span><span class=
"identifier">math
</span><span class=
"special">;
</span> <span class=
"comment">// Using declaration avoids very long names.
</span>
68 <span class=
"identifier">binomial
</span> <span class=
"identifier">my_dist
</span><span class=
"special">(
</span><span class=
"number">4</span><span class=
"special">,
</span> <span class=
"number">0.5</span><span class=
"special">);
</span> <span class=
"comment">// c.f. NAG n =
4, p =
0.5</span>
71 and values can be output thus:
73 <pre class=
"programlisting"><span class=
"identifier">cout
</span>
74 <span class=
"special"><<</span> <span class=
"identifier">my_dist
</span><span class=
"special">.
</span><span class=
"identifier">trials
</span><span class=
"special">()
</span> <span class=
"special"><<</span> <span class=
"string">" "</span> <span class=
"comment">// Echo the NAG input n =
4 trials.
</span>
75 <span class=
"special"><<</span> <span class=
"identifier">my_dist
</span><span class=
"special">.
</span><span class=
"identifier">success_fraction
</span><span class=
"special">()
</span> <span class=
"special"><<</span> <span class=
"string">" "</span> <span class=
"comment">// Echo the NAG input p =
0.5</span>
76 <span class=
"special"><<</span> <span class=
"identifier">cdf
</span><span class=
"special">(
</span><span class=
"identifier">my_dist
</span><span class=
"special">,
</span> <span class=
"number">2</span><span class=
"special">)
</span> <span class=
"special"><<</span> <span class=
"string">" "</span> <span class=
"comment">// NAG plek with k =
2</span>
77 <span class=
"special"><<</span> <span class=
"identifier">cdf
</span><span class=
"special">(
</span><span class=
"identifier">complement
</span><span class=
"special">(
</span><span class=
"identifier">my_dist
</span><span class=
"special">,
</span> <span class=
"number">2</span><span class=
"special">))
</span> <span class=
"special"><<</span> <span class=
"string">" "</span> <span class=
"comment">// NAG pgtk with k =
2</span>
78 <span class=
"special"><<</span> <span class=
"identifier">pdf
</span><span class=
"special">(
</span><span class=
"identifier">my_dist
</span><span class=
"special">,
</span> <span class=
"number">2</span><span class=
"special">)
</span> <span class=
"special"><<</span> <span class=
"identifier">endl
</span><span class=
"special">;
</span> <span class=
"comment">// NAG peqk with k =
2</span>
81 <code class=
"computeroutput"><span class=
"identifier">cdf
</span><span class=
"special">(
</span><span class=
"identifier">dist
</span><span class=
"special">,
</span> <span class=
"identifier">k
</span><span class=
"special">)
</span></code> is
82 equivalent to NAG library
<code class=
"computeroutput"><span class=
"identifier">plek
</span></code>,
83 lower tail probability of
<= k
86 <code class=
"computeroutput"><span class=
"identifier">cdf
</span><span class=
"special">(
</span><span class=
"identifier">complement
</span><span class=
"special">(
</span><span class=
"identifier">dist
</span><span class=
"special">,
</span> <span class=
"identifier">k
</span><span class=
"special">))
</span></code> is
87 equivalent to NAG library
<code class=
"computeroutput"><span class=
"identifier">pgtk
</span></code>,
88 upper tail probability of
> k
91 <code class=
"computeroutput"><span class=
"identifier">pdf
</span><span class=
"special">(
</span><span class=
"identifier">dist
</span><span class=
"special">,
</span> <span class=
"identifier">k
</span><span class=
"special">)
</span></code> is
92 equivalent to NAG library
<code class=
"computeroutput"><span class=
"identifier">peqk
</span></code>,
93 point probability of == k
96 See
<a href=
"../../../../../example/binomial_example_nag.cpp" target=
"_top">binomial_example_nag.cpp
</a>
100 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
101 <td align=
"left"></td>
102 <td align=
"right"><div class=
"copyright-footer">Copyright
© 2006-
2010,
2012-
2014 Nikhar Agrawal,
103 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
104 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R
åde, Gautam Sewani,
105 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang
<p>
106 Distributed under the Boost Software License, Version
1.0. (See accompanying
107 file LICENSE_1_0.txt or copy at
<a href=
"http://www.boost.org/LICENSE_1_0.txt" target=
"_top">http://www.boost.org/LICENSE_1_0.txt
</a>)
112 <div class=
"spirit-nav">
113 <a accesskey=
"p" href=
"find_eg/find_mean_and_sd_eg.html"><img src=
"../../../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../weg.html"><img src=
"../../../../../../../doc/src/images/up.png" alt=
"Up"></a><a accesskey=
"h" href=
"../../../index.html"><img src=
"../../../../../../../doc/src/images/home.png" alt=
"Home"></a><a accesskey=
"n" href=
"c_sharp.html"><img src=
"../../../../../../../doc/src/images/next.png" alt=
"Next"></a>