Home Libraries People FAQ More

##### 估算二項分佈(Binomial Distribution)的樣本大小.

```void find_max_sample_size(
double p,              // 成功比(success ratio).
unsigned successes)    // 總共的可能觀察的成功次數(Total number of observed successes permitted).
{
```

```double alpha[] = { 0.5, 0.25, 0.1, 0.05, 0.01, 0.001, 0.0001, 0.00001 };
```

```for(unsigned i = 0; i < sizeof(alpha)/sizeof(alpha[0]); ++i)
{
// Confidence value:
cout << fixed << setprecision(3) << setw(10) << right << 100 * (1-alpha[i]);
// 計算試驗次數:
double t = binomial::find_maximum_number_of_trials(
successes, p, alpha[i]);
t = floor(t);
// 打印試驗次數:
cout << fixed << setprecision(5) << setw(15) << right << t << endl;
}
```

```________________________
Maximum Number of Trials
________________________

Success ratio                           =  0.001
Maximum Number of "successes" permitted =  0

____________________________
Confidence        Max Number
Value (%)        Of Trials
____________________________
50.000            692
75.000            287
90.000            105
95.000             51
99.000             10
99.900              0
99.990              0
99.999              0
```

```________________________
Maximum Number of Trials
________________________

Success ratio                           =  0.0000010
Maximum Number of "successes" permitted =  0

____________________________
Confidence        Max Number
Value (%)        Of Trials
____________________________
50.000         693146
75.000         287681
90.000         105360
95.000          51293
99.000          10050
99.900           1000
99.990            100
99.999             10
```