Skip to content

Commit c8e2da1

Browse files
authored
Merge pull request #13 from PumasAI-Labs/an/pkuncertainty
Add uncertainty estimation for popPK model.
2 parents 30a50f2 + d6642a8 commit c8e2da1

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Script: AN01-pk_model_uncertainty.jl
2+
# Purpose: Provide uncertainty estimates for the points estimates of the model
3+
# ==============================================================
4+
5+
using Pumas, CairoMakie, DataFrames, DataFramesMeta, CategoricalArrays, Logging
6+
include(joinpath("..", "..", "Day1", "01-TeachingMaterial", "MW03-pk_model_fitting.jl")) # This gives us the fitted model 'fpm'
7+
8+
# Introduction to Parameter Uncertainty
9+
# --------------------------------
10+
# Understanding uncertainty in parameter estimates is crucial because:
11+
# 1. Some parameters might be poorly determined in the model for the data available
12+
# 2. Parameter uncertainty affects predictions and simulations
13+
# 3. Some parameters may be more precisely estimated than others
14+
# 4. Uncertainty helps inform experimental design and data collection
15+
#
16+
# We'll explore a variety of approaches:
17+
# 1. Asymptotic confidence intervals
18+
# a Sandwich estimator (default)
19+
# b Inverse Hessian (the classical maximum likelihood estimator)
20+
# 2. Bootstrap Method (non-parametric resampling)
21+
# 3. Sampling importance resampling (SIR)
22+
23+
@info "Asymptotic confidence intervals"
24+
@info "Sandwich estimator (default)"
25+
@info "===================================="
26+
asymp_inf_a = infer(fpm)
27+
28+
@info "Sandwich estimator (default)"
29+
asymp_inf_b = infer(fpm; sandwich_estimator = false)
30+
31+
# Step 2: Bootstrap Analysis
32+
# ----------------------
33+
# Bootstrap analysis:
34+
# - Resamples the data with replacement
35+
# - Refits the model to each sample
36+
# - Is more robust but computationally intensive
37+
38+
@info "Performing Bootstrap Analysis..."
39+
@info "This will take some time as we need to refit the model multiple times"
40+
41+
# Perform bootstrap with progress updates
42+
bts_inf = infer(fpm, Bootstrap(samples = 100))
43+
44+
@info "Bootstrap Analysis Complete!"
45+
@info "Parameter Standard Errors from Bootstrap:"
46+
coeftable(bts_inf)
47+
48+
# Step 3: Sampling importance resampling
49+
sir_inf = infer(fpm, SIR(samples = 1000, resamples = 200))
50+
51+
# Educational Note:
52+
# ---------------
53+
@info "Key Takeaways from Uncertainty Analysis:"
54+
@info "1. Parameter uncertainty can be estimated through multiple methods"
55+
@info "2. Bootstrap is more robust but computationally intensive"
56+
@info "3. Some parameters may be estimated more precisely than others"
57+
@info "4. Fixing poorly identified parameters can improve estimation"
58+
@info "5. Understanding uncertainty is crucial for model-based decision making"
59+
60+
# Next Steps:
61+
# ----------
62+
@info "Next Steps:"
63+
@info "1. Use uncertainty estimates in simulations (simulation.jl)"
64+
@info "2. Consider ways to reduce uncertainty:"
65+
@info " - Collect more data"
66+
@info " - Modify sampling times"
67+
@info " - Simplify the model if appropriate"

Day2/01-TeachingMaterial/MW04-pkpd_model_uncertainty_quantification.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include("MW02-pkpd_model_fitting.jl") # This gives us the fitted model 'fpm'
88
# Introduction to Parameter Uncertainty
99
# --------------------------------
1010
# Understanding uncertainty in parameter estimates is crucial because:
11-
# 1. No model fit is perfect - we need to quantify our confidence
11+
# 1. Some parameters might be poorly determined in the model for the data available
1212
# 2. Parameter uncertainty affects predictions and simulations
1313
# 3. Some parameters may be more precisely estimated than others
1414
# 4. Uncertainty helps inform experimental design and data collection
@@ -35,7 +35,6 @@ end
3535
# Bootstrap analysis:
3636
# - Resamples the data with replacement
3737
# - Refits the model to each sample
38-
# - Provides empirical parameter distributions
3938
# - Is more robust but computationally intensive
4039

4140
@info "Performing Bootstrap Analysis..."

0 commit comments

Comments
 (0)