How to customize individual subject fit plots in Pumas

Hello,

I was wondering if there is a way to customize individual subject fit plots in Pumas.

As an example, for a crossover study, I need pk fit plots for each subject stratified by period as below

image

and also I need the dose and period in the legend.

subject_fits from Pumas currently does not support stratifications.
You would need to customize a plot from the result of an inspect call (to get the pred/ipred).

Here’s a minimal working example:

using Pumas
using PharmaDatasets
using CairoMakie
using AlgebraOfGraphics

pop = read_pumas(dataset("iv_sd_3"); covariates=[:dosegrp])

model = @model begin
    @param begin
        tvcl ∈ RealDomain(; lower=0)
        tvvc ∈ RealDomain(; lower=0)
        σ ∈ RealDomain(; lower=0)
    end
    @pre begin
        CL = tvcl
        Vc = tvvc
    end
    @dynamics begin
        Central' = -CL/Vc*Central
    end
    @derived begin
        cp = @. 1000 * Central / Vc # Change of units
        dv ~ @. Normal(cp, abs(cp) * σ)
    end
end

inspect_df = DataFrame(inspect(
    fit(
        model, pop, init_params(model), NaivePooled()
    )
))

plt = data(dropmissing(inspect_df, :dv_ipred)) *
    mapping(
        :time,
        :dv_ipred;
        color=:dosegrp => nonnumeric,
    ) *
    visual(Lines)

draw(plt)

Which generates:

I highly recommend the Data Visualizations tutorials at tutorials.pumas.ai.