Sample size calculation

2025. 2. 11. 22:42Statistics/studying

버튼만 누르면 나오는 줄 아는 sample size =)

 

 언제나 또 요청받았다.

그렇다 사실 계산기가 있어서 .. 누르면 나온다는 말이 맞기도 하다.

 

계산기 작동 원리를 잘 모르겠다구요 ㅠㅠ 

 

평소에 자주 가서 보던 사이트는 

https://powerandsamplesize.com/Calculators/Compare-2-Means/2-Sample-Non-Inferiority-or-Superiority

 

Compare 2 Means 2-Sample Non-Inferiority or Superiority | Power and Sample Size Calculators | HyLown

Calculate Sample Size Needed to Compare 2 Means: 2-Sample Non-Inferiority or Superiority This calculator is useful for the types of tests known as non-inferiority and superiority tests. Whether the null hypothesis represents 'non-inferiority' or 'superiori

powerandsamplesize.com

여기로 식과 코드가 잘 정리되어 있어서 참고하기 좋았다.

 

proportion으로 구하는 것이 더 잘 알려져 있고 

식도 확실해 보였는데...

필자는 time-to-event data에 대한 non inferiority test 의 sample size를 구해야해서 아래와 같은 식이 필요했다.


 

Calculate Sample Size Needed to Test Time-To-Event Data: Cox PH 1-Sided, non-inferiority, or superiority

 

$H_0:\theta=\theta_0$
$H_1:\theta\gt \theta_0$
or$H_0:\theta=\theta_0$
$H_1:\theta\lt \theta_0$
where $\theta_0$ is the hazard ratio hypothesized under the null hypothesis; $\theta_0$ can also be viewed as the non-inferiority/superiority margin, just like in the other non-inferiority/superiority calculators here. The calculator above and the formulas below use the notation that

$\theta$ is the hazard ratio
$\ln(\theta)$ is the natural logarithm of the hazard ratio, or the log-hazard ratio
$p_E$ is the overall probability of the event occurring within the study period
$p_A$ and $p_B$ are the proportions of the sample size allotted to the two groups, named 'A' and 'B'
$n$ is the total sample size

Notice that $p_B=1-p_A$.

Formulas

This calculator uses the following formulas to compute sample size and power, respectively: $$n=\frac{1}{p_A\;p_B\;p_E}\left(\frac{z_{1-\alpha}+z_{1-\beta}}{\ln(\theta)-\ln(\theta_0)}\right)^2$$
$$1-\beta= \Phi\left( z-z_{1-\alpha}\right) \quad ,\quad z=\left(\ln(\theta)-\ln(\theta_0)\right)\sqrt{n\;p_A\;p_B\;p_E}$$ where


 

조건

1. event

2. Non inferiority test (margin = 2.5% 연구자 설정)

3. 1:1

4. accrual time: 2years

5. Total time: accrual 2 years + follow-up 1 year

6. assumption: event rates of 5% in both group. (reference들을 보고 정해야한다.)

7. statistical power 80%

8. primary statistical method: Kaplan-meier survival analysis with log-rank test

9. withdrawal rate: 5% (censoring 고려)

 

step0. 연구자가 reference 고려하여 margin과 연구기간등을 설정

step1. 각 군의 위험율을 계산하고 (margin 고려)

step2. 위험비를 구하고 (HR)

step3. 필요한 사건 수를 계산하고(schoenfeld 공식)

step4. sample 수 계산

step5. 탈락률 보정

 

제일 중요한건 언제나 뭘 보이고 싶은지 이다.

가설

$$H_0: HR \geq HR_{margin}$$

$$H_1: HR \lt HR_{margin}$$

 

여기서 $HR_0$가 inferiority HR 이다.(step 2에서 계산)

 

step1. 

두 군 모두 5% 가정에

inferiority margin 2.5% > 실험군에서 최대 5% + 2.5%의 사건율(생존율 92.5%)까지 허용한다.

 

대조군의 위험율

$\lambda_C = - ln(0.95) \approx 0.0513$

실험군의 생존율 

$\lambda_C = - ln(0.925) \approx 0.0770$

 

step2. 

Non inferiority margin in HR

$HR_{margin} = \frac{\lambda_T}{\lambda_C} \approx 1.5$

 

step3.

$$d = \left(\frac{Z_{1-\alpha} + Z_{1-\beta}}{ln(HR_{margin}}\right)^2$$

유의수준( \alpha ): $Z_{1-\alpha} = 1.645$

검정력(1-\beta): $Z_{1-\beta} = 0.84$

$ln(HR_{margin}) \approx 0.4055$

 

얼마나 많은 사건이 발생해야 통계적으로 유의미한 차이를 검출 할 수 있는가를 계산 하는 것이다.

 

step4.

$$ N = \frac{d}{사건율} = \frac{38}{0.05} \approx 760 $$

 

 

step5.

$$ \frac{N}{1-0.05} = \frac{760}{0.95} \approx 800 $$

 

전체 샘플 수 800명으로 각 군 400명 씩 필요하다는 결론이 나온다.

 

 

위의 페이지의 식과 차이?

 

 $$n=\frac{1}{p_A\;p_B\;p_E}\left(\frac{z_{1-\alpha}+z_{1-\beta}}{\ln(\theta)-\ln(\theta_0)}\right)^2$$

 

여기서 $p_A$와 $p_B$는 사건의 비율이다. 균등할당이면 각각 0.5가 되는 것이다.

그럼 이걸 고려하면 800명의 4배가 되는 것이다.

 

근데 균등할당일 때는 분산이나 필요 사건 수에 대해 미치는 영향이 상대적으로 최소화 되어 그냥 앞부분을 

1로 무시하고 사용할 수 있다고 한다.

 

조금 더 세밀하게 보정하여

3200명의 sample 을 모집할 수도 있다.

 

매번.. 뭔 소린지 잘 모르겠다.

그냥 일단 정리..

보고 답답하신 부분 있으시면 언제든지 댓글로 알려주십시오ㅠ ㅠ

 

 

 

728x90

'Statistics > studying' 카테고리의 다른 글

Non-inferiority trial  (2) 2024.01.07
glm? lm?  (0) 2023.07.12
z-score  (0) 2022.12.17
쳬비세프의 정리 (Chebyshev's theorem) 와 경험법칙(Empirical rule)  (2) 2022.12.17