Home Libraries People FAQ More

#### 理解離散分位點(Understanding Quantiles of Discrete Distributions)

• 我們可以將結果向下捨入到18。
• 我們可以將結果向上捨入到19。

• 計算一個整數結果通常要比計算一個浮點數結果要更快：實際上在我們的測試中要快20倍。
• 通常人們計算分位來進行一些測試："如果隨機變量的值小於N，那麼我們可以具有90%的把握來否決我們的虛假設(null-hypothesis)."

```quantile(binomial(50, 0.5), 0.05);
```

```cdf(binomial(50, 0.5), x) <= 0.05;
```

```quantile(binomial(50, 0.5), 0.95);
```

```cdf(binomial(50, 0.5), x) >= 0.95;
```

```X <= L || X > U
```

```L < X <= U
```

##### 其它可用的捨入策略

integer_round_outwards

integer_round_inwards

integer_round_down

integer_round_up

integer_round_nearest

real

```#include <iostream>
#include <boost/math/distributions/binomial.hpp>```

```using namespace boost::math::policies;
using namespace boost::math;

typedef binomial_distribution<
double,
policy<discrete_quantile<integer_round_outwards> > >
binom_round_outwards;

typedef binomial_distribution<
double,
policy<discrete_quantile<integer_round_inwards> > >
binom_round_inwards;

typedef binomial_distribution<
double,
policy<discrete_quantile<integer_round_down> > >
binom_round_down;

typedef binomial_distribution<
double,
policy<discrete_quantile<integer_round_up> > >
binom_round_up;

typedef binomial_distribution<
double,
policy<discrete_quantile<integer_round_nearest> > >
binom_round_nearest;

typedef binomial_distribution<
double,
policy<discrete_quantile<real> > >
binom_real_quantile;```

```int main()
{
std::cout <<
"Testing rounding policies for a 50 sample binomial distribution,\n"
"with a success fraction of 0.5.\n\n"
"Lower quantiles are calculated at p = 0.05\n\n"
"Upper quantiles at p = 0.95.\n\n";

std::cout << std::setw(25) << std::right
<< "Policy"<< std::setw(18) << std::right
<< "Lower Quantile" << std::setw(18) << std::right
<< "Upper Quantile" << std::endl;

// 測試 integer_round_outwards:
std::cout << std::setw(25) << std::right
<< "integer_round_outwards"
<< std::setw(18) << std::right
<< quantile(binom_round_outwards(50, 0.5), 0.05)
<< std::setw(18) << std::right
<< quantile(binom_round_outwards(50, 0.5), 0.95)
<< std::endl;

// 測試 integer_round_inwards:
std::cout << std::setw(25) << std::right
<< "integer_round_inwards"
<< std::setw(18) << std::right
<< quantile(binom_round_inwards(50, 0.5), 0.05)
<< std::setw(18) << std::right
<< quantile(binom_round_inwards(50, 0.5), 0.95)
<< std::endl;

// 測試 integer_round_down:
std::cout << std::setw(25) << std::right
<< "integer_round_down"
<< std::setw(18) << std::right
<< quantile(binom_round_down(50, 0.5), 0.05)
<< std::setw(18) << std::right
<< quantile(binom_round_down(50, 0.5), 0.95)
<< std::endl;

// 測試 integer_round_up:
std::cout << std::setw(25) << std::right
<< "integer_round_up"
<< std::setw(18) << std::right
<< quantile(binom_round_up(50, 0.5), 0.05)
<< std::setw(18) << std::right
<< quantile(binom_round_up(50, 0.5), 0.95)
<< std::endl;

// 測試 integer_round_nearest:
std::cout << std::setw(25) << std::right
<< "integer_round_nearest"
<< std::setw(18) << std::right
<< quantile(binom_round_nearest(50, 0.5), 0.05)
<< std::setw(18) << std::right
<< quantile(binom_round_nearest(50, 0.5), 0.95)
<< std::endl;

// 測試 real:
std::cout << std::setw(25) << std::right
<< "real"
<< std::setw(18) << std::right
<< quantile(binom_real_quantile(50, 0.5), 0.05)
<< std::setw(18) << std::right
<< quantile(binom_real_quantile(50, 0.5), 0.95)
<< std::endl;
}```

```Testing rounding policies for a 50 sample binomial distribution,
with a success fraction of 0.5.

Lower quantiles are calculated at p = 0.05

Upper quantiles at p = 0.95.

Testing rounding policies for a 50 sample binomial distribution,
with a success fraction of 0.5.

Lower quantiles are calculated at p = 0.05

Upper quantiles at p = 0.95.

Policy    Lower Quantile    Upper Quantile
integer_round_outwards                18                31
integer_round_inwards                19                30
integer_round_down                18                30
integer_round_up                19                31
integer_round_nearest                19                30
real            18.701            30.299
```