Date: 2012-05-15 22:20:12 (7 years 5 months ago) Michael Baudin 2 1 Added missing .ref files. Updated help pages.

File differences

macros/conint_bernoullip.sci
 16 16 17 17 18 18 19 19 20 20 21 21 22 22 ... ... 29 29 30 30 31 31 32 32 33 33 34 34 35 35 ... ... 70 70 71 71 72 72 73 73 74 74 75 75 76 76
 // n : a 1-by-1 matrix of doubles, integer value, positive, the number of trials␍␊ // level : a 1-by-1 matrix of doubles, the confidence level (default level = 1.-0.95=0.05). level is expected to be in the range [0.,0.5]␍␊ // twosided : a 1-by-1 matrix of booleans, the side of the interval (default twosided = %t). If twosided is true, then low and up is a two-sided interval [low,up]. If twosided is false, then the intervals are [-inf,up] and [low,inf].␍␊ // method : a 1-by-1 matrix of doubles, integer value, the method to estimate the C.I. Available values are method=1,2,3 (default method = 1). If method=1, then approximates the Binomial distribution with the Normal distribution. If method=2, then ␍␊ // method : a 1-by-1 matrix of doubles, integer value, the method to estimate the C.I. Available values are method=1,2,3 (default method = 1). See below for details.␍␊ // low : a 1-by-1 matrix of doubles, the estimated lower bound␍␊ // up : a 1-by-1 matrix of doubles, the estimated upper bound␍␊ //␍␊ // parameters p and ␍␊ // n.␍␊ // In other words, we consider that the random variable is a "success" with probability ␍␊ // p and is a failure with probability␍␊ // p and is a "failure" with probability␍␊ // 1-p.␍␊ // We assume that we have performed n trials ␍␊ // of this experiment.␍␊ //␍␊ // If method=2, then approximates the Binomial distribution with the Normal distribution. ␍␊ // Then computes exact roots of the quadratic equation.␍␊ // This is the Wilson (1927).␍␊ // This is the method by Wilson (1927).␍␊ //␍␊ // If method=3, then invert the quantiles of the ␍␊ // Binomial distribution with the Normal distribution. ␍␊
help/en_US/conint_bernoullipnumber.xml
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
 ␊ ␊ ␊ ␊ ␊ ␊ ␊ conint_bernoullipnumberNumber of experiments for a Bernoulli variable.␊ ␊ ␊ ␊ Calling Sequence␊ n = conint_bernoullipnumber ( len )␊ n = conint_bernoullipnumber ( len , level )␊ n = conint_bernoullipnumber ( len , level , pe )␊ ␊ ␊ ␊ Parameterslen : a 1-by-1 matrix of doubles, positive, the length of the required C.I.level : a 1-by-1 matrix of doubles, the confidence level (default level = 1.-0.95=0.05). level is expected to be in the range [0.,0.5]pe : a 1-by-1 matrix of doubles, an estimate of the probability of success (default pe = 0.5)n : a 1-by-1 matrix of doubles, the number of trials␊ ␊ Description␊ Returns the number of experiments which guarantees that the␊ length of the confidence interval for the␊ probability of success of a Bernoulli variable␊ is less than len.␊ ␊ In other words, if pe is the estimate of␊ the probability of success␊ with n trials, then␊ ␊ [low, up] = conint_bernoullip ( pe , n )␊ ␊ is so that␊ ␊ abs(up-low) <= len␊ ␊ To compute n, we assume that the random variable␊ has Binomial distribution.␊ ␊ This function makes the assumption that the data␊ in x has a binomial distribution with␊ parameters p and␊ n.␊ ␊ The default value pe=0.5␊ guarantees that the number of experiments is large enough,␊ no matter the actual value of the probability p.␊ In other words, if pe is not provided␊ be the user, the value of the output variable n␊ is guaranteed, but might be much too large than required.␊ ␊ ␊ Examples␊ ␊ AuthorsCopyright (C) 2011 - Michael Baudin␊ ␊ Bibliographyhttp://en.wikipedia.org/wiki/Confidence_interval"Introduction to probability and statistics for engineers and scientists", Sheldon Ross, Third Edition, 2004"Probabilités, Analyse de Données et Statistique", Gilbert Saporta, 2nd Ed., 2006␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ conint_bernoullipnumberNumber of experiments for a Bernoulli variable.␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Calling Sequence␍␊ ␍␊ n = conint_bernoullipnumber ( len )␍␊ n = conint_bernoullipnumber ( len , level )␍␊ n = conint_bernoullipnumber ( len , level , pe )␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Parameters␍␊ ␍␊ len :␍␊ a 1-by-1 matrix of doubles, positive, the length of the required C.I.␍␊ level :␍␊ a 1-by-1 matrix of doubles, the confidence level (default level = 1.-0.95=0.05). level is expected to be in the range [0.,0.5]␍␊ pe :␍␊ a 1-by-1 matrix of doubles, an estimate of the probability of success (default pe = 0.5)␍␊ n :␍␊ a 1-by-1 matrix of doubles, the number of trials␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Description␍␊ ␍␊ Returns the number of experiments which guarantees that the␍␊ length of the confidence interval for the␍␊ probability of success of a Bernoulli variable␍␊ is less than len.␍␊ ␍␊ ␍␊ In other words, if pe is the estimate of␍␊ the probability of success␍␊ with n trials, then␍␊ ␍␊ ␍␊ ␍␊ [low, up] = conint_bernoullip ( pe , n )␍␊ ␍␊ ␍␊ ␍␊ is so that␍␊ ␍␊ ␍␊ ␍␊ abs(up-low) <= len␍␊ ␍␊ ␍␊ ␍␊ To compute n, we assume that the random variable␍␊ has Binomial distribution.␍␊ ␍␊ ␍␊ This function makes the assumption that the data␍␊ in x has a binomial distribution with␍␊ parameters p and␍␊ n.␍␊ ␍␊ ␍␊ The default value pe=0.5␍␊ guarantees that the number of experiments is large enough,␍␊ no matter the actual value of the probability p.␍␊ In other words, if pe is not provided␍␊ be the user, the value of the output variable n␍␊ is guaranteed, but might be much too large than required.␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Examples␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Authors␍␊ ␍␊ Copyright (C) 2011 - Michael Baudin␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Bibliography␍␊ http://en.wikipedia.org/wiki/Confidence_interval␍␊ "Introduction to probability and statistics for engineers and scientists", Sheldon Ross, Third Edition, 2004␍␊ "Probabilités, Analyse de Données et Statistique", Gilbert Saporta, 2nd Ed., 2006␍␊ ␍␊ ␍␊
help/en_US/conint_bernoullip.xml
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
 ␊ ␊ ␊ ␊ ␊ ␊ ␊ conint_bernoullipC.I. of the probability of a Bernoulli variable.␊ ␊ ␊ ␊ Calling Sequence␊ [low, up] = conint_bernoullip ( pe , n )␊ [low, up] = conint_bernoullip ( pe , n , level )␊ [low, up] = conint_bernoullip ( pe , n , level , twosided )␊ ␊ ␊ ␊ Parameterspe : a 1-by-1 matrix of doubles, an estimate of the probabilityn : a 1-by-1 matrix of doubles, the number of trialslevel : a 1-by-1 matrix of doubles, the confidence level (default level = 1.-0.95=0.05). level is expected to be in the range [0.,0.5]twosided : a 1-by-1 matrix of booleans, the side of the interval (default twosided = %t). If twosided is true, then low and up is a two-sided interval [low,up]. If twosided is false, then the intervals are [-inf,up] and [low,inf].low : a 1-by-1 matrix of doubles, the estimated lower boundup : a 1-by-1 matrix of doubles, the estimated upper bound␊ ␊ Description␊ Computes a confidence interval of the probability␊ p of a Bernoulli variable.␊ This random variable is a "success" with probability␊ p and is a failure with probability␊ 1-p.␊ We assume that we have performed n trials␊ of this experiment and we assume that pe␊ is the fraction of the n trials which are successes.␊ This function computes confidence intervals for p.␊ ␊ If twosided is true, then␊ low and up are such that␊ the probability p satisfies the equality␊ ␊ P(low < p < up) = 1-level␊ ␊ If twosided is false, then␊ low and up are such that␊ the probability var(X) satisfies the equality␊ ␊ P(p < up) = 1-level␊ ␊ and␊ ␊ P(low < p) = 1-level␊ ␊ This function makes the assumption that the data␊ in x has a binomial distribution with␊ parameters p and␊ n.␊ ␊ The confidence interval that we compute is approximate.␊ It is based on the Central Limit Theorem.␊ We use a Normal distribution to compute the confidence interval.␊ ␊ ␊ Examples␊ ␊ AuthorsCopyright (C) 2011 - Michael Baudin␊ ␊ Bibliographyhttp://en.wikipedia.org/wiki/Confidence_interval"Introduction to probability and statistics for engineers and scientists", Sheldon Ross, Third Edition, 2004"Probabilités, Analyse de Données et Statistique", Gilbert Saporta, 2nd Ed., 2006␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ conint_bernoullipC.I. of the probability of a Bernoulli variable.␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Calling Sequence␍␊ ␍␊ [low, up] = conint_bernoullip ( pe , n )␍␊ [low, up] = conint_bernoullip ( pe , n , level )␍␊ [low, up] = conint_bernoullip ( pe , n , level , twosided )␍␊ [low, up] = conint_bernoullip ( pe , n , level , twosided , method )␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Parameters␍␊ ␍␊ pe :␍␊ a 1-by-1 matrix of doubles, an estimate of the probability␍␊ n :␍␊ a 1-by-1 matrix of doubles, integer value, positive, the number of trials␍␊ level :␍␊ a 1-by-1 matrix of doubles, the confidence level (default level = 1.-0.95=0.05). level is expected to be in the range [0.,0.5]␍␊ twosided :␍␊ a 1-by-1 matrix of booleans, the side of the interval (default twosided = %t). If twosided is true, then low and up is a two-sided interval [low,up]. If twosided is false, then the intervals are [-inf,up] and [low,inf].␍␊ method :␍␊ a 1-by-1 matrix of doubles, integer value, the method to estimate the C.I. Available values are method=1,2,3 (default method = 1). If method=1, then approximates the Binomial distribution with the Normal distribution. If method=2, then␍␊ low :␍␊ a 1-by-1 matrix of doubles, the estimated lower bound␍␊ up :␍␊ a 1-by-1 matrix of doubles, the estimated upper bound␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Description␍␊ ␍␊ Computes a confidence interval of the probability␍␊ p of a Bernoulli variable.␍␊ ␍␊ ␍␊ This function makes the assumption that the data␍␊ in x has a binomial distribution with␍␊ parameters p and␍␊ n.␍␊ In other words, we consider that the random variable is a "success" with probability␍␊ p and is a "failure" with probability␍␊ 1-p.␍␊ We assume that we have performed n trials␍␊ of this experiment.␍␊ We assume that pe␍␊ is the fraction of the n trials which are successes.␍␊ This function computes confidence intervals for p.␍␊ ␍␊ ␍␊ If twosided is true, then␍␊ low and up are such that␍␊ the probability p satisfies the equality␍␊ ␍␊ ␍␊ ␍␊ P(low < p < up) = 1-level␍␊ ␍␊ ␍␊ ␍␊ If twosided is false, then␍␊ low and up are such that␍␊ the probability p satisfies the equality␍␊ ␍␊ ␍␊ ␍␊ P(p < up) = 1-level␍␊ ␍␊ ␍␊ ␍␊ and␍␊ ␍␊ ␍␊ ␍␊ P(low < p) = 1-level␍␊ ␍␊ ␍␊ ␍␊ The confidence interval that we compute is approximate.␍␊ It is based on the Central Limit Theorem.␍␊ We use a Normal distribution to compute the confidence interval.␍␊ ␍␊ ␍␊ If method=1, then approximates the Binomial distribution␍␊ with the Normal distribution.␍␊ Then computes approximate roots of the quadratic equation.␍␊ This is the "Textbook" formula.␍␊ ␍␊ ␍␊ If method=2, then approximates the Binomial distribution with the Normal distribution.␍␊ Then computes exact roots of the quadratic equation.␍␊ This is the Wilson (1927).␍␊ ␍␊ ␍␊ If method=3, then invert the quantiles of the␍␊ Binomial distribution with the Normal distribution.␍␊ This is the Clopper-Pearson interval.␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Examples␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Authors␍␊ ␍␊ Copyright (C) 2011 - Michael Baudin␍␊ ␍␊ ␍␊ ␍␊ ␍␊ Bibliography␍␊ http://en.wikipedia.org/wiki/Confidence_interval␍␊ "Introduction to probability and statistics for engineers and scientists", Sheldon Ross, Third Edition, 2004␍␊ "Probabilités, Analyse de Données et Statistique", Gilbert Saporta, 2nd Ed., 2006␍␊ http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval␍␊ ␍␊ ␍␊
 5 5 6 6 7 7 8 9 8 10 9 11 10 12 ... ... 12 14 13 15 14 16 15 16 17 18 19 20 21 22 23 24 25 26 27 17 18 19 20 21 28 22 29 30 31 32 33 34 35 36 37 38 39 40 23 41 24 42 25 ... ... 52 35 53 36 54 37 55 38 56 39 57 40 58 41 ... ... 68 51 69 52 70 53 71 72 73 74 75 76 77 78 54 55 56 57 58 59
 ␊ The goal of this toolbox is to provide functions to ␊ compute confidence intervals for statistical estimators.␊ These confidence intervals are computed based on various ␊ probability distribution functions.␊ ␊ The toolbox is based on macros.␊ ␊ --------␊ ␊ The following is a list of the current accsum functions :␊ * accsum_dcs : A Doubly Self Compensated Sum algorithm␊ * accsum_scs : A Self Compensated Sum algorithm␊ * accsum_compsum : The compensated sum of a matrix.␊ * accsum_dblcompsum : The doubly compensated sum of a matrix.␊ * accsum_fasttwosum : The fast2sum sum of a and b.␊ * accsum_orderdynamic : Returns the sum with a dynamic re-ordering.␊ * accsum_straight : The straightforward sum of a matrix.␊ * accsum_twosum : The twosum sum of a and b.␊ * accsum_fcompsum : The compensated sum of a matrix.␊ * accsum_fdcs : A Doubly Self Compensated Sum algorithm␊ * accsum_fscs : A Self Compensated Sum algorithm␊ ␊ and support functions:␊ ␊ * accsum_getpath : Returns the path to the current module.␊ * accsum_order : Re-order the matrix.␊ * accsum_priestx : A difficult example for SCS by Priest.␊ * accsum_shuffle : Randomly shuffles the input.␊ * accsum_sumcond : Condition number of the sum function.␊ * accsum_wilkinson : A test vector by Wilkinson.␊ * accsum_higham : Returns an example designed by Higham.␊ ␊ The accsum_fcompsum, accsum_fdcs and accsum_fscs functions ␊ are based on compiled source code and are faster than the other.␊ ␊ Dependencies␊ ----␊ ␊ Forge␊ -----␊ ␊ http://forge.scilab.org/index.php/p/accsum/␊ http://forge.scilab.org/index.php/p/conint/␊ ␊ ATOMS␊ -----␊ ␊ Bibliography␊ ------------␊ * "Stability and numerical accuracy of algorithms", Nicolas Higham␊ * "Handbook of Floating Point Computations", Muller et al␊ * https://hpcrd.lbl.gov/SCG/ocean/NRS/ECMWF/img14.htm␊ * https://hpcrd.lbl.gov/SCG/ocean/NRS/SCSsum.F␊ * "On properties of floating point arithmetics: numerical stability and the cost of accurate computations", Douglas Priest, 1992␊ * "Using Accurate Arithmetics to Improve Numerical Reproducibility and Stability in Parallel Applications". Yun He and Chris H.Q. Ding. Journal of Supercomputing, Vol.18, Issue 3, 259-277, March 2001. Also Proceedings of International Conference on Supercomputing (ICS'00), May 2000, 225-234.␊ ␊ ␊ * http://en.wikipedia.org/wiki/Confidence_interval␊ * "Introduction to probability and statistics for engineers and scientists", ␊ Sheldon Ross, Third Edition, 2004␊ * "Probability and Statistics for Engineers and Scientists", ␊ Ronald Walpole, Raymond Myers, Sharon Myers, Keying Ye, Eight Edition, 2006␊
tests/unit_tests/bernoullip.dia.ref
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
 // Copyright (C) 2011 - Michael Baudin␍␊ //␍␊ // This file must be used under the terms of the GNU LGPL license.␍␊ // From Sheldon Ross, Example 7.5a, p.262␍␊ // We experimented with 100 transistors :␍␊ // 80 transistors works.␍␊ // Compute a 95% confidence interval for p, ␍␊ // the probability that a transistor works.␍␊ pe = 80./100.;␍␊ n = 100;␍␊ [low, up] = conint_bernoullip ( pe , n , 1.-0.95 );␍␊ assert_checkalmostequal(low,0.7216014,1.e-5);␍␊ assert_checkalmostequal(up,0.8783986,1.e-5);␍␊ // Then (0.7216,0.8774) is a 95% C.I. for p.␍␊ // From Gilbert Saporta␍␊ // Section 13.5.4 Intervalle de confiance ␍␊ // pour une proportion p␍␊ n = 400;␍␊ pe = 0.36;␍␊ [low, up] = conint_bernoullip ( pe , n , 1.-0.95 );␍␊ assert_checkalmostequal(low,0.3129609,1.e-5);␍␊ assert_checkalmostequal(up,0.4070391,1.e-5);␍␊ // Then (0.31,0.41) is a 95% C.I. for p.␍␊ // Check default value of level␍␊ n = 400;␍␊ pe = 0.36;␍␊ [low, up] = conint_bernoullip ( pe , n );␍␊ assert_checkalmostequal(low,0.3129609,1.e-5);␍␊ assert_checkalmostequal(up,0.4070391,1.e-5);␍␊ // Try various methods␍␊ // From Statistics: problems and solutions␍␊ // Edward Eryl Bassett,J. M. Bremner,B. J. T. Morgan␍␊ // "4C Binomial and Poisson distributions"␍␊ // "4C3 Women investors in building societies"␍␊ // p.148␍␊ pe = 22./80.;␍␊ n = 80;␍␊ level = 1.-0.90;␍␊ twosided = %t;␍␊ [low, up] = conint_bernoullip ( pe , n , level , twosided );␍␊ // Then (0.193,0.357) is a 90% C.I. for p.␍␊ assert_checkalmostequal(low,0.1928859,1.e-5);␍␊ assert_checkalmostequal(up,0.3571141,1.e-5);␍␊ // The quadratic or Wilson (1927) interval :␍␊ method = 2;␍␊ [low, up] = conint_bernoullip ( pe , n , level , twosided , method );␍␊ assert_checkalmostequal(low,0.2012659,1.e-5);␍␊ assert_checkalmostequal(up,0.3634549,1.e-5);␍␊ // Then (0.201,0.363) is an approximate 90% C.I. for p.␍␊ // Invert the Binomial: the Clopper-Pearson interval␍␊ method = 3;␍␊ [low, up] = conint_bernoullip ( pe , n , level , twosided , method );␍␊ assert_checkalmostequal(low,0.1884600,1.e-5);␍␊ assert_checkalmostequal(up,0.3522612,1.e-5);␍␊ // Then (0.188,0.352) is an approximate 90% C.I. for p.␍␊
tests/unit_tests/normmu.dia.ref
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
 // Copyright (C) 2011 - Michael Baudin␍␊ //␍␊ // This file must be used under the terms of the GNU LGPL license.␍␊ // Sheldon Ross, Example 7.3a, page 241␍␊ x = [5, 8.5, 12, 15, 7, 9, 7.5, 6.5, 10.5];␍␊ n = size(x,"*");␍␊ me = mean(x);␍␊ v = 4.;␍␊ [ low, up ] = conint_normmu ( n , me, v);␍␊ assert_checkalmostequal(me,9.,1.e-5);␍␊ assert_checkalmostequal(low,7.6933573,1.e-5);␍␊ assert_checkalmostequal(up,10.306643,1.e-5);␍␊ // Then P(7.69 <= mu <= 10.31) = 0.95␍␊ //␍␊ // Get one-sided intervals, Example 7.3b, p. 242␍␊ twosided = %f;␍␊ [ low, up ] = conint_normmu ( n , me, v, 1-0.95 , twosided );␍␊ assert_checkalmostequal(me,9.,1.e-5);␍␊ assert_checkalmostequal(low,7.9034309,1.e-5);␍␊ assert_checkalmostequal(up,10.096569,1.e-5);␍␊ // Then : P(7.903 <= mu) = 0.95 ␍␊ // P(mu <= 10.097) = 0.95 ␍␊ // Example 7.3c, p. 244␍␊ // Two-sided 99% interval, expected = (7.28, 10.72)␍␊ [ low, up ] = conint_normmu ( n , me, v, 1.-0.99 );␍␊ assert_checkalmostequal(me,9.,1.e-5);␍␊ assert_checkalmostequal(low,7.2827805,1.e-5);␍␊ assert_checkalmostequal(up,10.71722,1.e-5);␍␊ // One-sided 99% intervals are (7.447,inf), (−inf, 10.553)␍␊ [ low, up ] = conint_normmu ( n , me, v, 1.-0.99 , %f );␍␊ assert_checkalmostequal(me,9.,1.e-5);␍␊ assert_checkalmostequal(low,7.4491014,1.e-5);␍␊ assert_checkalmostequal(up,10.550899,1.e-5);␍␊ // EXAMPLE 7.3e, p. 247␍␊ // The variance is unknown: use Student's T random variable␍␊ v = variance(x);␍␊ [ low, up ] = conint_normmu ( n , me, v, 1.-0.95 , [] , %f );␍␊ assert_checkalmostequal(me,9.,1.e-5);␍␊ assert_checkalmostequal(low,6.630806,1.e-5);␍␊ assert_checkalmostequal(up,11.369194,1.e-5);␍␊ // Then P(6.63<= mu <= 11.37) = 0.95␍␊ // EXAMPLE 7.3f, p.249␍␊ x = [54, 63, 58, 72, 49, 92, 70, 73, ..␍␊ 69, 104, 48, 66, 80, 64, 77];␍␊ n = size(x,"*");␍␊ me = mean(x);␍␊ v = variance(x);␍␊ // Two-sided :␍␊ [ low, up ] = conint_normmu ( n , me, v, 1.-0.95 , [] , %f );␍␊ assert_checkalmostequal(me,69.266667,1.e-5);␍␊ assert_checkalmostequal(low,60.866937,1.e-5);␍␊ assert_checkalmostequal(up,77.666397,1.e-5);␍␊ // Then P(60.865<= mu <=77.6683) = 0.95␍␊ // One-sided :␍␊ [ low, up ] = conint_normmu ( n , me, v, 1.-0.95 , %f , %f );␍␊ assert_checkalmostequal(me,69.266667,1.e-5);␍␊ assert_checkalmostequal(low,62.368764,1.e-5);␍␊ assert_checkalmostequal(up,76.164569,1.e-5);␍␊ // Then : P (mu <= 76.16) = 0.95␍␊ // Then : P (62.368 <= mu) = 0.95␍␊ // EXAMPLE 7.3g, Monte-Carlo simulation␍␊ grand("setsd",0);␍␊ U = grand(100,1,"def");␍␊ x = sqrt(1-U.^2);␍␊ n = size(x,"*");␍␊ me = mean(x);␍␊ v = variance(x);␍␊ [ low, up ] = conint_normmu ( n , me, v, 1.-0.95 , [] , %f );␍␊ // Exact integral is : ␍␊ assert_checkalmostequal(me,%pi/4,1.e-1);␍␊ assert_checktrue(me>low);␍␊ assert_checktrue(me
tests/unit_tests/bernoullipnumber.dia.ref
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
 // Copyright (C) 2011 - Michael Baudin␍␊ //␍␊ // This file must be used under the terms of the GNU LGPL license.␍␊ // From Gilbert Saporta, ␍␊ // Section 13.5.4 Intervalle de confiance ␍␊ // pour une proportion p␍␊ // p.313␍␊ len = 0.05*2;␍␊ level = 1.-0.90;␍␊ n = conint_bernoullipnumber ( len , level );␍␊ assert_checkequal(n,271);␍␊ // Reproduce the table p 313.␍␊ mprintf("level = %9s %9s %9s %9s", ..␍␊ " ", "1.-0.90", "1.-0.95", "1.-0.98")␍␊ level = 1.-0.90 1.-0.95 1.-0.98for len = 2*[0.01 0.02 0.05]␍␊ mprintf("len = %9s, n = ", string(len))␍␊ for level = 1.-[0.90 0.95 0.98]␍␊ n = conint_bernoullipnumber ( len , level );␍␊ mprintf("%9s ", string(n));␍␊ end␍␊ mprintf("\n");␍␊ end␍␊ len = 0.02, n = 6764 9604 13530 ␍␊ len = 0.04, n = 1691 2401 3383 ␍␊ len = 0.1, n = 271 385 542 ␍␊ // From Sheldon Ross,␍␊ // Example 7.5c␍␊ len = 0.05;␍␊ // Compute n for 95% C.I.␍␊ n = conint_bernoullipnumber ( len );␍␊ assert_checkequal(n,1537);␍␊ // Compute n for 99% C.I.␍␊ level = 1.-0.99;␍␊ n = conint_bernoullipnumber ( len , level );␍␊ assert_checkequal(n,2654);␍␊ // Compute n for 99% C.I. and probability estimate␍␊ pe = 26. / 30.;␍␊ n = conint_bernoullipnumber ( len , level , pe );␍␊ assert_checkequal(n,1227);␍␊
tests/unit_tests/normvar.dia.ref
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
 // Copyright (C) 2011 - Michael Baudin␍␊ //␍␊ // This file must be used under the terms of the GNU LGPL license.␍␊ // Sheldon Ross, Example 7.3h, page 252␍␊ // Compute a 90% confidence interval for the ␍␊ // variance of a normal variable.␍␊ x = [0.123 0.124 0.126 0.120 0.130 ...␍␊ 0.133 0.125 0.128 0.124 0.126];␍␊ n = size(x,"*");␍␊ v = variance(x);␍␊ [ low, up ] = conint_normvar ( n , v , 1.-0.90 );␍␊ assert_checkalmostequal(v,1.36555556D-05,1.e-5);␍␊ assert_checkalmostequal(low,7.26403231D-06,1.e-5);␍␊ assert_checkalmostequal(up,3.69611516D-05,1.e-5);␍␊ // Then P(7.26403231D-06 <= var(X) <= 36.9611516D-06) = 0.90␍␊ // Example from Gilbert Saporta, ␍␊ // Section 13.5.3, "Variance d'une loi normale"␍␊ // Section 13.5.3.2, "m est inconnu"␍␊ x = [6;2;2;8;12;6;6;13;..␍␊ 8;2;10;0;7;5;4;4;3;..␍␊ ␉7;4;9;6;2;-3;5;7;2;4;5;2;2];␍␊ n = size(x,"*");␍␊ v = variance(x);␍␊ [ low, up ] = conint_normvar ( n , v , 1.-0.90 )␍␊ up =␍␊ ␍␊ 19.651728 ␍␊ low =␍␊ ␍␊ 8.1772743 ␍␊ assert_checkalmostequal(v,12.,1.e-5);␍␊ assert_checkalmostequal(low,8.1772743,1.e-5);␍␊ assert_checkalmostequal(up,19.651728,1.e-5);␍␊ // Check default value of level␍␊ x = [0.123 0.124 0.126 0.120 0.130 ...␍␊ 0.133 0.125 0.128 0.124 0.126];␍␊ n = size(x,"*");␍␊ v = variance(x);␍␊ [ low, up ] = conint_normvar ( n , v );␍␊ assert_checkalmostequal(v,1.36555556D-05,1.e-5);␍␊ assert_checkalmostequal(low,6.46067919D-06,1.e-5);␍␊ assert_checkalmostequal(up,4.55119530D-05,1.e-5);␍␊
tests/unit_tests/normmunumber.dia.ref
 1 2 3 4 5 6 7 8 9
 // Copyright (C) 2011 - Michael Baudin␍␊ //␍␊ // This file must be used under the terms of the GNU LGPL license.␍␊ // Sheldon Ross, Example 7.3a, page 241␍␊ n = conint_normmunumber ( 0.2 , 0.3^2 , 1.-0.95 );␍␊ assert_checkalmostequal(n,35);␍␊ // Check default value of level␍␊ n = conint_normmunumber ( 0.2 , 0.3^2 );␍␊ assert_checkalmostequal(n,35);␍␊

Revision: 2