Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80723 - trunk/libs/math/doc/sf_and_dist/distributions
From: pbristow_at_[hidden]
Date: 2012-09-27 12:19:09


Author: pbristow
Date: 2012-09-27 12:19:08 EDT (Thu, 27 Sep 2012)
New Revision: 80723
URL: http://svn.boost.org/trac/boost/changeset/80723

Log:
Added trac #7402 resolution
Text files modified:
   trunk/libs/math/doc/sf_and_dist/distributions/students_t_examples.qbk | 158 ++++++++++++++++++++--------------------
   1 files changed, 79 insertions(+), 79 deletions(-)

Modified: trunk/libs/math/doc/sf_and_dist/distributions/students_t_examples.qbk
==============================================================================
--- trunk/libs/math/doc/sf_and_dist/distributions/students_t_examples.qbk (original)
+++ trunk/libs/math/doc/sf_and_dist/distributions/students_t_examples.qbk 2012-09-27 12:19:08 EDT (Thu, 27 Sep 2012)
@@ -5,18 +5,18 @@
 
 Let's say you have a sample mean, you may wish to know what confidence intervals
 you can place on that mean. Colloquially: "I want an interval that I can be
-P% sure contains the true mean". (On a technical point, note that
-the interval either contains the true mean or it does not: the
-meaning of the confidence level is subtly
-different from this colloquialism. More background information can be found on the
+P% sure contains the true mean". (On a technical point, note that
+the interval either contains the true mean or it does not: the
+meaning of the confidence level is subtly
+different from this colloquialism. More background information can be found on the
 [@http://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm NIST site]).
 
 The formula for the interval can be expressed as:
 
 [equation dist_tutorial4]
 
-Where, ['Y[sub s]] is the sample mean, /s/ is the sample standard deviation,
-/N/ is the sample size, /[alpha]/ is the desired significance level and
+Where, ['Y[sub s]] is the sample mean, /s/ is the sample standard deviation,
+/N/ is the sample size, /[alpha]/ is the desired significance level and
 ['t[sub ([alpha]/2,N-1)]] is the upper critical value of the Students-t
 distribution with /N-1/ degrees of freedom.
 
@@ -27,8 +27,8 @@
 
 The confidence level of the test is defined as 1 - [alpha], and often expressed
 as a percentage. So for example a significance level of 0.05, is equivalent
-to a 95% confidence level. Refer to
-[@http://www.itl.nist.gov/div898/handbook/prc/section1/prc14.htm
+to a 95% confidence level. Refer to
+[@http://www.itl.nist.gov/div898/handbook/prc/section1/prc14.htm
 "What are confidence intervals?"] in __handbook for more information.
 ] [/ Note]
 
@@ -49,7 +49,7 @@
 The following example code is taken from the example program
 [@../../../example/students_t_single_sample.cpp students_t_single_sample.cpp].
 
-We'll begin by defining a procedure to calculate intervals for
+We'll begin by defining a procedure to calculate intervals for
 various confidence levels; the procedure will print these out
 as a table:
 
@@ -59,7 +59,7 @@
    #include <iomanip>
    // Bring everything into global namespace for ease of use:
    using namespace boost::math;
- using namespace std;
+ using namespace std;
 
    void confidence_limits_on_mean(
       double Sm, // Sm = Sample Mean.
@@ -70,7 +70,7 @@
       using namespace boost::math;
 
       // Print out general info:
- cout <<
+ cout <<
          "__________________________________\n"
          "2-Sided Confidence Limits For Mean\n"
          "__________________________________\n\n";
@@ -82,7 +82,7 @@
 We'll define a table of significance/risk levels for which we'll compute intervals:
 
       double alpha[] = { 0.5, 0.25, 0.1, 0.05, 0.01, 0.001, 0.0001, 0.00001 };
-
+
 Note that these are the complements of the confidence/probability levels: 0.5, 0.75, 0.9 .. 0.99999).
 
 Next we'll declare the distribution object we'll need, note that
@@ -97,11 +97,11 @@
 we have to wrap the arguments in a call to /complement(...)/:
 
    double T = quantile(complement(dist, alpha[i] / 2));
-
+
 Note that alpha was divided by two, since we'll be calculating
 both the upper and lower bounds: had we been interested in a single
 sided interval then we would have omitted this step.
-
+
 Now to complete the picture, we'll get the (one-sided) width of the
 interval from the t-statistic
 by multiplying by the standard deviation, and dividing by the square
@@ -115,12 +115,12 @@
 
 Let's take a look at some sample output, first using the
 [@http://www.itl.nist.gov/div898/handbook/eda/section4/eda428.htm
-Heat flow data] from the NIST site. The data set was collected
-by Bob Zarr of NIST in January, 1990 from a heat flow meter
+Heat flow data] from the NIST site. The data set was collected
+by Bob Zarr of NIST in January, 1990 from a heat flow meter
 calibration and stability analysis.
 The corresponding dataplot
-output for this test can be found in
-[@http://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm
+output for this test can be found in
+[@http://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm
 section 3.5.2] of the __handbook.
 
 [pre'''
@@ -146,7 +146,7 @@
        99.990 3.973 6.484e-003 9.25498 9.26794
        99.999 4.537 7.404e-003 9.25406 9.26886
 ''']
-
+
 As you can see the large sample size (195) and small standard deviation (0.023)
 have combined to give very small intervals, indeed we can be
 very confident that the true mean is 9.2.
@@ -155,7 +155,7 @@
 ['P.K.Hou, O. W. Lau & M.C. Wong, Analyst (1983) vol. 108, p 64.
 and from Statistics for Analytical Chemistry, 3rd ed. (1994), pp 54-55
 J. C. Miller and J. N. Miller, Ellis Horwood ISBN 0 13 0309907.]
-The values result from the determination of mercury by cold-vapour
+The values result from the determination of mercury by cold-vapour
 atomic absorption.
 
 [pre'''
@@ -190,12 +190,12 @@
 
 [section:tut_mean_test Testing a sample mean for difference from a "true" mean]
 
-When calibrating or comparing a scientific instrument or measurement method of some kind,
+When calibrating or comparing a scientific instrument or measurement method of some kind,
 we want to be answer the question "Does an observed sample mean differ from the
 "true" mean in any significant way?". If it does, then we have evidence of
 a systematic difference. This question can be answered with a Students-t test:
-more information can be found
-[@http://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm
+more information can be found
+[@http://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm
 on the NIST site].
 
 Of course, the assignment of "true" to one mean may be quite arbitrary,
@@ -213,7 +213,7 @@
 (often of the null-hypothesis) implying, wrongly, that there really *IS* no difference,
 but statisticans eschew this to avoid implying that there is positive evidence of 'no difference'.
 'Not-rejected' here means there is *no evidence* of difference, but there still might well be a difference.
-For example, see [@http://en.wikipedia.org/wiki/Argument_from_ignorance argument from ignorance] and
+For example, see [@http://en.wikipedia.org/wiki/Argument_from_ignorance argument from ignorance] and
 [@http://www.bmj.com/cgi/content/full/311/7003/485 Absence of evidence does not constitute evidence of absence.]
 ] [/ note]
 
@@ -224,7 +224,7 @@
    #include <iomanip>
    // Bring everything into global namespace for ease of use:
    using namespace boost::math;
- using namespace std;
+ using namespace std;
 
    void single_sample_t_test(double M, double Sm, double Sd, unsigned Sn, double alpha)
    {
@@ -234,7 +234,7 @@
       // Sd = Sample Standard Deviation.
       // Sn = Sample Size.
       // alpha = Significance Level.
-
+
 Most of the procedure is pretty-printing, so let's just focus on the
 calculation, we begin by calculating the t-statistic:
 
@@ -245,7 +245,7 @@
    // t-statistic:
    double t_stat = diff * sqrt(double(Sn)) / Sd;
 
-Finally calculate the probability from the t-statistic. If we're interested
+Finally calculate the probability from the t-statistic. If we're interested
 in simply whether there is a difference (either less or greater) or not,
 we don't care about the sign of the t-statistic,
 and we take the complement of the probability for comparison
@@ -253,33 +253,33 @@
 
    students_t dist(v);
    double q = cdf(complement(dist, fabs(t_stat)));
-
+
 The procedure then prints out the results of the various tests
-that can be done, these
+that can be done, these
 can be summarised in the following table:
 
 [table
 [[Hypothesis][Test]]
 [[The Null-hypothesis: there is
-*no difference* in means]
+*no difference* in means]
 [Reject if complement of CDF for |t| < significance level / 2:
 
 `cdf(complement(dist, fabs(t))) < alpha / 2`]]
 
 [[The Alternative-hypothesis: there
-*is difference* in means]
+*is difference* in means]
 [Reject if complement of CDF for |t| > significance level / 2:
 
 `cdf(complement(dist, fabs(t))) > alpha / 2`]]
 
 [[The Alternative-hypothesis: the sample mean *is less* than
-the true mean.]
+the true mean.]
 [Reject if CDF of t > significance level:
 
 `cdf(dist, t) > alpha`]]
 
 [[The Alternative-hypothesis: the sample mean *is greater* than
-the true mean.]
+the true mean.]
 [Reject if complement of CDF of t > significance level:
 
 `cdf(complement(dist, t)) > alpha`]]
@@ -289,14 +289,14 @@
 Notice that the comparisons are against `alpha / 2` for a two-sided test
 and against `alpha` for a one-sided test]
 
-Now that we have all the parts in place, let's take a look at some
+Now that we have all the parts in place, let's take a look at some
 sample output, first using the
 [@http://www.itl.nist.gov/div898/handbook/eda/section4/eda428.htm
-Heat flow data] from the NIST site. The data set was collected
-by Bob Zarr of NIST in January, 1990 from a heat flow meter
+Heat flow data] from the NIST site. The data set was collected
+by Bob Zarr of NIST in January, 1990 from a heat flow meter
 calibration and stability analysis. The corresponding dataplot
-output for this test can be found in
-[@http://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm
+output for this test can be found in
+[@http://www.itl.nist.gov/div898/handbook/eda/section3/eda352.htm
 section 3.5.2] of the __handbook.
 
 [pre'''
@@ -334,7 +334,7 @@
 ['P.K.Hou, O. W. Lau & M.C. Wong, Analyst (1983) vol. 108, p 64.
 and from Statistics for Analytical Chemistry, 3rd ed. (1994), pp 54-55
 J. C. Miller and J. N. Miller, Ellis Horwood ISBN 0 13 0309907.]
-The values result from the determination of mercury by cold-vapour
+The values result from the determination of mercury by cold-vapour
 atomic absorption.
 
 [pre'''
@@ -363,8 +363,8 @@
 As you can see the small number of measurements (3) has led to a large uncertainty
 in the location of the true mean. So even though there appears to be a difference
 between the sample mean and the expected true mean, we conclude that there
-is no significant difference, and are unable to reject the null hypothesis.
-However, if we were to lower the bar for acceptance down to alpha = 0.1
+is no significant difference, and are unable to reject the null hypothesis.
+However, if we were to lower the bar for acceptance down to alpha = 0.1
 (a 90% confidence level) we see a different output:
 
 [pre'''
@@ -406,7 +406,7 @@
 The parameter estimators of the students_t_distribution class
 can provide this information.
 
-This section is based on the example code in
+This section is based on the example code in
 [@../../../example/students_t_single_sample.cpp students_t_single_sample.cpp]
 and we begin by defining a procedure that will print out a table of
 estimated sample sizes for various confidence levels:
@@ -417,7 +417,7 @@
    #include <iomanip>
    // Bring everything into global namespace for ease of use:
    using namespace boost::math;
- using namespace std;
+ using namespace std;
 
    void single_sample_find_df(
       double M, // M = true mean.
@@ -447,13 +447,13 @@
 
 The first argument is the difference between the means that you
 wish to be able to detect, here it's the absolute value of the
-difference between the sample mean, and the true mean.
+difference between the sample mean, and the true mean.
 
 Then come two probability values: alpha and beta. Alpha is the
 maximum acceptable risk of rejecting the null-hypothesis when it is
 in fact true. Beta is the maximum acceptable risk of failing to reject
 the null-hypothesis when in fact it is false.
-Also note that for a two-sided test, alpha must be divided by 2.
+Also note that for a two-sided test, alpha must be divided by 2.
 
 The final parameter of the function is the standard deviation of the sample.
 
@@ -487,8 +487,8 @@
 ['P.K.Hou, O. W. Lau & M.C. Wong, Analyst (1983) vol. 108, p 64.
 and from Statistics for Analytical Chemistry, 3rd ed. (1994), pp 54-55
 J. C. Miller and J. N. Miller, Ellis Horwood ISBN 0 13 0309907.]
-The values result from the determination of mercury by cold-vapour
-atomic absorption.
+The values result from the determination of mercury by cold-vapour
+atomic absorption.
 
 Only three measurements were made, and the Students-t test above
 gave a borderline result, so this example
@@ -518,7 +518,7 @@
     99.999 66 68
 ''']
 
-So in this case, many more measurements would have had to be made,
+So in this case, many more measurements would have had to be made,
 for example at the 95% level, 14 measurements in total for a two-sided test.
 
 [endsect]
@@ -528,20 +528,20 @@
 their means are different or not. This situation often arises when
 determining whether a new process or treatment is better than an old one.
 
-In this example, we'll be using the
+In this example, we'll be using the
 [@http://www.itl.nist.gov/div898/handbook/eda/section3/eda3531.htm
-Car Mileage sample data] from the
+Car Mileage sample data] from the
 [@http://www.itl.nist.gov NIST website]. The data compares
 miles per gallon of US cars with miles per gallon of Japanese cars.
 
-The sample code is in
+The sample code is in
 [@../../../example/students_t_two_samples.cpp students_t_two_samples.cpp].
 
 There are two ways in which this test can be conducted: we can assume
 that the true standard deviations of the two samples are equal or not.
 If the standard deviations are assumed to be equal, then the calculation
 of the t-statistic is greatly simplified, so we'll examine that case first.
-In real life we should verify whether this assumption is valid with a
+In real life we should verify whether this assumption is valid with a
 Chi-Squared test for equal variances.
 
 We begin by defining a procedure that will conduct our test assuming equal
@@ -564,14 +564,14 @@
            unsigned Sn2, // Sn2 = Sample 2 Size.
            double alpha) // alpha = Significance Level.
    {
-
+
 
 Our procedure will begin by calculating the t-statistic, assuming
 equal variances the needed formulae are:
 
 [equation dist_tutorial1]
 
-where Sp is the "pooled" standard deviation of the two samples,
+where Sp is the "pooled" standard deviation of the two samples,
 and /v/ is the number of degrees of freedom of the two combined
 samples. We can now write the code to calculate the t-statistic:
 
@@ -580,17 +580,17 @@
    cout << setw(55) << left << "Degrees of Freedom" << "= " << v << "\n";
    // Pooled variance:
    double sp = sqrt(((Sn1-1) * Sd1 * Sd1 + (Sn2-1) * Sd2 * Sd2) / v);
- cout << setw(55) << left << "Pooled Standard Deviation" << "= " << v << "\n";
+ cout << setw(55) << left << "Pooled Standard Deviation" << "= " << sp << "\n";
    // t-statistic:
    double t_stat = (Sm1 - Sm2) / (sp * sqrt(1.0 / Sn1 + 1.0 / Sn2));
    cout << setw(55) << left << "T Statistic" << "= " << t_stat << "\n";
-
+
 The next step is to define our distribution object, and calculate the
 complement of the probability:
 
    students_t dist(v);
    double q = cdf(complement(dist, fabs(t_stat)));
- cout << setw(55) << left << "Probability that difference is due to chance" << "= "
+ cout << setw(55) << left << "Probability that difference is due to chance" << "= "
       << setprecision(3) << scientific << 2 * q << "\n\n";
 
 Here we've used the absolute value of the t-statistic, because we initially
@@ -602,25 +602,25 @@
 [table
 [[Hypothesis][Test]]
 [[The Null-hypothesis: there is
-*no difference* in means]
+*no difference* in means]
 [Reject if complement of CDF for |t| < significance level / 2:
 
 `cdf(complement(dist, fabs(t))) < alpha / 2`]]
 
 [[The Alternative-hypothesis: there is a
-*difference* in means]
+*difference* in means]
 [Reject if complement of CDF for |t| > significance level / 2:
 
 `cdf(complement(dist, fabs(t))) < alpha / 2`]]
 
 [[The Alternative-hypothesis: Sample 1 Mean is *less* than
-Sample 2 Mean.]
+Sample 2 Mean.]
 [Reject if CDF of t > significance level:
 
 `cdf(dist, t) > alpha`]]
 
 [[The Alternative-hypothesis: Sample 1 Mean is *greater* than
-Sample 2 Mean.]
+Sample 2 Mean.]
 
 [Reject if complement of CDF of t > significance level:
 
@@ -633,7 +633,7 @@
 Most of the rest of the sample program is pretty-printing, so we'll
 skip over that, and take a look at the sample output for alpha=0.05
 (a 95% probability level). For comparison the dataplot output
-for the same data is in
+for the same data is in
 [@http://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm
 section 1.3.5.3] of the __handbook.
 
@@ -643,14 +643,14 @@
    ________________________________________________
 
    Number of Observations (Sample 1) = 249
- Sample 1 Mean = 20.14458
- Sample 1 Standard Deviation = 6.41470
+ Sample 1 Mean = 20.145
+ Sample 1 Standard Deviation = 6.4147
    Number of Observations (Sample 2) = 79
- Sample 2 Mean = 30.48101
- Sample 2 Standard Deviation = 6.10771
- Degrees of Freedom = 326.00000
- Pooled Standard Deviation = 326.00000
- T Statistic = -12.62059
+ Sample 2 Mean = 30.481
+ Sample 2 Standard Deviation = 6.1077
+ Degrees of Freedom = 326
+ Pooled Standard Deviation = 6.3426
+ T Statistic = -12.621
    Probability that difference is due to chance = 5.273e-030
 
    Results for Alternative Hypothesis and alpha = 0.0500'''
@@ -666,8 +666,8 @@
 
 The tests on the alternative hypothesis show that we must
 also reject the hypothesis that Sample 1 Mean is
-greater than that for Sample 2: in this case Sample 1 represents the
-miles per gallon for Japanese cars, and Sample 2 the miles per gallon for
+greater than that for Sample 2: in this case Sample 1 represents the
+miles per gallon for Japanese cars, and Sample 2 the miles per gallon for
 US cars, so we conclude that Japanese cars are on average more
 fuel efficient.
 
@@ -677,7 +677,7 @@
 
 [equation dist_tutorial2]
 
-And for the combined degrees of freedom we use the
+And for the combined degrees of freedom we use the
 [@http://en.wikipedia.org/wiki/Welch-Satterthwaite_equation Welch-Satterthwaite]
 approximation:
 
@@ -691,7 +691,7 @@
 Some statistical packages truncate the effective degrees of freedom to
 an integer value: this may be necessary if you are relying on lookup tables,
 but since our code fully supports non-integer degrees of freedom there is no
-need to truncate in this case. Also note that when the degrees of freedom
+need to truncate in this case. Also note that when the degrees of freedom
 is small then the Welch-Satterthwaite approximation may be a significant
 source of error.]
 
@@ -753,14 +753,14 @@
 the change, because each patient will have a different baseline reading.
 Instead we calculate the difference between before and after measurements
 in each patient, and calculate the mean and standard deviation of the differences.
-To test whether a significant change has taken place, we can then test
-the null-hypothesis that the true mean is zero using the same procedure
+To test whether a significant change has taken place, we can then test
+the null-hypothesis that the true mean is zero using the same procedure
 we used in the single sample cases previously discussed.
 
 That means we can:
 
-* [link math_toolkit.dist.stat_tut.weg.st_eg.tut_mean_intervals Calculate confidence intervals of the mean].
-If the endpoints of the interval differ in sign then we are unable to reject
+* [link math_toolkit.dist.stat_tut.weg.st_eg.tut_mean_intervals Calculate confidence intervals of the mean].
+If the endpoints of the interval differ in sign then we are unable to reject
 the null-hypothesis that there is no change.
 * [link math_toolkit.dist.stat_tut.weg.st_eg.tut_mean_test Test whether the true mean is zero]. If the
 result is consistent with a true mean of zero, then we are unable to reject the
@@ -772,8 +772,8 @@
 
 [endsect][/section:st_eg Student's t]
 
-[/
- Copyright 2006 John Maddock and Paul A. Bristow.
+[/
+ Copyright 2006, 2012 John Maddock and Paul A. Bristow.
   Distributed under the Boost Software License, Version 1.0.
   (See accompanying file LICENSE_1_0.txt or copy at
   http://www.boost.org/LICENSE_1_0.txt).


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk