]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/f_test.cpp
1 // Copyright John Maddock 2006
2 // Copyright Paul A. Bristow 2007, 2008, 2010
4 // Use, modification and distribution are subject to the
5 // Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt
7 // or copy at http://www.boost.org/LICENSE_1_0.txt)
10 # pragma warning(disable: 4512) // assignment operator could not be generated.
11 # pragma warning(disable: 4510) // default constructor could not be generated.
12 # pragma warning(disable: 4610) // can never be instantiated - user defined constructor required.
13 # pragma warning(disable: 4180) // qualifier has no effect (in Fusion).
17 using std::cout
; using std::endl
;
18 using std::left
; using std::fixed
; using std::right
; using std::scientific
;
21 using std::setprecision
;
23 #include <boost/math/distributions/fisher_f.hpp>
26 double sd1
, // Sample 1 std deviation
27 double sd2
, // Sample 2 std deviation
28 double N1
, // Sample 1 size
29 double N2
, // Sample 2 size
30 double alpha
) // Significance level
33 // An F test applied to two sets of data.
34 // We are testing the null hypothesis that the
35 // standard deviation of the samples is equal, and
36 // that any variation is down to chance. We can
37 // also test the alternative hypothesis that any
38 // difference is not down to chance.
39 // See http://www.itl.nist.gov/div898/handbook/eda/section3/eda359.htm
41 // Avoid "using namespace boost::math;" because of potential name ambiguity.
42 using boost::math::fisher_f
;
46 "____________________________________\n"
47 "F test for equal standard deviations\n"
48 "____________________________________\n\n";
49 cout
<< setprecision(5);
50 cout
<< "Sample 1:\n";
51 cout
<< setw(55) << left
<< "Number of Observations" << "= " << N1
<< "\n";
52 cout
<< setw(55) << left
<< "Sample Standard Deviation" << "= " << sd1
<< "\n\n";
53 cout
<< "Sample 2:\n";
54 cout
<< setw(55) << left
<< "Number of Observations" << "= " << N2
<< "\n";
55 cout
<< setw(55) << left
<< "Sample Standard Deviation" << "= " << sd2
<< "\n\n";
57 // Now we can calculate and output some stats:
60 double F
= (sd1
/ sd2
);
62 cout
<< setw(55) << left
<< "Test Statistic" << "= " << F
<< "\n\n";
64 // Finally define our distribution, and get the probability:
66 fisher_f
dist(N1
- 1, N2
- 1);
67 double p
= cdf(dist
, F
);
68 cout
<< setw(55) << left
<< "CDF of test statistic: " << "= "
69 << setprecision(3) << scientific
<< p
<< "\n";
70 double ucv
= quantile(complement(dist
, alpha
));
71 double ucv2
= quantile(complement(dist
, alpha
/ 2));
72 double lcv
= quantile(dist
, alpha
);
73 double lcv2
= quantile(dist
, alpha
/ 2);
74 cout
<< setw(55) << left
<< "Upper Critical Value at alpha: " << "= "
75 << setprecision(3) << scientific
<< ucv
<< "\n";
76 cout
<< setw(55) << left
<< "Upper Critical Value at alpha/2: " << "= "
77 << setprecision(3) << scientific
<< ucv2
<< "\n";
78 cout
<< setw(55) << left
<< "Lower Critical Value at alpha: " << "= "
79 << setprecision(3) << scientific
<< lcv
<< "\n";
80 cout
<< setw(55) << left
<< "Lower Critical Value at alpha/2: " << "= "
81 << setprecision(3) << scientific
<< lcv2
<< "\n\n";
83 // Finally print out results of null and alternative hypothesis:
85 cout
<< setw(55) << left
<<
86 "Results for Alternative Hypothesis and alpha" << "= "
87 << setprecision(4) << fixed
<< alpha
<< "\n\n";
88 cout
<< "Alternative Hypothesis Conclusion\n";
89 cout
<< "Standard deviations are unequal (two sided test) ";
90 if((ucv2
< F
) || (lcv2
> F
))
91 cout
<< "NOT REJECTED\n";
94 cout
<< "Standard deviation 1 is less than standard deviation 2 ";
96 cout
<< "NOT REJECTED\n";
99 cout
<< "Standard deviation 1 is greater than standard deviation 2 ";
101 cout
<< "NOT REJECTED\n";
103 cout
<< "REJECTED\n";
104 cout
<< endl
<< endl
;
110 // Run tests for ceramic strength data:
111 // see http://www.itl.nist.gov/div898/handbook/eda/section4/eda42a1.htm
112 // The data for this case study were collected by Said Jahanmir of the
113 // NIST Ceramics Division in 1996 in connection with a NIST/industry
114 // ceramics consortium for strength optimization of ceramic strength.
116 f_test(65.54909, 61.85425, 240, 240, 0.05);
118 // And again for the process change comparison:
119 // see http://www.itl.nist.gov/div898/handbook/prc/section3/prc32.htm
120 // A new procedure to assemble a device is introduced and tested for
121 // possible improvement in time of assembly. The question being addressed
122 // is whether the standard deviation of the new assembly process (sample 2) is
123 // better (i.e., smaller) than the standard deviation for the old assembly
124 // process (sample 1).
126 f_test(4.9082, 2.5874, 11, 9, 0.05);
135 F-test_example1.vcxproj -> J:\Cpp\MathToolkit\test\Math_test\Debug\F_test_example1.exe
136 ____________________________________
137 F test for equal standard deviations
138 ____________________________________
141 Number of Observations = 240
142 Sample Standard Deviation = 65.549
145 Number of Observations = 240
146 Sample Standard Deviation = 61.854
148 Test Statistic = 1.123
150 CDF of test statistic: = 8.148e-001
151 Upper Critical Value at alpha: = 1.238e+000
152 Upper Critical Value at alpha/2: = 1.289e+000
153 Lower Critical Value at alpha: = 8.080e-001
154 Lower Critical Value at alpha/2: = 7.756e-001
156 Results for Alternative Hypothesis and alpha = 0.0500
158 Alternative Hypothesis Conclusion
159 Standard deviations are unequal (two sided test) REJECTED
160 Standard deviation 1 is less than standard deviation 2 REJECTED
161 Standard deviation 1 is greater than standard deviation 2 REJECTED
164 ____________________________________
165 F test for equal standard deviations
166 ____________________________________
169 Number of Observations = 11.00000
170 Sample Standard Deviation = 4.90820
173 Number of Observations = 9.00000
174 Sample Standard Deviation = 2.58740
176 Test Statistic = 3.59847
178 CDF of test statistic: = 9.589e-001
179 Upper Critical Value at alpha: = 3.347e+000
180 Upper Critical Value at alpha/2: = 4.295e+000
181 Lower Critical Value at alpha: = 3.256e-001
182 Lower Critical Value at alpha/2: = 2.594e-001
184 Results for Alternative Hypothesis and alpha = 0.0500
186 Alternative Hypothesis Conclusion
187 Standard deviations are unequal (two sided test) REJECTED
188 Standard deviation 1 is less than standard deviation 2 REJECTED
189 Standard deviation 1 is greater than standard deviation 2 NOT REJECTED
192 ____________________________________
193 F test for equal standard deviations
194 ____________________________________
197 Number of Observations = 240
198 Sample Standard Deviation = 65.549
201 Number of Observations = 240
202 Sample Standard Deviation = 61.854
204 Test Statistic = 1.123
206 CDF of test statistic: = 8.148e-001
207 Upper Critical Value at alpha: = 1.238e+000
208 Upper Critical Value at alpha/2: = 1.289e+000
209 Lower Critical Value at alpha: = 8.080e-001
210 Lower Critical Value at alpha/2: = 7.756e-001
212 Results for Alternative Hypothesis and alpha = 0.0500
214 Alternative Hypothesis Conclusion
215 Standard deviations are unequal (two sided test) REJECTED
216 Standard deviation 1 is less than standard deviation 2 REJECTED
217 Standard deviation 1 is greater than standard deviation 2 REJECTED
220 ____________________________________
221 F test for equal standard deviations
222 ____________________________________
225 Number of Observations = 11.00000
226 Sample Standard Deviation = 4.90820
229 Number of Observations = 9.00000
230 Sample Standard Deviation = 2.58740
232 Test Statistic = 3.59847
234 CDF of test statistic: = 9.589e-001
235 Upper Critical Value at alpha: = 3.347e+000
236 Upper Critical Value at alpha/2: = 4.295e+000
237 Lower Critical Value at alpha: = 3.256e-001
238 Lower Critical Value at alpha/2: = 2.594e-001
240 Results for Alternative Hypothesis and alpha = 0.0500
242 Alternative Hypothesis Conclusion
243 Standard deviations are unequal (two sided test) REJECTED
244 Standard deviation 1 is less than standard deviation 2 REJECTED
245 Standard deviation 1 is greater than standard deviation 2 NOT REJECTED