using Random
using Distributions
using CairoMakie
using AlgebraOfGraphics
Understanding Normal vs LogNormal for Modeling PK Parameters
Load the necessary libraries
1 Background
In pharmacometrics, it’s common to model parameters like clearance (CL) as random variables to account for unexplained variability between individuals. One of the most prevalent ways to model this variability is by assuming that these parameters follow a log-normal distribution. However, the mathematical notation and code implementation can sometimes be confusing, especially when dealing with logarithms and exponentials.
This tutorial will walk you through various ways to model a parameter like CL in Pumas, illustrating the equivalence between different formulations. We’ll start with basic Julia code examples to understand the underlying mathematics and then move on to Pumas-specific implementations.
2 Basics of Normal and Log-Normal Distributions
Before diving into the code, let’s understand the difference between normal and log-normal distributions.
Normal Distribution: A continuous probability distribution characterized by its mean (μ) and standard deviation (σ). It is symmetric around the mean.
Log-Normal Distribution: If a random variable \(X\) is log-normally distributed, then the natural logarithm \(log(X)\) is normally distributed. This distribution is skewed and only takes positive values, which makes it suitable for modeling parameters like CL.
In Julia, the log
function calculates the natural logarithm, equivalent to ln
in other languages. For logarithms with base 10 or 2, use log10
or log2
respectively.
2.1 Relationship Between Normal and Log-Normal Distributions
If \(\eta \sim \mathcal{N}(0, \omega^2)\), then \(\exp(\eta)\) follows a log-normal distribution.
Mathematical Formulation:
- \(\eta \sim \mathcal{N}(0, \omega^2)\)
- \(CL = \theta \cdot \exp(\eta)\)
- \(\log(CL) = \log(\theta) + \eta\)
2.2 Modeling CL with Exponentiated Normal Distribution
Let’s start by modeling CL as an exponentiated normal random variable.
# Parameters
= 10.0 # Typical value of CL
theta = 0.3 # Between-subject variability
omega
# Number of individuals
= 1000
N
# Simulate eta from a normal distribution
Random.seed!(1234)
= rand(Normal(0, omega), N)
eta
# Calculate CL
= theta * exp.(eta)
CL
# Plot the distribution of CL
hist(
CL,= 50,
bins = (title = "Distribution of CL", xlabel = "CL", ylabel = "Frequency"),
axis )
Explanation
- eta: Simulated from a normal distribution with mean 0 and standard deviation \(\omega\).
- CL: Calculated as \(\theta \cdot \exp(\eta)\), resulting in a log-normally distributed CL.
2.3 Modeling CL with Log-Normal Distribution
Alternatively, we can model CL directly as a log-normally distributed variable.
# Parameters
= 10.0 # Typical value of CL
theta = 0.3 # Between-subject variability
omega
# Number of individuals
= 1000
N
# Simulate CL directly from a log-normal distribution
Random.seed!(1234)
= rand(LogNormal(log(theta), omega), N)
CL
# Plot the distribution of CL
hist(
CL,= 50,
bins = (title = "Distribution of CL", xlabel = "CL", ylabel = "Frequency"),
axis )
Explanation
- CL: Simulated directly from a log-normal distribution with parameters \(\log(\theta)\) and \(\omega\).
2.4 Equivalence of Different Modeling Approaches
The two approaches above are mathematically equivalent. Here’s why:
- Approach 1: \(CL = \theta \cdot \exp(\eta)\), where \(\eta \sim \mathcal{N}(0, \omega)\).
- Approach 2: \(CL \sim \text{LogNormal}(\log(\theta), \omega)\).
Proof of Equivalence:
From Approach 1:
- \(\log(CL) = \log(\theta) + \eta\).
- Since \(\eta \sim \mathcal{N}(0, \omega^2)\), \(\log(CL)\) is normally distributed with mean \(\log(\theta)\) and variance \(\omega^2\).
This matches the parameters of the log-normal distribution in Approach 2.
2.5 Pumas Code Examples
Now, let’s translate these concepts into Pumas code. We’ll explore different ways to model CL and show their equivalence.
2.5.1 Using Exponentiated Normal Distribution
@model begin
@param begin
∈ RealDomain()
θ ∈ RealDomain()
ω end
@random η ~ Normal(0, ω)
@pre CL = θ * exp(η)
end
Explanation:
- η ~ Normal(0, ω): Random effect η is normally distributed.
- CL = θ * exp(η): CL is calculated by exponentiating η.
2.5.2 Using Log-Normal Distribution for Random Effect
@model begin
@param begin
∈ RealDomain()
θ ∈ RealDomain()
ω end
@random sCL ~ LogNormal(log(θ), ω)
@pre CL = sCL
end
Explanation:
- sCL ~ LogNormal(log(θ), ω): Random effect η is log-normally distributed.
- CL = sCL: The
@random
block directly gets the log normal clearance (sCL
) that we are assigning to CL in the@pre
block.
The downside of using this approach is that we don’t get an explicit \(\eta\) to use in the post-processing.
2.5.3 Explicitly Calculating CL Using log(θ)
@model begin
@param begin
∈ RealDomain()
θ ∈ RealDomain()
ω end
@random η ~ Normal(0, ω)
@pre CL = exp(log(θ) + η)
end
Explanation:
- CL = exp(log(θ) + η): This is mathematically equivalent to \(CL = θ * exp(η)\).
2.5.4 Modeling log(CL) Directly
@model begin
@param begin
∈ RealDomain()
θ ∈ RealDomain()
ω end
@random logCL ~ Normal(log(θ), ω)
@pre CL = exp(logCL)
end
Explanation:
- logCL ~ Normal(log(θ), ω): The logarithm of CL is normally distributed.
- CL = exp(logCL): Recover CL by exponentiating logCL.
The downside of using this approach is that we don’t get an explicit \(\eta\) to use in the post-processing.
2.5.5 Directly Modeling CL as Log-Normal
@model begin
@param θ
@random CL ~ LogNormal(log(θ), ω)
end
Explanation:
- CL ~ LogNormal(log(θ), ω): CL is directly modeled as a log-normally distributed variable.
The downside of using this approach is that we don’t get an explicit \(\eta\) to use in the post-processing.
3 Conclusion
All the above Pumas models are mathematically equivalent in how they handle the random variability of CL. They just implement it differently in code. Understanding the equivalence between these formulations is crucial for correctly specifying models and interpreting results.
4 Key Takeaways
- Exponentiating a Normal Variable: If you exponentiate a normally distributed variable, the result is log-normally distributed.
- Log-Normal Distribution Parameters: In a log-normal distribution, the parameters are the mean and variance of the logarithm of the variable.
- Modeling Strategies: You can model variability in a positive parameter by adding a normally distributed random effect to the logarithm of the parameter, or by multiplying a log-normally distributed random effect to the positive parameter directly.