generated from PumasAI-Labs/Workshop-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-single_tte.jl
153 lines (125 loc) · 3.65 KB
/
01-single_tte.jl
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using Pumas
using PumasUtilities
using PharmaDatasets
using DataFrames
using DataFramesMeta
# dataset
tte_single = dataset("tte_single")
# including AMT column
@rtransform! tte_single :AMT = 0
# Pumas Modeling
pop_single = read_pumas(
tte_single;
observations = [:DV],
covariates = [:DOSE],
id = :ID,
time = :TIME,
amt = :AMT,
evid = :EVID,
)
# Exponential
tte_single_exp_model = @model begin
@param begin
λ₁ ∈ RealDomain(; lower = 0, init = 0.001) # basal hazard
β ∈ RealDomain(; init = 0.001) # fixed effect DOSE
ω ∈ RealDomain(; lower = 0) # inter-subject variability
end
@random begin
η ~ Normal(0.0, ω)
end
@covariates DOSE
@pre begin
_λ₁ = λ₁ * exp(η) # basal hazard with inter-subject variability
_λ₀ = _λ₁ * exp(β * DOSE) # total hazard
end
@vars begin
# exponential
λ = _λ₀
end
@dynamics begin
# the derivative of cumulative hazard is equal to hazard
Λ' = λ
end
@derived begin
DV ~ @. TimeToEvent(λ, Λ) # special type of distribution
end
end
tte_single_exp_fit =
fit(tte_single_exp_model, pop_single, init_params(tte_single_exp_model), LaplaceI())
# Weibull
tte_single_weibull_model = @model begin
@param begin
λ₁ ∈ RealDomain(; lower = 0, init = 0.001) # basal hazard
β ∈ RealDomain(; init = 0.001) # fixed effect DOSE
ω ∈ RealDomain(; lower = 0) # inter-subject variability
Κ ∈ RealDomain(; lower = 0, init = 0.001) # Weibull shape
end
@random begin
η ~ Normal(0.0, ω)
end
@covariates DOSE
@pre begin
_Κ = Κ # shape parameter
_λ₁ = λ₁ * exp(η) # basal hazard with inter-subject variability
_λ₀ = _λ₁ * exp(β * DOSE) # total hazard
end
@vars begin
# Weibull
# 1e-10 for model numerical stability
λ = _λ₀ * _Κ * (_λ₀ * t + 1e-10)^(_Κ - 1)
end
@dynamics begin
# the derivative of cumulative hazard is equal to hazard
Λ' = λ
end
@derived begin
DV ~ @. TimeToEvent(λ, Λ) # special type of distribution
end
end
tte_single_weibull_fit = fit(
tte_single_weibull_model,
pop_single,
init_params(tte_single_weibull_model),
LaplaceI(),
)
# Gompertz
tte_single_gompertz_model = @model begin
@param begin
λ₁ ∈ RealDomain(; lower = 0, init = 0.001) # basal hazard
β ∈ RealDomain(; init = 0.001) # fixed effect DOSE
ω ∈ RealDomain(; lower = 0) # inter-subject variability
Κ ∈ RealDomain(; lower = 0, init = 0.001) # Gompertz shape
end
@random begin
η ~ Normal(0.0, ω)
end
@covariates DOSE
@pre begin
_Κ = Κ # shape parameter
_λ₁ = λ₁ * exp(η) # basal hazard with inter-subject variability
_λ₀ = _λ₁ * exp(β * DOSE) # total hazard
end
@vars begin
# Gompertz
λ = _λ₀ * exp(_Κ * t)
end
@dynamics begin
# the derivative of cumulative hazard is equal to hazard
Λ' = λ
end
@derived begin
DV ~ @. TimeToEvent(λ, Λ) # special type of distribution
end
end
tte_single_gompertz_fit = fit(
tte_single_gompertz_model,
pop_single,
init_params(tte_single_gompertz_model),
LaplaceI(),
)
# compare MLE estimates
compare_estimates(;
Exponential = tte_single_exp_fit,
Weibull = tte_single_weibull_fit,
Gompertz = tte_single_gompertz_fit,
)