My program runs into a problem with the time variable when I try to run the simulation.
Can you spot the problem?
# Practice developing dissolution model using Pumas
using Random
using Pumas
using PumasUtilities
using CairoMakie
using AlgebraOfGraphics
using DataFramesMeta
using DataFrames
## Model definition
pk_44_cim_emax = @model begin
@metadata begin
desc = "Dissolution model"
timeu = u"minute"
end
@param begin
"Maximum % drug dissolved (%)"
tvfdissmax ∈ RealDomain(lower=0)
"Time required for 50% of the drug to dissolve (minutes)"
tvtd50 ∈ RealDomain(lower=0)
"Additive RUV"
σ_add ∈ RealDomain(lower=0)
end
@covariates dtd50
@pre begin
fdissmax = tvfdissmax
td50 = tvtd50*(1 + dtd50)
_time = time
end
@derived begin
fdiss = @. fdissmax * _time / (td50 + _time)
"""
Fraction dissolved in vitro
"""
dv_fdiss ~ @. Normal(fdiss, σ_add)
end
end
param_emax = ( tvfdissmax = 100.0, tvtd50 = 10, σ_add = 0.01)
## Creating a Dataset
df_sub1_emax = map(i -> DataFrame(id = i, time = 1:1:1000, dv_fdiss = missing, dtd50=0), 1:6)
df = vcat(DataFrame.(df_sub1_emax)...)
df[!, :dtd50] = ifelse.(df.id .== 2, -0.75, df.dtd50)
df[!, :dtd50] = ifelse.(df.id .== 3, -0.5, df.dtd50)
df[!, :dtd50] = ifelse.(df.id .== 4, -0.25, df.dtd50)
df[!, :dtd50] = ifelse.(df.id .== 5, 0.25, df.dtd50)
df[!, :dtd50] = ifelse.(df.id .== 6, 0.5, df.dtd50)
df_sub1_emax = df
sub1_emax = read_pumas(df_sub1_emax, observations=[:dv_fdiss], covariates=[:dtd50], event_data=false)
##Simulation
Random.seed!(123)
sim_emax = simobs(pk_44_cim_emax, sub1_emax, param_emax)
df44_1_emax = DataFrame(sim_emax)
##Visualization
@chain df44_1_emax begin
@rsubset :time ∈ [1,5,10,26,104,251,502,1000]
data(_) *
mapping(:time => "Time(minutes)",
:fdiss => "Fraction dissolved",
color = :dtd50 => nonnumeric => "Exposure") *
visual(ScatterLines, linewidth = 4, markersize = 12)
draw(axis = (;xticks = 0:100:1000, yticks = 0:10:100))
end