Skip to content

Commit

Permalink
Apply JuliaFormatter (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jotas6 authored Aug 31, 2023
1 parent 3e9c519 commit 9a86a02
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
indent = 2
format_docstrings = true
107 changes: 61 additions & 46 deletions 00-model_fits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ pkdata = dataset("nlme_sample")

pop = read_pumas(
pkdata;
id=:ID,
time=:TIME,
amt=:AMT,
observations=[:DV],
cmt=:CMT,
evid=:EVID,
rate=:RATE
id = :ID,
time = :TIME,
amt = :AMT,
observations = [:DV],
cmt = :CMT,
evid = :EVID,
rate = :RATE,
)

# 1-compartment model
Expand All @@ -26,19 +26,27 @@ model_1cmt = @model begin
end

@param begin
"Clearance (L/hr)"
tvcl RealDomain(; lower=0)
"Volume Central Compartment (L)"
tvvc RealDomain(; lower=0)
"""
- ΩCL
- ΩVc
Clearance (L/hr)
"""
tvcl RealDomain(; lower = 0)
"""
Volume Central Compartment (L)
"""
tvvc RealDomain(; lower = 0)
"""
- ΩC
- ΩV
"""
Ω PDiagDomain(2)
"Additive RUV"
σ_add RealDomain(; lower=0)
"Proportional RUV"
σ_prop RealDomain(; lower=0)
"""
Additive RUV
"""
σ_add RealDomain(; lower = 0)
"""
Proportional RUV
"""
σ_prop RealDomain(; lower = 0)
end

@random begin
Expand All @@ -61,13 +69,8 @@ model_1cmt = @model begin
end
end

params_1cmt = (;
tvvc=5,
tvcl=0.2,
Ω=Diagonal([0.01, 0.01]),
σ_add=0.1,
σ_prop=0.1
)
params_1cmt =
(; tvvc = 5, tvcl = 0.2, Ω = Diagonal([0.01, 0.01]), σ_add = 0.1, σ_prop = 0.1)

fit_1cmt = fit(model_1cmt, pop, params_1cmt, FOCE())

Expand All @@ -79,23 +82,35 @@ model_2cmt = @model begin
end

@param begin
"Clearance (L/hr)"
tvcl RealDomain(; lower=0)
"Volume Central Compartment (L)"
tvvc RealDomain(; lower=0)
"Intercompartmental Clearance (L/hr)"
tvq RealDomain(; lower=0)
"Volume Peripheral Compartment (L)"
tvvp RealDomain(; lower=0)
"""
- ΩCL
- ΩVc
"""
Clearance (L/hr)
"""
tvcl RealDomain(; lower = 0)
"""
Volume Central Compartment (L)
"""
tvvc RealDomain(; lower = 0)
"""
Intercompartmental Clearance (L/hr)
"""
tvq RealDomain(; lower = 0)
"""
Volume Peripheral Compartment (L)
"""
tvvp RealDomain(; lower = 0)
"""
- ΩC
- ΩV
"""
Ω PDiagDomain(2)
"Additive RUV"
σ_add RealDomain(; lower=0)
"Proportional RUV"
σ_prop RealDomain(; lower=0)
"""
Additive RUV
"""
σ_add RealDomain(; lower = 0)
"""
Proportional RUV
"""
σ_prop RealDomain(; lower = 0)
end

@random begin
Expand All @@ -118,13 +133,13 @@ model_2cmt = @model begin
end

params_2cmt = (;
tvvc=5,
tvcl=0.02,
tvq=0.01,
tvvp=10,
Ω=Diagonal([0.01, 0.01]),
σ_add=0.1,
σ_prop=0.1
tvvc = 5,
tvcl = 0.02,
tvq = 0.01,
tvvp = 10,
Ω = Diagonal([0.01, 0.01]),
σ_add = 0.1,
σ_prop = 0.1,
)

fit_2cmt = fit(model_2cmt, pop, params_2cmt, FOCE())
4 changes: 2 additions & 2 deletions 01-inspect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ inspect_1cmt = inspect(fit_1cmt)
# You can also have NPDEs if you pass an extra optional keyword
# argument nsim with the number of times each subject is simulated
# for npde computation
inspect_1cmt_npde = inspect(fit_1cmt; nsim=200)
inspect_1cmt_npde = inspect(fit_1cmt; nsim = 200)

# Let's also call the inspect function on our 2-compartment model
inspect_2cmt = inspect(fit_2cmt)
inspect_2cmt_npde = inspect(fit_2cmt; nsim=200)
inspect_2cmt_npde = inspect(fit_2cmt; nsim = 200)

# You can convert any inspect object to a NM-TRAN-formatted DataFrame
inspect_1cmt_df = DataFrame(inspect_1cmt)
Expand Down
2 changes: 1 addition & 1 deletion 02-predict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ predict_1cmt = DataFrame(predict(model_1cmt, pop, coef(fit_1cmt)))
# Suppose you want a more richer/denser pred/ipred time profile
# You can do that with the keyword argument obstimes
# it will "extend" the original observation profile to encompass the desired obstimes
predict_1cmt_custom = DataFrame(predict(fit_1cmt; obstimes=168:172))
predict_1cmt_custom = DataFrame(predict(fit_1cmt; obstimes = 168:172))
20 changes: 10 additions & 10 deletions 03-metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ bic(fit_1cmt)
# It can compute a loglikelihood for any model given any population, parameter values, and estimation method
# This is helpful for model conversions from other software/tools
loglikelihood(
model_1cmt,
pop,
(; # NamedTuple of parameter values
tvcl=0.2,
tvvc=5,
Ω=Diagonal([0.1, 0.1]),
σ_add=0.01,
σ_prop=0.05
),
FOCE(),
model_1cmt,
pop,
(; # NamedTuple of parameter values
tvcl = 0.2,
tvvc = 5,
Ω = Diagonal([0.1, 0.1]),
σ_add = 0.01,
σ_prop = 0.05,
),
FOCE(),
)

# There are several plotting functions available in Pumas
Expand Down
4 changes: 2 additions & 2 deletions 04-vpc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ vpc_plot(vpc_1cmt)
vpc_plot(vpc_2cmt)

# You can also use a prediction-corrected VPC with the keyword argument prediction_correction
vpc_1cmt_pc = vpc(fit_1cmt; prediction_correction=true)
vpc_2cmt_pc = vpc(fit_2cmt; prediction_correction=true)
vpc_1cmt_pc = vpc(fit_1cmt; prediction_correction = true)
vpc_2cmt_pc = vpc(fit_2cmt; prediction_correction = true)
vpc_plot(vpc_1cmt_pc)
vpc_plot(vpc_2cmt_pc)

0 comments on commit 9a86a02

Please sign in to comment.