Hi I am trying to use L2 correlation, since the pk and pd concentrations are taken from the same sample. The simulations work and it also starts the estimation but then fails with an error. Can you please help me fix this?
Attached model code and failed estimation error
true_model_pk_delay_pd_sim = @model begin
@param begin
tvcl ∈ RealDomain(lower=0.0)
tvvc ∈ RealDomain(lower=0.0)
tvq ∈ RealDomain(lower=0.0)
tvvp ∈ RealDomain(lower=0.0)
tvka ∈ RealDomain(lower=0.0)
tvkin ∈ RealDomain(lower=0.0)
tvkout ∈ RealDomain(lower=0.0)
tvImax ∈ RealDomain(lower=0.0)
tvIC50 ∈ RealDomain(lower=0.0)
Ω ∈ PDiagDomain(8)
Σ ∈ PSDDomain(2)
end
@random begin
η ~ MvNormal(Ω)
end
@pre begin
CL = tvcl * exp(η[1])
Vc = tvvc * exp(η[2])
Q = tvq * exp(η[3])
Vp = tvvp * exp(η[4])
Ka = tvka * exp(η[5])
Kin = tvkin * exp(η[6])
Kout = tvkout * exp(η[7])
Imax = tvImax
IC50 = tvIC50 * exp(η[8])
σ_prop_pk = Σ[1]
σ_prop_pd = Σ[2]
end
@init begin
Response = Kin/Kout
end
@vars begin
Central_conc = (Central/Vc)*1000
end
@dynamics begin
Depot' = -Ka*Depot
Central' = Ka*Depot - (CL/Vc)*Central - (Q/Vc)*Central + (Q/Vp)*Peripheral
Peripheral' = (Q/Vc)*Central - (Q/Vp)*Peripheral
Response' = Kin*(1-((Imax * Central_conc)/(IC50 + Central_conc))) - Kout*Response
end
@derived begin
Cp = @. Central_conc
DV ~ @. Normal(Cp, Cp*σ_prop_pk)
Resp = @. Response
DV_Resp ~ @. Normal(Resp, Resp*σ_prop_pd)
end
end
##Simulation
final_params = (tvcl = 11.3,
tvvc = 37.6,
tvq = 31.4,
tvvp = 47.8,
tvka = 0.8,
tvkin = 20,
tvkout = 0.8,
tvImax = 1,
tvIC50 = 2000,
Ω = Diagonal([0.0625,0.09,0.0625,0.09,0.09,0.16,0.09,0.09]),
Σ = [0.1 0.02
0.02 0.2])
N=30
ev0 = DosageRegimen(500, time=0, cmt=1)
protocol_sampling_time = [0.20,1.33,1.66,1.99,2.95,6.96,7.30,7.63,19.22]
pop0 = map(i -> Subject(id=i, events=ev0, time=protocol_sampling_time), 1:N)
pop0_df = DataFrame(pop0)
Random.seed!(123)
sim_base = simobs(true_model_pk_delay_pd_sim,
pop0,
final_params)
df_base_sim = DataFrame(sim_base)
##Estimation
initial_params = ( tvcl = 10.3,
tvvc = 39.6,
tvq = 35.4,
tvvp = 50.8,
tvka = 0.8,
tvkin = 20,
tvkout = 0.7,
tvImax = 0.8,
tvIC50 = 2100,
Ω = Diagonal([0.0625,0.09,0.0625,0.09,0.09,0.16,0.09,0.09]),
Σ = [0.1 0.02
0.02 0.2])
read_fit_df = read_pumas(df_base_sim,
observations = [:DV, :DV_Resp])
fit_foce = fit(true_model_pk_delay_pd_sim, read_fit_df, initial_params,
FOCE(), ensemblealg=EnsembleThreads())
Error
[ Info: Checking the initial parameter values.
[ Info: The initial negative log likelihood and its gradient are finite. Check passed.
Iter Function value Gradient norm
0 2.810998e+03 2.300546e+04
* time: 2.5987625122070312e-5
ERROR: MethodError: no method matching iterate(::Nothing)
Closest candidates are:
iterate(::Union{LinRange, StepRangeLen}) at range.jl:872
iterate(::Union{LinRange, StepRangeLen}, ::Integer) at range.jl:872
iterate(::T) where T<:Union{Base.KeySet{<:Any, <:Dict}, Base.ValueIterator{<:Dict}} at dict.jl:712
...
Stacktrace:
[1] indexed_iterate(I::Nothing, i::Int64)
@ Base ./tuple.jl:91
[2] _unidentified_exception(A::PDMats.PDMat{Float64, Matrix{Float64}}, i::Int64, j::Int64, d::Int64, k::Symbol)
@ Pumas /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/zfm1h/src/estimation/likelihoods.jl:3510
[3] _check_zero_gradient(vparam::Vector{Float64}, g::Vector{Float64}, fixedtrf::TransformVariables.TransformTuple{NamedTuple{(:tvcl, :tvvc, :tvq, :tvvp, :tvka, :tvkin, :tvkout, :tvImax, :tvIC50, :Ω, :Σ), Tuple{TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, Pumas.PDiagTransform, Pumas.PSDTransform}}})
@ Pumas /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/zfm1h/src/estimation/likelihoods.jl:3475
[4] (::Pumas.var"#619#621"{FOCE, Bool, NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, TransformVariables.TransformTuple{NamedTuple{(:tvcl, :tvvc, :tvq, :tvvp, :tvka, :tvkin, :tvkout, :tvImax, :tvIC50, :Ω, :Σ), Tuple{TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, Pumas.PDiagTransform, Pumas.PSDTransform}}}, Vector{Vector{Float64}}, Vector{Vector{Float64}}})(state::Vector{Optim.OptimizationState{Float64, Optim.BFGS{LineSearches.InitialStatic{Float64}, LineSearches.BackTracking{Float64, Int64}, Nothing, Float64, Optim.Flat}}})
@ Pumas /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/zfm1h/src/estimation/likelihoods.jl:4047
[5] #588
@ /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/zfm1h/src/estimation/likelihoods.jl:3000 [inlined]
[6] update!(tr::Vector{Optim.OptimizationState{Float64, Optim.BFGS{LineSearches.InitialStatic{Float64}, LineSearches.BackTracking{Float64, Int64}, Nothing, Float64, Optim.Flat}}}, iteration::Int64, f_x::Float64, grnorm::Float64, dt::Dict{Any, Any}, store_trace::Bool, show_trace::Bool, show_every::Int64, callback::Pumas.var"#588#590"{Pumas.DefaultOptimizeFN{Nothing, NamedTuple{(:show_trace, :store_trace, :extended_trace, :g_tol, :allow_f_increases), Tuple{Bool, Bool, Bool, Float64, Bool}}}, Pumas.var"#619#621"{FOCE, Bool, NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, TransformVariables.TransformTuple{NamedTuple{(:tvcl, :tvvc, :tvq, :tvvp, :tvka, :tvkin, :tvkout, :tvImax, :tvIC50, :Ω, :Σ), Tuple{TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, Pumas.PDiagTransform, Pumas.PSDTransform}}}, Vector{Vector{Float64}}, Vector{Vector{Float64}}}}, trace_simplex::Bool)
@ Optim /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Optim/tP8PJ/src/utilities/update.jl:23
[7] update!
@ /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Optim/tP8PJ/src/utilities/update.jl:11 [inlined]
[8] trace!(tr::Vector{Optim.OptimizationState{Float64, Optim.BFGS{LineSearches.InitialStatic{Float64}, LineSearches.BackTracking{Float64, Int64}, Nothing, Float64, Optim.Flat}}}, d::NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, state::Optim.BFGSState{Vector{Float64}, Matrix{Float64}, Float64, Vector{Float64}}, iteration::Int64, method::Optim.BFGS{LineSearches.InitialStatic{Float64}, LineSearches.BackTracking{Float64, Int64}, Nothing, Float64, Optim.Flat}, options::Optim.Options{Float64, Pumas.var"#588#590"{Pumas.DefaultOptimizeFN{Nothing, NamedTuple{(:show_trace, :store_trace, :extended_trace, :g_tol, :allow_f_increases), Tuple{Bool, Bool, Bool, Float64, Bool}}}, Pumas.var"#619#621"{FOCE, Bool, NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, TransformVariables.TransformTuple{NamedTuple{(:tvcl, :tvvc, :tvq, :tvvp, :tvka, :tvkin, :tvkout, :tvImax, :tvIC50, :Ω, :Σ), Tuple{TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, Pumas.PDiagTransform, Pumas.PSDTransform}}}, Vector{Vector{Float64}}, Vector{Vector{Float64}}}}}, curr_time::Float64)
@ Optim /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Optim/tP8PJ/src/multivariate/solvers/first_order/bfgs.jl:191
[9] optimize(d::NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, initial_x::Vector{Float64}, method::Optim.BFGS{LineSearches.InitialStatic{Float64}, LineSearches.BackTracking{Float64, Int64}, Nothing, Float64, Optim.Flat}, options::Optim.Options{Float64, Pumas.var"#588#590"{Pumas.DefaultOptimizeFN{Nothing, NamedTuple{(:show_trace, :store_trace, :extended_trace, :g_tol, :allow_f_increases), Tuple{Bool, Bool, Bool, Float64, Bool}}}, Pumas.var"#619#621"{FOCE, Bool, NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, TransformVariables.TransformTuple{NamedTuple{(:tvcl, :tvvc, :tvq, :tvvp, :tvka, :tvkin, :tvkout, :tvImax, :tvIC50, :Ω, :Σ), Tuple{TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, Pumas.PDiagTransform, Pumas.PSDTransform}}}, Vector{Vector{Float64}}, Vector{Vector{Float64}}}}}, state::Optim.BFGSState{Vector{Float64}, Matrix{Float64}, Float64, Vector{Float64}})
@ Optim /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Optim/tP8PJ/src/multivariate/optimize/optimize.jl:50
[10] optimize
@ /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Optim/tP8PJ/src/multivariate/optimize/optimize.jl:36 [inlined]
[11] DefaultOptimizeFN
@ /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/zfm1h/src/estimation/likelihoods.jl:2993 [inlined]
[12] _fit(m::PumasModel{(tvcl = 1, tvvc = 1, tvq = 1, tvvp = 1, tvka = 1, tvkin = 1, tvkout = 1, tvImax = 1, tvIC50 = 1, Ω = 8, Σ = 3), 8, (:Depot, :Central, :Peripheral, :Response), ParamSet{NamedTuple{(:tvcl, :tvvc, :tvq, :tvvp, :tvka, :tvkin, :tvkout, :tvImax, :tvIC50, :Ω, :Σ), Tuple{RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, PDiagDomain{PDMats.PDiagMat{Float64, Vector{Float64}}}, PSDDomain{Matrix{Float64}}}}}, var"#5#12", var"#6#13", Nothing, var"#7#14", ODEProblem{Nothing, Tuple{Nothing, Nothing}, false, Nothing, ODEFunction{false, ModelingToolkit.ODEFunctionClosure{var"#8#15", var"#9#16"}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Vector{Symbol}, Symbol, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, var"#10#17", var"#11#18", ModelingToolkit.ODESystem}, population::Vector{Subject{NamedTuple{(:DV, :DV_Resp), Tuple{Vector{Union{Missing, Float64}}, Vector{Union{Missing, Float64}}}}, Pumas.ConstantCovar{NamedTuple{(), Tuple{}}}, Vector{Pumas.Event{Float64, Float64, Float64, Float64, Float64, Float64, Int64}}, Vector{Float64}}}, param::NamedTuple{(:tvcl, :tvvc, :tvq, :tvvp, :tvka, :tvkin, :tvkout, :tvImax, :tvIC50, :Ω, :Σ), Tuple{Float64, Float64, Float64, Float64, Float64, Int64, Float64, Float64, Int64, Diagonal{Float64, Vector{Float64}}, Matrix{Float64}}}, approx::FOCE, ensemblealg::EnsembleThreads, optimize_fn::Pumas.DefaultOptimizeFN{Nothing, NamedTuple{(:show_trace, :store_trace, :extended_trace, :g_tol, :allow_f_increases), Tuple{Bool, Bool, Bool, Float64, Bool}}}, fixedparamset::ParamSet{NamedTuple{(:tvcl, :tvvc, :tvq, :tvvp, :tvka, :tvkin, :tvkout, :tvImax, :tvIC50, :Ω, :Σ), Tuple{RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, PDiagDomain{PDMats.PDiagMat{Float64, Vector{Float64}}}, PSDDomain{Matrix{Float64}}}}}, fixedparam::NamedTuple{(:tvcl, :tvvc, :tvq, :tvvp, :tvka, :tvkin, :tvkout, :tvImax, :tvIC50, :Ω, :Σ), Tuple{Float64, Float64, Float64, Float64, Float64, Int64, Float64, Float64, Int64, Diagonal{Float64, Vector{Float64}}, Matrix{Float64}}}, checkidentification::Bool, diffeq_options::NamedTuple{(), Tuple{}}, init_vrandeffsorth::Vector{Vector{Float64}}, verbose::Bool)
@ Pumas /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/zfm1h/src/estimation/likelihoods.jl:4062
[13] __fit
@ /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/zfm1h/src/estimation/likelihoods.jl:3804 [inlined]
[14] fit(m::PumasModel{(tvcl = 1, tvvc = 1, tvq = 1, tvvp = 1, tvka = 1, tvkin = 1, tvkout = 1, tvImax = 1, tvIC50 = 1, Ω = 8, Σ = 3), 8, (:Depot, :Central, :Peripheral, :Response), ParamSet{NamedTuple{(:tvcl, :tvvc, :tvq, :tvvp, :tvka, :tvkin, :tvkout, :tvImax, :tvIC50, :Ω, :Σ), Tuple{RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, RealDomain{Float64, TransformVariables.Infinity{true}, Float64}, PDiagDomain{PDMats.PDiagMat{Float64, Vector{Float64}}}, PSDDomain{Matrix{Float64}}}}}, var"#5#12", var"#6#13", Nothing, var"#7#14", ODEProblem{Nothing, Tuple{Nothing, Nothing}, false, Nothing, ODEFunction{false, ModelingToolkit.ODEFunctionClosure{var"#8#15", var"#9#16"}, UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Vector{Symbol}, Symbol, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, var"#10#17", var"#11#18", ModelingToolkit.ODESystem}, _population::Vector{Subject{NamedTuple{(:DV, :DV_Resp), Tuple{Vector{Union{Missing, Float64}}, Vector{Union{Missing, Float64}}}}, Pumas.ConstantCovar{NamedTuple{(), Tuple{}}}, Vector{Pumas.Event{Float64, Float64, Float64, Float64, Float64, Float64, Symbol}}, Vector{Float64}}}, param::NamedTuple{(:tvcl, :tvvc, :tvq, :tvvp, :tvka, :tvkin, :tvkout, :tvImax, :tvIC50, :Ω, :Σ), Tuple{Float64, Float64, Float64, Float64, Float64, Int64, Float64, Float64, Int64, Diagonal{Float64, Vector{Float64}}, Matrix{Float64}}}, approx::FOCE; optim_alg::Nothing, optim_options::Nothing, optimize_fn::Nothing, constantcoef::NamedTuple{(), Tuple{}}, omegas::Tuple{}, ensemblealg::EnsembleThreads, checkidentification::Bool, diffeq_options::NamedTuple{(), Tuple{}}, init_randeffs::Nothing, init_vrandeffsorth::Nothing, verbose::Bool)
@ Pumas /build/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/zfm1h/src/estimation/likelihoods.jl:3768
[15] top-level scope
@ ~/data/code/Methodology-Project/model/L2 Correlation/l2_correlation.jmd:161