Conint

Conint Commit Details

Date:2012-05-15 22:20:12 (7 years 5 months ago)
Author:Michael Baudin
Commit:2
Parents: 1
Message:Added missing .ref files. Updated help pages.
Changes:
A/tests/unit_tests/bernoullipnumber.dia.ref
A/tests/unit_tests/normvar.dia.ref
A/tests/unit_tests/normmunumber.dia.ref
A/tests/unit_tests/bernoullip.dia.ref
A/tests/unit_tests/normmu.dia.ref
M/readme.txt
M/help/en_US/conint_bernoullipnumber.xml
M/help/en_US/conint_bernoullip.xml
M/macros/conint_bernoullip.sci

File differences

macros/conint_bernoullip.sci
1616
1717
1818
19
19
2020
2121
2222
......
2929
3030
3131
32
32
3333
3434
3535
......
7070
7171
7272
73
73
7474
7575
7676
// 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 <literal>p</literal> and
// <literal>n</literal>.
// In other words, we consider that the random variable is a "success" with probability
// <literal>p</literal> and is a failure with probability
// <literal>p</literal> and is a "failure" with probability
// <literal>1-p</literal>.
// We assume that we have performed <literal>n</literal> 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
<?xml version="1.0" encoding="UTF-8"?>
<!--
*
* This help file was generated from conint_bernoullipnumber.sci using help_from_sci().
*
-->
<refentry version="5.0-subset Scilab" xml:id="conint_bernoullipnumber" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:ns3="http://www.w3.org/1999/xhtml"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:db="http://docbook.org/ns/docbook">
<refnamediv>
<refname>conint_bernoullipnumber</refname><refpurpose>Number of experiments for a Bernoulli variable.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Calling Sequence</title>
<synopsis>
n = conint_bernoullipnumber ( len )
n = conint_bernoullipnumber ( len , level )
n = conint_bernoullipnumber ( len , level , pe )
</synopsis>
</refsynopsisdiv>
<refsection>
<title>Parameters</title>
<variablelist>
<varlistentry><term>len :</term>
<listitem><para> a 1-by-1 matrix of doubles, positive, the length of the required C.I.</para></listitem></varlistentry>
<varlistentry><term>level :</term>
<listitem><para> 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]</para></listitem></varlistentry>
<varlistentry><term>pe :</term>
<listitem><para> a 1-by-1 matrix of doubles, an estimate of the probability of success (default pe = 0.5)</para></listitem></varlistentry>
<varlistentry><term>n :</term>
<listitem><para> a 1-by-1 matrix of doubles, the number of trials</para></listitem></varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Description</title>
<para>
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 <literal>len</literal>.
</para>
<para>
In other words, if <literal>pe</literal> is the estimate of
the probability of success
with <literal>n</literal> trials, then
</para>
<para>
<screen>
[low, up] = conint_bernoullip ( pe , n )
</screen>
</para>
<para>
is so that
</para>
<para>
<literal>
abs(up-low) &lt;= len
</literal>
</para>
<para>
To compute <literal>n</literal>, we assume that the random variable
has Binomial distribution.
</para>
<para>
This function makes the assumption that the data
in <literal>x</literal> has a binomial distribution with
parameters <literal>p</literal> and
<literal>n</literal>.
</para>
<para>
The default value <literal>pe=0.5</literal>
guarantees that the number of experiments is large enough,
no matter the actual value of the probability <literal>p</literal>.
In other words, if <literal>pe</literal> is not provided
be the user, the value of the output variable <literal>n</literal>
is guaranteed, but might be much too large than required.
</para>
<para>
</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting role="example"><![CDATA[
// 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 )
// Therefore, it requires 271 experiments
// to make sure that the 90% C.I. for p
// has a length no greater than 0.1.
// Reproduce the table p 313.
mprintf("level = %9s %9s %9s %9s", ..
" ", "1.-0.90", "1.-0.95", "1.-0.98")
for 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
// From Sheldon Ross,
// Example 7.5c
// Estimate the failure rate of computer chips.
len = 0.05
// Compute n for 95% C.I.
n = conint_bernoullipnumber ( len )
// Compute n for 99% C.I.
level = 1.-0.99
n = conint_bernoullipnumber ( len , level )
// Compute n for 99% C.I. and probability estimate
// From 30 sample computer chips, there are
// 26. chips which works.
pe = 26. / 30.
n = conint_bernoullipnumber ( len , level , pe )
// It may require 1227 experiments to get a
// 99 C.I. with length less than 0.05.
]]></programlisting>
</refsection>
<refsection>
<title>Authors</title>
<simplelist type="vert">
<member>Copyright (C) 2011 - Michael Baudin</member>
</simplelist>
</refsection>
<refsection>
<title>Bibliography</title>
<para>http://en.wikipedia.org/wiki/Confidence_interval</para>
<para>"Introduction to probability and statistics for engineers and scientists", Sheldon Ross, Third Edition, 2004</para>
<para>"Probabilités, Analyse de Données et Statistique", Gilbert Saporta, 2nd Ed., 2006</para>
</refsection>
</refentry>
<?xml version="1.0" encoding="UTF-8"?>
<!--
*
* This help file was generated from conint_bernoullipnumber.sci using help_from_sci().
*
-->
<refentry version="5.0-subset Scilab" xml:id="conint_bernoullipnumber" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:ns3="http://www.w3.org/1999/xhtml"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:db="http://docbook.org/ns/docbook">
<refnamediv>
<refname>conint_bernoullipnumber</refname><refpurpose>Number of experiments for a Bernoulli variable.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Calling Sequence</title>
<synopsis>
n = conint_bernoullipnumber ( len )
n = conint_bernoullipnumber ( len , level )
n = conint_bernoullipnumber ( len , level , pe )
</synopsis>
</refsynopsisdiv>
<refsection>
<title>Parameters</title>
<variablelist>
<varlistentry><term>len :</term>
<listitem><para> a 1-by-1 matrix of doubles, positive, the length of the required C.I.</para></listitem></varlistentry>
<varlistentry><term>level :</term>
<listitem><para> 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]</para></listitem></varlistentry>
<varlistentry><term>pe :</term>
<listitem><para> a 1-by-1 matrix of doubles, an estimate of the probability of success (default pe = 0.5)</para></listitem></varlistentry>
<varlistentry><term>n :</term>
<listitem><para> a 1-by-1 matrix of doubles, the number of trials</para></listitem></varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Description</title>
<para>
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 <literal>len</literal>.
</para>
<para>
In other words, if <literal>pe</literal> is the estimate of
the probability of success
with <literal>n</literal> trials, then
</para>
<para>
<screen>
[low, up] = conint_bernoullip ( pe , n )
</screen>
</para>
<para>
is so that
</para>
<para>
<literal>
abs(up-low) &lt;= len
</literal>
</para>
<para>
To compute <literal>n</literal>, we assume that the random variable
has Binomial distribution.
</para>
<para>
This function makes the assumption that the data
in <literal>x</literal> has a binomial distribution with
parameters <literal>p</literal> and
<literal>n</literal>.
</para>
<para>
The default value <literal>pe=0.5</literal>
guarantees that the number of experiments is large enough,
no matter the actual value of the probability <literal>p</literal>.
In other words, if <literal>pe</literal> is not provided
be the user, the value of the output variable <literal>n</literal>
is guaranteed, but might be much too large than required.
</para>
<para>
</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting role="example"><![CDATA[
// 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 )
// Therefore, it requires 271 experiments
// to make sure that the 90% C.I. for p
// has a length no greater than 0.1.
// Reproduce the table p 313.
mprintf("level = %9s %9s %9s %9s", ..
" ", "1.-0.90", "1.-0.95", "1.-0.98")
for 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
// From Sheldon Ross,
// Example 7.5c
// Estimate the failure rate of computer chips.
len = 0.05
// Compute n for 95% C.I.
n = conint_bernoullipnumber ( len )
// Compute n for 99% C.I.
level = 1.-0.99
n = conint_bernoullipnumber ( len , level )
// Compute n for 99% C.I. and probability estimate
// From 30 sample computer chips, there are
// 26. chips which works.
pe = 26. / 30.
n = conint_bernoullipnumber ( len , level , pe )
// It may require 1227 experiments to get a
// 99 C.I. with length less than 0.05.
// How many experiments to estimate accurately a
// small probability with 95% C.I. ?
level = 1.-0.95;
for pe = logspace(-1,-7,7)
len = pe/10.;
n = conint_bernoullipnumber ( len , level , pe );
mprintf("pe = %-9s, len = %-9s, n = %-9s\n", ..
string(pe), string(len), string(n))
end
]]></programlisting>
</refsection>
<refsection>
<title>Authors</title>
<simplelist type="vert">
<member>Copyright (C) 2011 - Michael Baudin</member>
</simplelist>
</refsection>
<refsection>
<title>Bibliography</title>
<para>http://en.wikipedia.org/wiki/Confidence_interval</para>
<para>"Introduction to probability and statistics for engineers and scientists", Sheldon Ross, Third Edition, 2004</para>
<para>"Probabilités, Analyse de Données et Statistique", Gilbert Saporta, 2nd Ed., 2006</para>
</refsection>
</refentry>
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
<?xml version="1.0" encoding="UTF-8"?>
<!--
*
* This help file was generated from conint_bernoullip.sci using help_from_sci().
*
-->
<refentry version="5.0-subset Scilab" xml:id="conint_bernoullip" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:ns3="http://www.w3.org/1999/xhtml"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:db="http://docbook.org/ns/docbook">
<refnamediv>
<refname>conint_bernoullip</refname><refpurpose>C.I. of the probability of a Bernoulli variable.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Calling Sequence</title>
<synopsis>
[low, up] = conint_bernoullip ( pe , n )
[low, up] = conint_bernoullip ( pe , n , level )
[low, up] = conint_bernoullip ( pe , n , level , twosided )
</synopsis>
</refsynopsisdiv>
<refsection>
<title>Parameters</title>
<variablelist>
<varlistentry><term>pe :</term>
<listitem><para> a 1-by-1 matrix of doubles, an estimate of the probability</para></listitem></varlistentry>
<varlistentry><term>n :</term>
<listitem><para> a 1-by-1 matrix of doubles, the number of trials</para></listitem></varlistentry>
<varlistentry><term>level :</term>
<listitem><para> 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]</para></listitem></varlistentry>
<varlistentry><term>twosided :</term>
<listitem><para> 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].</para></listitem></varlistentry>
<varlistentry><term>low :</term>
<listitem><para> a 1-by-1 matrix of doubles, the estimated lower bound</para></listitem></varlistentry>
<varlistentry><term>up :</term>
<listitem><para> a 1-by-1 matrix of doubles, the estimated upper bound</para></listitem></varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Description</title>
<para>
Computes a confidence interval of the probability
<literal>p</literal> of a Bernoulli variable.
This random variable is a "success" with probability
<literal>p</literal> and is a failure with probability
<literal>1-p</literal>.
We assume that we have performed <literal>n</literal> trials
of this experiment and we assume that <literal>pe</literal>
is the fraction of the <literal>n</literal> trials which are successes.
This function computes confidence intervals for <literal>p</literal>.
</para>
<para>
If <literal>twosided</literal> is true, then
<literal>low</literal> and <literal>up</literal> are such that
the probability <literal>p</literal> satisfies the equality
</para>
<para>
<literal>
P(low &lt; p &lt; up) = 1-level
</literal>
</para>
<para>
If <literal>twosided</literal> is false, then
<literal>low</literal> and <literal>up</literal> are such that
the probability <literal>var(X)</literal> satisfies the equality
</para>
<para>
<literal>
P(p &lt; up) = 1-level
</literal>
</para>
<para>
and
</para>
<para>
<literal>
P(low &lt; p) = 1-level
</literal>
</para>
<para>
This function makes the assumption that the data
in <literal>x</literal> has a binomial distribution with
parameters <literal>p</literal> and
<literal>n</literal>.
</para>
<para>
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.
</para>
<para>
</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting role="example"><![CDATA[
// 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 )
// 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 )
// Then (0.31,0.41) is a 95% C.I. for p.
]]></programlisting>
</refsection>
<refsection>
<title>Authors</title>
<simplelist type="vert">
<member>Copyright (C) 2011 - Michael Baudin</member>
</simplelist>
</refsection>
<refsection>
<title>Bibliography</title>
<para>http://en.wikipedia.org/wiki/Confidence_interval</para>
<para>"Introduction to probability and statistics for engineers and scientists", Sheldon Ross, Third Edition, 2004</para>
<para>"Probabilités, Analyse de Données et Statistique", Gilbert Saporta, 2nd Ed., 2006</para>
</refsection>
</refentry>
<?xml version="1.0" encoding="UTF-8"?>
<!--
*
* This help file was generated from conint_bernoullip.sci using help_from_sci().
*
-->
<refentry version="5.0-subset Scilab" xml:id="conint_bernoullip" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:ns3="http://www.w3.org/1999/xhtml"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:db="http://docbook.org/ns/docbook">
<refnamediv>
<refname>conint_bernoullip</refname><refpurpose>C.I. of the probability of a Bernoulli variable.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Calling Sequence</title>
<synopsis>
[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 )
</synopsis>
</refsynopsisdiv>
<refsection>
<title>Parameters</title>
<variablelist>
<varlistentry><term>pe :</term>
<listitem><para> a 1-by-1 matrix of doubles, an estimate of the probability</para></listitem></varlistentry>
<varlistentry><term>n :</term>
<listitem><para> a 1-by-1 matrix of doubles, integer value, positive, the number of trials</para></listitem></varlistentry>
<varlistentry><term>level :</term>
<listitem><para> 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]</para></listitem></varlistentry>
<varlistentry><term>twosided :</term>
<listitem><para> 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].</para></listitem></varlistentry>
<varlistentry><term>method :</term>
<listitem><para> 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</para></listitem></varlistentry>
<varlistentry><term>low :</term>
<listitem><para> a 1-by-1 matrix of doubles, the estimated lower bound</para></listitem></varlistentry>
<varlistentry><term>up :</term>
<listitem><para> a 1-by-1 matrix of doubles, the estimated upper bound</para></listitem></varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Description</title>
<para>
Computes a confidence interval of the probability
<literal>p</literal> of a Bernoulli variable.
</para>
<para>
This function makes the assumption that the data
in <literal>x</literal> has a binomial distribution with
parameters <literal>p</literal> and
<literal>n</literal>.
In other words, we consider that the random variable is a "success" with probability
<literal>p</literal> and is a "failure" with probability
<literal>1-p</literal>.
We assume that we have performed <literal>n</literal> trials
of this experiment.
We assume that <literal>pe</literal>
is the fraction of the <literal>n</literal> trials which are successes.
This function computes confidence intervals for <literal>p</literal>.
</para>
<para>
If <literal>twosided</literal> is true, then
<literal>low</literal> and <literal>up</literal> are such that
the probability <literal>p</literal> satisfies the equality
</para>
<para>
<literal>
P(low &lt; p &lt; up) = 1-level
</literal>
</para>
<para>
If <literal>twosided</literal> is false, then
<literal>low</literal> and <literal>up</literal> are such that
the probability <literal>p</literal> satisfies the equality
</para>
<para>
<literal>
P(p &lt; up) = 1-level
</literal>
</para>
<para>
and
</para>
<para>
<literal>
P(low &lt; p) = 1-level
</literal>
</para>
<para>
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.
</para>
<para>
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.
</para>
<para>
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).
</para>
<para>
If method=3, then invert the quantiles of the
Binomial distribution with the Normal distribution.
This is the Clopper-Pearson interval.
</para>
<para>
</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting role="example"><![CDATA[
// 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 )
// Then (0.7216,0.8774) is an approximate 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 )
// Then (0.31,0.41) is an approximate 95% C.I. for p.
// 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.
// The quadratic or Wilson (1927) interval :
method = 2;
[low, up] = conint_bernoullip ( pe , n , level , twosided , method )
// 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 )
// Then (0.188,0.352) is an approximate 90% C.I. for p.
]]></programlisting>
</refsection>
<refsection>
<title>Authors</title>
<simplelist type="vert">
<member>Copyright (C) 2011 - Michael Baudin</member>
</simplelist>
</refsection>
<refsection>
<title>Bibliography</title>
<para>http://en.wikipedia.org/wiki/Confidence_interval</para>
<para>"Introduction to probability and statistics for engineers and scientists", Sheldon Ross, Third Edition, 2004</para>
<para>"Probabilités, Analyse de Données et Statistique", Gilbert Saporta, 2nd Ed., 2006</para>
<para>http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval</para>
</refsection>
</refentry>
readme.txt
55
66
77
8
9
810
911
1012
......
1214
1315
1416
15
16
17
18
19
20
21
22
23
24
25
26
27
17
18
19
20
21
2822
29
30
31
32
33
34
35
36
37
38
39
4023
4124
4225
......
5235
5336
5437
55
38
5639
5740
5841
......
6851
6952
7053
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<up);
// Check default value of level
x = [5, 8.5, 12, 15, 7, 9, 7.5, 6.5, 10.5];
n = size(x,"*");
me = mean(x);
v = variance(x);
[ low, up ] = conint_normmu ( n , me, v , [] , [] , %f );
assert_checkalmostequal(me,9.,1.e-5);
assert_checkalmostequal(low,6.630806,1.e-5);
assert_checkalmostequal(up,11.369194,1.e-5);
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);

Archive Download the corresponding diff file

Revision: 2