No method matching for time

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
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)
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
"""
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
``````

Hi Kevin - change

``````@pre begin
fdissmax = tvfdissmax
td50 = tvtd50*(1 + dtd50)
_time = time
end
``````

to this:

``````@pre begin
fdissmax = tvfdissmax
td50 = tvtd50*(1 + dtd50)
_time = t
end
``````

and it will work. Essentially, underlying Pumas uses `t` for time and not `time`

For the future, remember to post the full error message when posing a question along with the code and data (or data sample), it will better help to resolve the error. You can use the “Hide Details” option by clicking the gear icon in the message.

1 Like

Thank you! That let it run, but now my fdiss is only simulated as zeros.

By mentioning `_time = t` it is only considering at the first time point which is time=0 for all time points for a single ID. Change the @derived block to:

``````@derived begin
fdiss = @. fdissmax * t / (td50 + t)
"""
Fraction dissolved in vitro
"""