# Why do we get cp_pred and dv_pred when inspecting?

Here is my code:

``````using Pumas
using PumasUtilities
using DataFramesMeta

# Read in Data
pkfile = dataset("iv_sd_3")

# Convert DataFrame into Collection of Subjects (Population)

# Model definition
model = @model begin

@param begin
# here we define the parameters of the model
tvcl ∈ RealDomain(; lower = 0.001) # typical clearance
tvvc ∈ RealDomain(; lower = 0.001) # typical central volume of distribution
Ω ∈ PDiagDomain(2)             # between-subject variability
σ ∈ RealDomain(; lower = 0.001)    # residual error
end

@random begin
# here we define random effects
η ~ MvNormal(Ω) # multi-variate Normal with mean 0 and covariance matrix Ω
end

@pre begin
# pre computations and other statistical transformations
CL = tvcl * exp(η[1])
Vc = tvvc * exp(η[2])
end

# here we define compartments and dynamics
@dynamics Central1 # same as Central' = -(CL/Vc)*Central (see Pumas documentation)

@derived begin
# here is where we calculate concentration and add residual variability
# tilde (~) means "distributed as"
cp = @. 1000 * Central / Vc # ipred = A1/V
dv ~ @. Normal(cp, σ)
# dv ~ @. Normal(cp, sqrt(cp^2 * σ_prop^2 + σ_add^2))
end
end

# Parameter values
params = (tvcl = 1.0, tvvc = 10.0, Ω = Diagonal([0.09, 0.09]), σ = 3.16)

# Fit a base model
fit_results = fit(model, population, params, Pumas.FOCE())

ins_results = DataFrame(inspect(fit_results))
all_names =names(ins_results)
all_sel = @select(ins_results, :id, :time,  :dv, :cp_pred, :dv_pred,:cp_ipred, :dv_ipred)
``````

dv is the the observed concentration, but what is the different between cp_pred and dv_pred?
They show the exact same values. Why would it predict two of the same value?

The reason is that you are defining two variables in the derived block so we’ll compute the (conditional) expectation of each of them. or `cp`, the expectation is not changing the value since the quantity isn’t a random variable. For this choice of error model, the two predicted variables will be identical but that is not necessarily the case. If you had written

``````cp = @. 1000 * Central / Vc
dv ~ @. LogNormal(log(cp), σ)
``````

then the two values would be different since the expectation of the LogNormal is `exp(log(cp) + σ^2/2)` which is larger than `cp`.

However, we probably shouldn’t compute `_pred` values for the non-random variables in the derived block. We might change this behavior in the future.

1 Like