forked from selcukorkmaz/geneSurv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
power.R
72 lines (47 loc) · 1.91 KB
/
power.R
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
## 1. Exponential Model
## 1.1 Test for Equality
hazardRate1 = 1
hazardRate2 = 2
T=3
T0=1
k = 1
alpha = 0.05
beta = 0.2
sigma_hazardRate1 = (hazardRate1^2)*(1+(exp(-hazardRate1*T)-exp(-hazardRate1*(T+T0)))/hazardRate1*T0)^(-1)
sigma_hazardRate2 = (hazardRate2^2)*(1+(exp(-hazardRate2*T)-exp(-hazardRate2*(T+T0)))/hazardRate2*T0)^(-1)
za = qnorm(alpha/2,lower.tail = F)
zb = qnorm(beta,lower.tail = F)
n = round((((za+zb)^(2))/(hazardRate2-hazardRate1)^(2))*((sigma_hazardRate1/k)+sigma_hazardRate2),0)
## 1.1.1 Unconditional Versus Conditional (Lachin, 1981)
e = hazardRate1-hazardRate2
hazardRateMean = (k*hazardRate1+hazardRate2)/(k+1)
sigma_hazardRateMean = (hazardRateMean^2)*(1+(exp(-hazardRateMean*T)-exp(-hazardRateMean*(T+T0)))/hazardRateMean*T0)^(-1)
n = (1/e^(2))*(za*sigma_hazardRateMean*((1/k)+1)+ zb*((sigma_hazardRate1/k)+sigma_hazardRate2)^(0.5))^(2)
## 1.2 Test for Non-Inferiority/Superiority
hazardRate1 = 1
hazardRate2 = 2
superiorityMargin = 0.2
T=3
T0=1
k = 1
alpha = 0.05
beta = 0.2
sigma_hazardRate1 = (hazardRate1^2)*(1+(exp(-hazardRate1*T)-exp(-hazardRate1*(T+T0)))/hazardRate1*T0)^(-1)
sigma_hazardRate2 = (hazardRate2^2)*(1+(exp(-hazardRate2*T)-exp(-hazardRate2*(T+T0)))/hazardRate2*T0)^(-1)
za = qnorm(alpha,lower.tail = F)
zb = qnorm(beta,lower.tail = F)
n = round((((za+zb)^(2))/(hazardRate2-hazardRate1-superiorityMargin)^(2))*((sigma_hazardRate1/k)+sigma_hazardRate2),0)
## 1.2 Test for Equivalence
hazardRate1 = 1
hazardRate2 = 1
equivalenceMargin = 0.5
T=3
T0=1
k = 1
alpha = 0.05
beta = 0.2
sigma_hazardRate1 = (hazardRate1^2)*(1+(exp(-hazardRate1*T)-exp(-hazardRate1*(T+T0)))/hazardRate1*T0)^(-1)
sigma_hazardRate2 = (hazardRate2^2)*(1+(exp(-hazardRate2*T)-exp(-hazardRate2*(T+T0)))/hazardRate2*T0)^(-1)
za = qnorm(alpha,lower.tail = F)
zb = qnorm(beta/2,lower.tail = F)
n = round((((za+zb)^(2))/(equivalenceMargin-abs(hazardRate1-hazardRate2))^(2))*((sigma_hazardRate1/k)+sigma_hazardRate2),0)