normal_misc_examples.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. // normal_misc_examples.cpp
  2. // Copyright Paul A. Bristow 2007, 2010.
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt
  6. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. // Example of using normal distribution.
  8. // Note that this file contains Quickbook mark-up as well as code
  9. // and comments, don't change any of the special comment mark-ups!
  10. //[normal_basic1
  11. /*`
  12. First we need some includes to access the normal distribution
  13. (and some std output of course).
  14. */
  15. #include <boost/math/distributions/normal.hpp> // for normal_distribution
  16. using boost::math::normal; // typedef provides default type is double.
  17. #include <iostream>
  18. using std::cout; using std::endl; using std::left; using std::showpoint; using std::noshowpoint;
  19. #include <iomanip>
  20. using std::setw; using std::setprecision;
  21. #include <limits>
  22. using std::numeric_limits;
  23. int main()
  24. {
  25. cout << "Example: Normal distribution, Miscellaneous Applications.";
  26. try
  27. {
  28. { // Traditional tables and values.
  29. /*`Let's start by printing some traditional tables.
  30. */
  31. double step = 1.; // in z
  32. double range = 4; // min and max z = -range to +range.
  33. int precision = 17; // traditional tables are only computed to much lower precision.
  34. // but std::numeric_limits<double>::max_digits10; on new Standard Libraries gives
  35. // 17, the maximum number of digits that can possibly be significant.
  36. // std::numeric_limits<double>::digits10; == 15 is number of guaranteed digits,
  37. // the other two digits being 'noisy'.
  38. // Construct a standard normal distribution s
  39. normal s; // (default mean = zero, and standard deviation = unity)
  40. cout << "Standard normal distribution, mean = "<< s.mean()
  41. << ", standard deviation = " << s.standard_deviation() << endl;
  42. /*` First the probability distribution function (pdf).
  43. */
  44. cout << "Probability distribution function values" << endl;
  45. cout << " z " " pdf " << endl;
  46. cout.precision(5);
  47. for (double z = -range; z < range + step; z += step)
  48. {
  49. cout << left << setprecision(3) << setw(6) << z << " "
  50. << setprecision(precision) << setw(12) << pdf(s, z) << endl;
  51. }
  52. cout.precision(6); // default
  53. /*`And the area under the normal curve from -[infin] up to z,
  54. the cumulative distribution function (cdf).
  55. */
  56. // For a standard normal distribution
  57. cout << "Standard normal mean = "<< s.mean()
  58. << ", standard deviation = " << s.standard_deviation() << endl;
  59. cout << "Integral (area under the curve) from - infinity up to z " << endl;
  60. cout << " z " " cdf " << endl;
  61. for (double z = -range; z < range + step; z += step)
  62. {
  63. cout << left << setprecision(3) << setw(6) << z << " "
  64. << setprecision(precision) << setw(12) << cdf(s, z) << endl;
  65. }
  66. cout.precision(6); // default
  67. /*`And all this you can do with a nanoscopic amount of work compared to
  68. the team of *human computers* toiling with Milton Abramovitz and Irene Stegen
  69. at the US National Bureau of Standards (now [@http://www.nist.gov NIST]).
  70. Starting in 1938, their "Handbook of Mathematical Functions with Formulas, Graphs and Mathematical Tables",
  71. was eventually published in 1964, and has been reprinted numerous times since.
  72. (A major replacement is planned at [@http://dlmf.nist.gov Digital Library of Mathematical Functions]).
  73. Pretty-printing a traditional 2-dimensional table is left as an exercise for the student,
  74. but why bother now that the Math Toolkit lets you write
  75. */
  76. double z = 2.;
  77. cout << "Area for z = " << z << " is " << cdf(s, z) << endl; // to get the area for z.
  78. /*`
  79. Correspondingly, we can obtain the traditional 'critical' values for significance levels.
  80. For the 95% confidence level, the significance level usually called alpha,
  81. is 0.05 = 1 - 0.95 (for a one-sided test), so we can write
  82. */
  83. cout << "95% of area has a z below " << quantile(s, 0.95) << endl;
  84. // 95% of area has a z below 1.64485
  85. /*`and a two-sided test (a comparison between two levels, rather than a one-sided test)
  86. */
  87. cout << "95% of area has a z between " << quantile(s, 0.975)
  88. << " and " << -quantile(s, 0.975) << endl;
  89. // 95% of area has a z between 1.95996 and -1.95996
  90. /*`
  91. First, define a table of significance levels: these are the probabilities
  92. that the true occurrence frequency lies outside the calculated interval.
  93. It is convenient to have an alpha level for the probability that z lies outside just one standard deviation.
  94. This will not be some nice neat number like 0.05, but we can easily calculate it,
  95. */
  96. double alpha1 = cdf(s, -1) * 2; // 0.3173105078629142
  97. cout << setprecision(17) << "Significance level for z == 1 is " << alpha1 << endl;
  98. /*`
  99. and place in our array of favorite alpha values.
  100. */
  101. double alpha[] = {0.3173105078629142, // z for 1 standard deviation.
  102. 0.20, 0.1, 0.05, 0.01, 0.001, 0.0001, 0.00001 };
  103. /*`
  104. Confidence value as % is (1 - alpha) * 100 (so alpha 0.05 == 95% confidence)
  105. that the true occurrence frequency lies *inside* the calculated interval.
  106. */
  107. cout << "level of significance (alpha)" << setprecision(4) << endl;
  108. cout << "2-sided 1 -sided z(alpha) " << endl;
  109. for (unsigned i = 0; i < sizeof(alpha)/sizeof(alpha[0]); ++i)
  110. {
  111. cout << setw(15) << alpha[i] << setw(15) << alpha[i] /2 << setw(10) << quantile(complement(s, alpha[i]/2)) << endl;
  112. // Use quantile(complement(s, alpha[i]/2)) to avoid potential loss of accuracy from quantile(s, 1 - alpha[i]/2)
  113. }
  114. cout << endl;
  115. /*`Notice the distinction between one-sided (also called one-tailed)
  116. where we are using a > *or* < test (and not both)
  117. and considering the area of the tail (integral) from z up to +[infin],
  118. and a two-sided test where we are using two > *and* < tests, and thus considering two tails,
  119. from -[infin] up to z low and z high up to +[infin].
  120. So the 2-sided values alpha[i] are calculated using alpha[i]/2.
  121. If we consider a simple example of alpha = 0.05, then for a two-sided test,
  122. the lower tail area from -[infin] up to -1.96 is 0.025 (alpha/2)
  123. and the upper tail area from +z up to +1.96 is also 0.025 (alpha/2),
  124. and the area between -1.96 up to 12.96 is alpha = 0.95.
  125. and the sum of the two tails is 0.025 + 0.025 = 0.05,
  126. */
  127. //] [/[normal_basic1]
  128. //[normal_basic2
  129. /*`Armed with the cumulative distribution function, we can easily calculate the
  130. easy to remember proportion of values that lie within 1, 2 and 3 standard deviations from the mean.
  131. */
  132. cout.precision(3);
  133. cout << showpoint << "cdf(s, s.standard_deviation()) = "
  134. << cdf(s, s.standard_deviation()) << endl; // from -infinity to 1 sd
  135. cout << "cdf(complement(s, s.standard_deviation())) = "
  136. << cdf(complement(s, s.standard_deviation())) << endl;
  137. cout << "Fraction 1 standard deviation within either side of mean is "
  138. << 1 - cdf(complement(s, s.standard_deviation())) * 2 << endl;
  139. cout << "Fraction 2 standard deviations within either side of mean is "
  140. << 1 - cdf(complement(s, 2 * s.standard_deviation())) * 2 << endl;
  141. cout << "Fraction 3 standard deviations within either side of mean is "
  142. << 1 - cdf(complement(s, 3 * s.standard_deviation())) * 2 << endl;
  143. /*`
  144. To a useful precision, the 1, 2 & 3 percentages are 68, 95 and 99.7,
  145. and these are worth memorising as useful 'rules of thumb', as, for example, in
  146. [@http://en.wikipedia.org/wiki/Standard_deviation standard deviation]:
  147. [pre
  148. Fraction 1 standard deviation within either side of mean is 0.683
  149. Fraction 2 standard deviations within either side of mean is 0.954
  150. Fraction 3 standard deviations within either side of mean is 0.997
  151. ]
  152. We could of course get some really accurate values for these
  153. [@http://en.wikipedia.org/wiki/Confidence_interval confidence intervals]
  154. by using cout.precision(15);
  155. [pre
  156. Fraction 1 standard deviation within either side of mean is 0.682689492137086
  157. Fraction 2 standard deviations within either side of mean is 0.954499736103642
  158. Fraction 3 standard deviations within either side of mean is 0.997300203936740
  159. ]
  160. But before you get too excited about this impressive precision,
  161. don't forget that the *confidence intervals of the standard deviation* are surprisingly wide,
  162. especially if you have estimated the standard deviation from only a few measurements.
  163. */
  164. //] [/[normal_basic2]
  165. //[normal_bulbs_example1
  166. /*`
  167. Examples from K. Krishnamoorthy, Handbook of Statistical Distributions with Applications,
  168. ISBN 1 58488 635 8, page 125... implemented using the Math Toolkit library.
  169. A few very simple examples are shown here:
  170. */
  171. // K. Krishnamoorthy, Handbook of Statistical Distributions with Applications,
  172. // ISBN 1 58488 635 8, page 125, example 10.3.5
  173. /*`Mean lifespan of 100 W bulbs is 1100 h with standard deviation of 100 h.
  174. Assuming, perhaps with little evidence and much faith, that the distribution is normal,
  175. we construct a normal distribution called /bulbs/ with these values:
  176. */
  177. double mean_life = 1100.;
  178. double life_standard_deviation = 100.;
  179. normal bulbs(mean_life, life_standard_deviation);
  180. double expected_life = 1000.;
  181. /*`The we can use the Cumulative distribution function to predict fractions
  182. (or percentages, if * 100) that will last various lifetimes.
  183. */
  184. cout << "Fraction of bulbs that will last at best (<=) " // P(X <= 1000)
  185. << expected_life << " is "<< cdf(bulbs, expected_life) << endl;
  186. cout << "Fraction of bulbs that will last at least (>) " // P(X > 1000)
  187. << expected_life << " is "<< cdf(complement(bulbs, expected_life)) << endl;
  188. double min_life = 900;
  189. double max_life = 1200;
  190. cout << "Fraction of bulbs that will last between "
  191. << min_life << " and " << max_life << " is "
  192. << cdf(bulbs, max_life) // P(X <= 1200)
  193. - cdf(bulbs, min_life) << endl; // P(X <= 900)
  194. /*`
  195. [note Real-life failures are often very ab-normal,
  196. with a significant number that 'dead-on-arrival' or suffer failure very early in their life:
  197. the lifetime of the survivors of 'early mortality' may be well described by the normal distribution.]
  198. */
  199. //] [/normal_bulbs_example1 Quickbook end]
  200. }
  201. {
  202. // K. Krishnamoorthy, Handbook of Statistical Distributions with Applications,
  203. // ISBN 1 58488 635 8, page 125, Example 10.3.6
  204. //[normal_bulbs_example3
  205. /*`Weekly demand for 5 lb sacks of onions at a store is normally distributed with mean 140 sacks and standard deviation 10.
  206. */
  207. double mean = 140.; // sacks per week.
  208. double standard_deviation = 10;
  209. normal sacks(mean, standard_deviation);
  210. double stock = 160.; // per week.
  211. cout << "Percentage of weeks overstocked "
  212. << cdf(sacks, stock) * 100. << endl; // P(X <=160)
  213. // Percentage of weeks overstocked 97.7
  214. /*`So there will be lots of mouldy onions!
  215. So we should be able to say what stock level will meet demand 95% of the weeks.
  216. */
  217. double stock_95 = quantile(sacks, 0.95);
  218. cout << "Store should stock " << int(stock_95) << " sacks to meet 95% of demands." << endl;
  219. /*`And it is easy to estimate how to meet 80% of demand, and waste even less.
  220. */
  221. double stock_80 = quantile(sacks, 0.80);
  222. cout << "Store should stock " << int(stock_80) << " sacks to meet 8 out of 10 demands." << endl;
  223. //] [/normal_bulbs_example3 Quickbook end]
  224. }
  225. { // K. Krishnamoorthy, Handbook of Statistical Distributions with Applications,
  226. // ISBN 1 58488 635 8, page 125, Example 10.3.7
  227. //[normal_bulbs_example4
  228. /*`A machine is set to pack 3 kg of ground beef per pack.
  229. Over a long period of time it is found that the average packed was 3 kg
  230. with a standard deviation of 0.1 kg.
  231. Assuming the packing is normally distributed,
  232. we can find the fraction (or %) of packages that weigh more than 3.1 kg.
  233. */
  234. double mean = 3.; // kg
  235. double standard_deviation = 0.1; // kg
  236. normal packs(mean, standard_deviation);
  237. double max_weight = 3.1; // kg
  238. cout << "Percentage of packs > " << max_weight << " is "
  239. << cdf(complement(packs, max_weight)) << endl; // P(X > 3.1)
  240. double under_weight = 2.9;
  241. cout <<"fraction of packs <= " << under_weight << " with a mean of " << mean
  242. << " is " << cdf(complement(packs, under_weight)) << endl;
  243. // fraction of packs <= 2.9 with a mean of 3 is 0.841345
  244. // This is 0.84 - more than the target 0.95
  245. // Want 95% to be over this weight, so what should we set the mean weight to be?
  246. // KK StatCalc says:
  247. double over_mean = 3.0664;
  248. normal xpacks(over_mean, standard_deviation);
  249. cout << "fraction of packs >= " << under_weight
  250. << " with a mean of " << xpacks.mean()
  251. << " is " << cdf(complement(xpacks, under_weight)) << endl;
  252. // fraction of packs >= 2.9 with a mean of 3.06449 is 0.950005
  253. double under_fraction = 0.05; // so 95% are above the minimum weight mean - sd = 2.9
  254. double low_limit = standard_deviation;
  255. double offset = mean - low_limit - quantile(packs, under_fraction);
  256. double nominal_mean = mean + offset;
  257. normal nominal_packs(nominal_mean, standard_deviation);
  258. cout << "Setting the packer to " << nominal_mean << " will mean that "
  259. << "fraction of packs >= " << under_weight
  260. << " is " << cdf(complement(nominal_packs, under_weight)) << endl;
  261. /*`
  262. Setting the packer to 3.06449 will mean that fraction of packs >= 2.9 is 0.95.
  263. Setting the packer to 3.13263 will mean that fraction of packs >= 2.9 is 0.99,
  264. but will more than double the mean loss from 0.0644 to 0.133.
  265. Alternatively, we could invest in a better (more precise) packer with a lower standard deviation.
  266. To estimate how much better (how much smaller standard deviation) it would have to be,
  267. we need to get the 5% quantile to be located at the under_weight limit, 2.9
  268. */
  269. double p = 0.05; // wanted p th quantile.
  270. cout << "Quantile of " << p << " = " << quantile(packs, p)
  271. << ", mean = " << packs.mean() << ", sd = " << packs.standard_deviation() << endl; //
  272. /*`
  273. Quantile of 0.05 = 2.83551, mean = 3, sd = 0.1
  274. With the current packer (mean = 3, sd = 0.1), the 5% quantile is at 2.8551 kg,
  275. a little below our target of 2.9 kg.
  276. So we know that the standard deviation is going to have to be smaller.
  277. Let's start by guessing that it (now 0.1) needs to be halved, to a standard deviation of 0.05
  278. */
  279. normal pack05(mean, 0.05);
  280. cout << "Quantile of " << p << " = " << quantile(pack05, p)
  281. << ", mean = " << pack05.mean() << ", sd = " << pack05.standard_deviation() << endl;
  282. cout <<"Fraction of packs >= " << under_weight << " with a mean of " << mean
  283. << " and standard deviation of " << pack05.standard_deviation()
  284. << " is " << cdf(complement(pack05, under_weight)) << endl;
  285. //
  286. /*`
  287. Fraction of packs >= 2.9 with a mean of 3 and standard deviation of 0.05 is 0.9772
  288. So 0.05 was quite a good guess, but we are a little over the 2.9 target,
  289. so the standard deviation could be a tiny bit more. So we could do some
  290. more guessing to get closer, say by increasing to 0.06
  291. */
  292. normal pack06(mean, 0.06);
  293. cout << "Quantile of " << p << " = " << quantile(pack06, p)
  294. << ", mean = " << pack06.mean() << ", sd = " << pack06.standard_deviation() << endl;
  295. cout <<"Fraction of packs >= " << under_weight << " with a mean of " << mean
  296. << " and standard deviation of " << pack06.standard_deviation()
  297. << " is " << cdf(complement(pack06, under_weight)) << endl;
  298. /*`
  299. Fraction of packs >= 2.9 with a mean of 3 and standard deviation of 0.06 is 0.9522
  300. Now we are getting really close, but to do the job properly,
  301. we could use root finding method, for example the tools provided, and used elsewhere,
  302. in the Math Toolkit, see __root_finding_without_derivatives.
  303. But in this normal distribution case, we could be even smarter and make a direct calculation.
  304. */
  305. normal s; // For standard normal distribution,
  306. double sd = 0.1;
  307. double x = 2.9; // Our required limit.
  308. // then probability p = N((x - mean) / sd)
  309. // So if we want to find the standard deviation that would be required to meet this limit,
  310. // so that the p th quantile is located at x,
  311. // in this case the 0.95 (95%) quantile at 2.9 kg pack weight, when the mean is 3 kg.
  312. double prob = pdf(s, (x - mean) / sd);
  313. double qp = quantile(s, 0.95);
  314. cout << "prob = " << prob << ", quantile(p) " << qp << endl; // p = 0.241971, quantile(p) 1.64485
  315. // Rearranging, we can directly calculate the required standard deviation:
  316. double sd95 = std::abs((x - mean)) / qp;
  317. cout << "If we want the "<< p << " th quantile to be located at "
  318. << x << ", would need a standard deviation of " << sd95 << endl;
  319. normal pack95(mean, sd95); // Distribution of the 'ideal better' packer.
  320. cout <<"Fraction of packs >= " << under_weight << " with a mean of " << mean
  321. << " and standard deviation of " << pack95.standard_deviation()
  322. << " is " << cdf(complement(pack95, under_weight)) << endl;
  323. // Fraction of packs >= 2.9 with a mean of 3 and standard deviation of 0.0608 is 0.95
  324. /*`Notice that these two deceptively simple questions
  325. (do we over-fill or measure better) are actually very common.
  326. The weight of beef might be replaced by a measurement of more or less anything.
  327. But the calculations rely on the accuracy of the standard deviation - something
  328. that is almost always less good than we might wish,
  329. especially if based on a few measurements.
  330. */
  331. //] [/normal_bulbs_example4 Quickbook end]
  332. }
  333. { // K. Krishnamoorthy, Handbook of Statistical Distributions with Applications,
  334. // ISBN 1 58488 635 8, page 125, example 10.3.8
  335. //[normal_bulbs_example5
  336. /*`A bolt is usable if between 3.9 and 4.1 long.
  337. From a large batch of bolts, a sample of 50 show a
  338. mean length of 3.95 with standard deviation 0.1.
  339. Assuming a normal distribution, what proportion is usable?
  340. The true sample mean is unknown,
  341. but we can use the sample mean and standard deviation to find approximate solutions.
  342. */
  343. normal bolts(3.95, 0.1);
  344. double top = 4.1;
  345. double bottom = 3.9;
  346. cout << "Fraction long enough [ P(X <= " << top << ") ] is " << cdf(bolts, top) << endl;
  347. cout << "Fraction too short [ P(X <= " << bottom << ") ] is " << cdf(bolts, bottom) << endl;
  348. cout << "Fraction OK -between " << bottom << " and " << top
  349. << "[ P(X <= " << top << ") - P(X<= " << bottom << " ) ] is "
  350. << cdf(bolts, top) - cdf(bolts, bottom) << endl;
  351. cout << "Fraction too long [ P(X > " << top << ") ] is "
  352. << cdf(complement(bolts, top)) << endl;
  353. cout << "95% of bolts are shorter than " << quantile(bolts, 0.95) << endl;
  354. //] [/normal_bulbs_example5 Quickbook end]
  355. }
  356. }
  357. catch(const std::exception& e)
  358. { // Always useful to include try & catch blocks because default policies
  359. // are to throw exceptions on arguments that cause errors like underflow, overflow.
  360. // Lacking try & catch blocks, the program will abort without a message below,
  361. // which may give some helpful clues as to the cause of the exception.
  362. std::cout <<
  363. "\n""Message from thrown exception was:\n " << e.what() << std::endl;
  364. }
  365. return 0;
  366. } // int main()
  367. /*
  368. Output is:
  369. Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\normal_misc_examples.exe"
  370. Example: Normal distribution, Miscellaneous Applications.Standard normal distribution, mean = 0, standard deviation = 1
  371. Probability distribution function values
  372. z pdf
  373. -4 0.00013383022576488537
  374. -3 0.0044318484119380075
  375. -2 0.053990966513188063
  376. -1 0.24197072451914337
  377. 0 0.3989422804014327
  378. 1 0.24197072451914337
  379. 2 0.053990966513188063
  380. 3 0.0044318484119380075
  381. 4 0.00013383022576488537
  382. Standard normal mean = 0, standard deviation = 1
  383. Integral (area under the curve) from - infinity up to z
  384. z cdf
  385. -4 3.1671241833119979e-005
  386. -3 0.0013498980316300959
  387. -2 0.022750131948179219
  388. -1 0.1586552539314571
  389. 0 0.5
  390. 1 0.84134474606854293
  391. 2 0.97724986805182079
  392. 3 0.9986501019683699
  393. 4 0.99996832875816688
  394. Area for z = 2 is 0.97725
  395. 95% of area has a z below 1.64485
  396. 95% of area has a z between 1.95996 and -1.95996
  397. Significance level for z == 1 is 0.3173105078629142
  398. level of significance (alpha)
  399. 2-sided 1 -sided z(alpha)
  400. 0.3173 0.1587 1
  401. 0.2 0.1 1.282
  402. 0.1 0.05 1.645
  403. 0.05 0.025 1.96
  404. 0.01 0.005 2.576
  405. 0.001 0.0005 3.291
  406. 0.0001 5e-005 3.891
  407. 1e-005 5e-006 4.417
  408. cdf(s, s.standard_deviation()) = 0.841
  409. cdf(complement(s, s.standard_deviation())) = 0.159
  410. Fraction 1 standard deviation within either side of mean is 0.683
  411. Fraction 2 standard deviations within either side of mean is 0.954
  412. Fraction 3 standard deviations within either side of mean is 0.997
  413. Fraction of bulbs that will last at best (<=) 1.00e+003 is 0.159
  414. Fraction of bulbs that will last at least (>) 1.00e+003 is 0.841
  415. Fraction of bulbs that will last between 900. and 1.20e+003 is 0.819
  416. Percentage of weeks overstocked 97.7
  417. Store should stock 156 sacks to meet 95% of demands.
  418. Store should stock 148 sacks to meet 8 out of 10 demands.
  419. Percentage of packs > 3.10 is 0.159
  420. fraction of packs <= 2.90 with a mean of 3.00 is 0.841
  421. fraction of packs >= 2.90 with a mean of 3.07 is 0.952
  422. Setting the packer to 3.06 will mean that fraction of packs >= 2.90 is 0.950
  423. Quantile of 0.0500 = 2.84, mean = 3.00, sd = 0.100
  424. Quantile of 0.0500 = 2.92, mean = 3.00, sd = 0.0500
  425. Fraction of packs >= 2.90 with a mean of 3.00 and standard deviation of 0.0500 is 0.977
  426. Quantile of 0.0500 = 2.90, mean = 3.00, sd = 0.0600
  427. Fraction of packs >= 2.90 with a mean of 3.00 and standard deviation of 0.0600 is 0.952
  428. prob = 0.242, quantile(p) 1.64
  429. If we want the 0.0500 th quantile to be located at 2.90, would need a standard deviation of 0.0608
  430. Fraction of packs >= 2.90 with a mean of 3.00 and standard deviation of 0.0608 is 0.950
  431. Fraction long enough [ P(X <= 4.10) ] is 0.933
  432. Fraction too short [ P(X <= 3.90) ] is 0.309
  433. Fraction OK -between 3.90 and 4.10[ P(X <= 4.10) - P(X<= 3.90 ) ] is 0.625
  434. Fraction too long [ P(X > 4.10) ] is 0.0668
  435. 95% of bolts are shorter than 4.11
  436. */