> For the complete documentation index, see [llms.txt](https://ykkim.gitbook.io/wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ykkim.gitbook.io/wiki/machine-learning/probability-and-statistics-for-machine-learning/confidence-intervals-three-views.md).

# Confidence Intervals: Three Views

## Introduction

* 이전 단원에서는 confidence intervals을 standardized statistics와 hypothesis의 조합으로 설정하는 방법만 다뤘지만 이번 단원에서는 각각 따로 설정하는 방법을 배울 것임
  * Standardized statistics
  * Hypothesis Testing
  * Formal

## Confidence intervals via standardized statistics

### z-confidence intervals for µ: normal data with known σ

z-statistics를 기반으로 함

n개의 independent normal samples:

$$
x\_1 ,x\_2 ,...,x\_n \sim N\left( {\mu ,\sigma ^2 } \right)
$$

µ: unknown, σ: known이라고 가정, standard mean이 정규 분포를 따름:

$$
z = {{\bar x - \mu } \over {\sigma /\sqrt n }} \sim N\left( {0,1} \right)
$$

normal critical value z\_α/2에 대해

$$
\eqalign{ & P\left( { - z\_{\alpha /2} < Z < z\_{\alpha /2} } \right) = 1 - \alpha \cr & P\left( { - z\_{\alpha /2} < {{\bar x - \mu } \over {\sigma /\sqrt n }} < z\_{\alpha /2} |\mu } \right) = 1 - \alpha \cr & P\left( {\bar x - z\_{\alpha /2} \cdot {\sigma \over {\sqrt n }} < \mu < \bar x + z\_{\alpha /2} \cdot {\sigma \over {\sqrt n }}|\mu } \right) = 1 - \alpha \cr & P\left( {\left\[ {\bar x - z\_{\alpha /2} \cdot {\sigma \over {\sqrt n }},\bar x + z\_{\alpha /2} \cdot {\sigma \over {\sqrt n }}} \right],,contains,\mu |\mu } \right) = 1 - \alpha \cr}
$$

위 식은 µ에 대한 (1 − α) z-confidence interval. 다음과 같이 쓸 수도 있음:

$$
\overline x \pm z\_{\alpha /2} \cdot {\sigma \over {\sqrt n }}
$$

위 식을 x ± error라고 생각해도 됨

### t-confidence intervals for µ: normal data with unknown µ and σ

t-statistics를 기반으로 함

N개의 independent normal samples:

$$
x\_1 ,x\_2 ,...,x\_n \sim N\left( {\mu ,\sigma ^2 } \right)
$$

z-statics와는 다르게 µ와 σ 둘 다 unknown

studentized mean은 n-1 dof의 Student t distribution을 따름:

$$
t = {{\overline x - \mu } \over {s/\sqrt n }} \sim t\left( {n - 1} \right)
$$

z-statistics처럼 standardized mean을 studentized mean에 대한 식으로 바꿈:

$$
\eqalign{ & P\left( { - t\_{\alpha /2} < {{\overline x - \mu } \over {s/\sqrt n }} < t\_{\alpha /2} |\mu } \right) = 1 - \alpha \cr & P\left( {\overline x - t\_{\alpha /2} \cdot {s \over {\sqrt n }} < \mu < \overline x + t\_{\alpha /2} \cdot {s \over {\sqrt n }}|\mu } \right) = 1 - \alpha \cr & P\left( {\left\[ {\overline x - t\_{\alpha /2} \cdot {s \over {\sqrt n }},,\overline x + t\_{\alpha /2} \cdot {s \over {\sqrt n }}|\mu } \right],contains,\mu |\mu } \right) = 1 - \alpha \cr}
$$

위 식은 µ에 대한 (1 − α) t-confidence interval.

$$
\overline x \pm z\_{\alpha /2} \cdot {\sigma \over {\sqrt n }}
$$

위 식을 x ± error라고 생각해도 됨

### X2-confidence intervals for σ2: normal data with unknown µ and σ

X2-statistics를 기반으로 함

σ2에 대한 X2-confidence interval을 구하기 위해 위에서 사용한 방법을 사용함

n independent normal samples:

$$
x\_1 ,x\_2 ,...,x\_n \sim N\left( {\mu ,\sigma ^2 } \right)
$$

µ와 σ 둘 다 unknown

standardized variance:

$$
X^2 = {{\left( {n - 1} \right)s^2 } \over {\sigma ^2 }} \sim X^2 \left( {n - 1} \right)
$$

X2 statistics는 n-1 dof의 X2 distribution을 따름

Z와 t distribution의 경우에는 symmetry하기 때문에

$$
\eqalign{ & z\_{1 - \alpha /2} = z\_{\alpha /2} \cr & and \cr & t\_{1 - \alpha /2} = t\_{\alpha /2} \cr}
$$

이었지만 X2 distribution은 symmetry하지 않기 때문에 치환할 수 없음

$$
\eqalign{ & P\left( {c\_{1 - \alpha /2} < X^2 < c\_{\alpha /2} } \right) = 1 - \alpha \cr & where,c\_{\alpha /2} ,and,c\_{1 - \alpha /2} ,are,right,tail,critical,value.,Thus, \cr & P\left( {c\_{1 - \alpha /2} < {{\left( {n - 1} \right)s} \over {\sigma ^2 }}^2 < c\_{\alpha /2} |\sigma } \right) = 1 - \alpha \cr & P\left( {{{\left( {n - 1} \right)s^2 } \over {c\_{\alpha /2} }} < \sigma ^2 < {{\left( {n - 1} \right)s^2 } \over {c\_{1 - \alpha /2} }}|\sigma } \right) = 1 - \alpha \cr & P\left( {\left\[ {{{\left( {n - 1} \right)s^2 } \over {c\_{\alpha /2} }},,{{\left( {n - 1} \right)s^2 } \over {c\_{1 - \alpha /2} }}} \right],contains,\sigma ^2 |\sigma ^2 } \right) = 1 - \alpha \cr}
$$

위 식은 σ^2에 대한 (1 − α) χ2-confidence interval임

## Confidence intervals via hypothesis testing

값을 모르는 파라미터 θ가 있는 distribution에서 데이터를 추출했다고 가정함. 값 θ에 대한 significance test는 다음과 같음

1. 특정값 θ0에 대해 H0: θ = θ0을 설정함, θ0 = 0으로 설정하는 경우가 많음
2. 데이터를 사용해 test statistics의 값을 계산하고 x라고 부름
3. x가 null hypothesis의 tail까지 충분히 멀리 있으면 H0를 reject함

#### example

데이터 x가 알려지지 않은 이항 분포 (12, θ)에서 추출되었다고 가정함. α = 0.1으로 설정하고 (1 - α) = 90% confidence interval을 생성함. α = 0.1인 significance test에 대해 reject region을 선택함. 그 후에 각 x의 값에 대해 어떤 θ일 때 reject되지 않았는지( = x와 관련된 신뢰구간)을 알 수 있음.

각 행은 고정된 θ에 대한 p(x|θ)

![](https://3698175758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAwtzMy_pbrChIExFtN%2Fuploads%2Fgit-blob-763504fac678bf63e32b21e33dbeb35364008276%2Flikelihood_table_for_binomial.png?alt=media)

![](https://3698175758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MAwtzMy_pbrChIExFtN%2Fuploads%2Fgit-blob-664d78a679bbeae2fb4cb70f8f7c5b17bc2290f2%2Fliekihood_table_with_rejection_non_rejection?alt=media)

왼쪽 열부터 값을 더했을 때 0.1이 넘는 시점부터 non-reject함

주황색: rejection region

파란색: non-rejection region

#### example 2

x = 8일 때 confidence interval 0.9를 정하라

x=8일 때 모든 θ가 α=0.1 hypothesis test에 의해 reject되지 않는 confidence interval은 \[0.5, 0.8]임

#### example 3

type 1 CI error의 비율이 최대 0.092인 이유를 설명하시오

confidence interval에 θ의 실제 값이 포함되지 않은 경우 발생하는 오류고, 이를 θtrue라고 함. 데이터가 θtrue에 대한 rejection region에 있을 때 발생함. 이것이 일어날 확률은 θtrue의 significance이고 최대 0.092임

#### example 4

<https://mathlets.org/mathlets/confidence-intervals/>

## Formal view of confidence intervals

unknown parameter θ가 있는 pdf(x|θ) distribution을 가정함

(1 − α) confidence interval for θ is an interval statistic Ix

$$
P\left( {I\_x ,contains,\theta \_0 |\theta = \theta \_0 } \right) = 1 - \alpha
$$

모델의 실제 파라미터가 θ0일 때 ramdom interval에 θ0가 포함될 확률을 의미함

## Comparison with Bayesian probability intervals

* 신뢰 구간은 빈도주의적인 개념
  * probability가 아니라 likelihood의 개념
* 반대로 베이지안 posterior probability interval은 알려지지 않은 파라미터가 알려진 범위에 있을 확률임
* Bayesian posterior probability intervals과 frequentist confidence intervals는 다음과 같은 공통점이 있기 때문에 차이가 미묘함
  * They start from a model f(x|θ) for observed data x with unknown parameter θ.
  * Given data x, they give an interval I(x) specifying a range of values for θ.
  * They come with a number (say .95) that is the probability of something
