# Fitting error of a tumor growth model

**URL:** <https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147>\
**Category:** Basic Usage\
**Created:** [March 4, 2025, 4:09pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147 "2025-03-04T16:09:14Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleem](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@Aleem](https://discourse.pumas.ai/u/Aleem)\
**Post date:** [March 4, 2025, 4:09pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/1 "2025-03-04T16:09:14Z")

</div>

Hi I am tryting to recaptulate a tumour model of a published study as a practice. But I encounted

ERROR: MethodError: no method matching fit(::PumasModel{…}, ::Vector{…}, ::FOCE{…})

```auto
using Pumas
using CSV
using DataFrames
using DataFramesMeta

# Define the model
model = @model begin
    @param begin
        TRF ∈ RealDomain(lower=-Inf, upper=Inf, init = -2.0)
        TG ∈ RealDomain(lower=-Inf, upper=Inf, init = -7.0)
        TD ∈ RealDomain(lower=-Inf, upper=Inf, init = -4.0)
        add_err ∈ RealDomain(lower=0, upper=10, init = 0.1)
        prop_err ∈ RealDomain(lower=0, upper=10, init = 0.1)
        Ω ∈ PDiagDomain(init=[0.1])
    end

    @random begin
        η_RF ~ MvNormal(Ω)
    end

    @pre begin
        RF = exp(TRF + η_RF) / (1 + exp(TRF + η_RF))
        G = exp(TG)
        D = exp(TD)
        CL = 92.2
        Q = 125
        V1 = 17.5
        V2 = 47.4
        Vmax = 2
        Km = 0.0075
        k30 = log(2) / 12
        k10 = CL / V1
        k12 = Q / V1
        k21 = Q / V2
    end

    @init begin
        C = 0
        P = 0
        Cin = 0
        Lsen = ILS - ILS * RF # Use ILS from the dataset
    end

    @dynamics begin
        C' = -(k12 + k10) * C + k21 * P
        P' = k12 * C - k21 * P
        Cin' = Vmax * (C / V1) / (Km + C / V1) - k30 * Cin
        Lsen' = G * Lsen - D * Lsen * Cin
    end

    @derived begin
        LS = @. Lsen + ILS * RF * exp(G * time) # Compute LS (lesion size)
        dv ~ @. Normal(LS, sqrt(add_err^2 + (prop_err * LS)^2))
    end
end

# Create the population object
pop = read_pumas(Dat;
                 id = :ID,
                 time = :TIME,
                 observations = [:DV],
                 covariates = [:ILS], # Include ILS (initial lesion size) as a covariate
                 amt = :AMT,
                 evid = :EVID,
                 cmt = :CMT,
                 rate = :RATE
)

# Fit the model
fit1 = fit(model, pop, FOCE())

```

ERROR: MethodError: no method matching fit(::PumasModel{…}, ::Vector{…}, ::FOCE{…})

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)\
**Post date:** [March 4, 2025, 4:31pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/2 "2025-03-04T16:31:30Z")

</div>

> [@Aleem](#):
>
> `fit1 = fit(model, pop, FOCE())`

This needs to be

```julia
fit1 = fit(model, pop, init_params(model), FOCE())

```

you forgot to pass in the initial parameters of the model

---

<div class="post-metadata">

**Author:** ![Aleem](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@Aleem](https://discourse.pumas.ai/u/Aleem)\
**Post date:** [March 4, 2025, 7:06pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/3 "2025-03-04T19:06:32Z")

</div>

Hi, it failed with the same error after pass in the inits directly. I have defined the initial values in the model structure before.

---

<div class="post-metadata">

**Author:** ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)\
**Post date:** [March 4, 2025, 7:53pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/4 "2025-03-04T19:53:05Z")

</div>

Can you please paste the entire error message here?

---

<div class="post-metadata">

**Author:** ![Aleem](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@Aleem](https://discourse.pumas.ai/u/Aleem)\
**Post date:** [March 4, 2025, 8:30pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/5 "2025-03-04T20:30:25Z")

</div>

Sure.

```auto
ERROR: MethodError: no method matching fit(::PumasModel{…}, ::@NamedTuple{…}, ::Vector{…}, ::FOCE{…})

Closest candidates are:
  fit(::Type{E}, ::Any...) where E<:Survival.NonparametricEstimator
   @ Survival /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Survival/ciOeA/src/estimator.jl:25
  fit(::Type{D}, ::Any...) where D<:Distribution
   @ Distributions /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Distributions/uuqsE/src/genericfit.jl:47
  fit(::Type{StatsBase.Histogram}, ::Any...; kwargs...)
   @ StatsBase /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/StatsBase/ebrT3/src/hist.jl:413
  ...

Some type information was truncated. Use `show(err)` to see complete types.

```

---

<div class="post-metadata">

**Author:** ![andreasnoack](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/andreasnoack/32/22_2.png) [@andreasnoack](https://discourse.pumas.ai/u/andreasnoack)\
**Post date:** [March 4, 2025, 8:35pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/6 "2025-03-04T20:35:59Z")

</div>

It looks like you might have called `fit(model, init_params(model), pop, FOCE())` instead of `fit(model, pop, init_params(model), FOCE())`. Try to reverse the two middle arguments.

---

<div class="post-metadata">

**Author:** ![Aleem](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@Aleem](https://discourse.pumas.ai/u/Aleem)\
**Post date:** [March 4, 2025, 9:29pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/7 "2025-03-04T21:29:00Z")

</div>

Hi,

After changing the order , it became

```auto
ERROR: PumasDataError: Subjects with ids 1, 2, ...., 367 have no modeled observations

```

Then I realized in the model structure dv should be DV to match my read\_pumas function.

After this change, the error is

```auto
PumasModel
  Parameters: TRF, TG, TD, add_err, prop_err, Ω
  Random effects: η_RF
  Covariates:
  Dynamical system variables: C, P, Cin, Lsen
  Dynamical system type: Nonlinear ODE
  Derived: LS, DV
  Observed: LS, DV

Population
  Subjects: 367
  Covariates: ILS
  Observations: DV

[ Info: Checking the initial parameter values.
ERROR: MethodError: no method matching +(::Float64, ::Vector{ForwardDiff.Dual{ForwardDiff.Tag{Pumas.Tag, Float64}, Float64, 1}})
For element-wise addition, use broadcasting with dot syntax: scalar .+ array

Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...)
   @ Base operators.jl:587
  +(::MutableArithmetics.Zero, ::Any)
   @ MutableArithmetics /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/MutableArithmetics/6jxVC/src/rewrite.jl:64
  +(::Any, ::ChainRulesCore.NoTangent)
   @ ChainRulesCore /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/ChainRulesCore/6Pucz/src/tangent_arithmetic.jl:60
  ...

Stacktrace:
  [1] (::var"#88#95")(_param#529::@NamedTuple{…}, _random#530::@NamedTuple{…}, _subject#528::Subject{…})
    @ Main /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/dsl/model_macro.jl:864
  [2] #_derived#328
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/models/model_api.jl:1214 [inlined]
  [3] _derived
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/models/model_api.jl:1192 [inlined]
  [4] (::Pumas.var"#569#570"{…})(vηorth::Vector{…})
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:2873
  [5] chunk_mode_jacobian(f::Pumas.var"#569#570"{…}, x::Vector{…}, cfg::ForwardDiff.JacobianConfig{…}, ::Val{…})
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:2806
  [6] _derived_vηorth_gradient(m::PumasModel{…}, subject::Subject{…}, param::@NamedTuple{…}, vrandeffsorth::Vector{…}, diffeq_options::@NamedTuple{})
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:2877
  [7] _∂²l∂η²(m::PumasModel{…}, subject::Subject{…}, param::@NamedTuple{…}, vrandeffsorth::Vector{…}, approx::FOCE{…}, diffeq_options::@NamedTuple{})
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:2922
  [8] (::Pumas.var"#489#490"{…})(F::Float64, G::Vector{…}, H::Matrix{…}, x::Vector{…})
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:1204
  [9] (::NLSolversBase.var"#98#104"{…})(G::Vector{…}, H::Matrix{…}, x::Vector{…})
    @ NLSolversBase /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/NLSolversBase/kavn7/src/objective_types/incomplete.jl:115
 [10] value_gradient_hessian!!(obj::NLSolversBase.TwiceDifferentiable{…}, x::Vector{…})
    @ NLSolversBase /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/NLSolversBase/kavn7/src/objective_types/incomplete.jl:138
 [11] initial_state(method::Optim.NewtonTrustRegion{…}, options::Optim.Options{…}, d::NLSolversBase.TwiceDifferentiable{…}, initial_x::Vector{…})
    @ Optim /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Optim/ZhuZN/src/multivariate/solvers/second_order/newton_trust_region.jl:310
 [12] optimize
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Optim/ZhuZN/src/multivariate/optimize/optimize.jl:36 [inlined]
 [13] _orth_empirical_bayes!(vrandeffsorth::Vector{…}, m::PumasModel{…}, _subject::Subject{…}, param::@NamedTuple{…}, approx::FOCE{…}, diffeq_options::@NamedTuple{})
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:1231
 [14] _update_ebes_and_evaluate_marginal_nll!(m::PumasModel{…}, subject::Subject{…}, param::@NamedTuple{…}, vrandeffsorth::Vector{…}, approx::FOCE{…}, diffeq_options::@NamedTuple{})
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:3357
 [15] #590
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:3515 [inlined]
 [16] next
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/library.jl:54 [inlined]
 [17] next
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/core.jl:777 [inlined]
 [18] next
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/simd.jl:8 [inlined]
 [19] macro expansion
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/core.jl:181 [inlined]
 [20] __foldl__
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/processes.jl:237 [inlined]
 [21] foldl_basecase
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/processes.jl:361 [inlined]
 [22] _reduce_basecase(rf::Transducers.Reduction{…}, init::InitialValues.InitialValueOf{…}, reducible::Transducers.SizedReducible{…})
    @ Transducers /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/threading_utils.jl:58
 [23] _reduce(ctx::Transducers.NoopDACContext, rf::Transducers.Reduction{…}, init::InitialValues.InitialValueOf{…}, reducible::Transducers.SizedReducible{…})
    @ Transducers /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/reduce.jl:139
 [24] _reduce(ctx::Transducers.NoopDACContext, rf::Transducers.Reduction{…}, init::InitialValues.InitialValueOf{…}, reducible::Transducers.SizedReducible{…}) (repeats 3 times)
    @ Transducers /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/reduce.jl:148
 [25] _reduce(ctx::Transducers.NoopDACContext, rf::Transducers.Reduction{…}, init::InitialValues.InitialValueOf{…}, reducible::Transducers.SizedReducible{…})
    @ Transducers /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/reduce.jl:148
 [26] _transduce_assoc_nocomplete
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/reduce.jl:131 [inlined]
 [27] transduce_assoc(xform::Transducers.Map{…}, step::Transducers.Completing{…}, init::InitialValues.InitialValueOf{…}, coll0::Base.Iterators.Zip{…}; simd::Val{…}, basesize::Int64, stoppable::Nothing, nestlevel::Nothing)
    @ Transducers /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/reduce.jl:108
 [28] transduce_assoc
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/reduce.jl:84 [inlined]
 [29] #foldxt#184
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Transducers/IAWgA/src/reduce.jl:235 [inlined]
 [30] mapreduce(f::Function, op::Function, itr::Base.Iterators.Zip{Tuple{…}}; kw::@Kwargs{simd::Val{…}})
    @ ThreadsX.Implementations /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/ThreadsX/Bml38/src/reduce.jl:19
 [31] mapreduce
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/ThreadsX/Bml38/src/reduce.jl:17 [inlined]
 [32] sum
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/ThreadsX/Bml38/src/reduce.jl:48 [inlined]
 [33] _update_ebes_and_evaluate_marginal_nll_gradient_threads!(g::Vector{…}, m::PumasModel{…}, population::Vector{…}, param::@NamedTuple{…}, vparam::Vector{…}, vvrandeffs::Vector{…}, vvrandeffs_tmp::Vector{…}, approx::FOCE{…}, trf::TransformVariables.TransformTuple{…}, diffeq_options::@NamedTuple{})
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:3510
 [34] (::Pumas.var"#611#615"{…})(f::Float64, g::Vector{…}, _vparam::Vector{…})
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:4556
 [35] _optim_check_initial_values(costf::Pumas.var"#611#615"{…}, vparam::Vector{…}, verbose::Bool)
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:4449
 [36] _fit(m::PumasModel{…}, population::Vector{…}, param::@NamedTuple{…}, approx::FOCE{…}, ensemblealg::EnsembleThreads, optimize_fn::Pumas.DefaultOptimizeFN{…}, fixedparamset::ParamSet{…}, fixedparam::@NamedTuple{…}, checkidentification::Bool, diffeq_options::@NamedTuple{}, init_vrandeffsorth::Vector{…}, verbose::Bool, ignore_numerical_error::Bool, optim_state::Nothing)
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:4622
 [37] __fit
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:4331 [inlined]
 [38] __fit
    @ /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:4318 [inlined]
 [39] fit(m::PumasModel{…}, population::Vector{…}, param::@NamedTuple{…}, approx::FOCE{…}; optim_alg::Nothing, optim_options::Nothing, optimize_fn::Nothing, constantcoef::Tuple{}, omegas::Tuple{}, ensemblealg::EnsembleThreads, checkidentification::Bool, diffeq_options::@NamedTuple{}, init_randeffs::Nothing, init_vrandeffsorth::Nothing, verbose::Bool, ignore_numerical_error::Bool)
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:4285
 [40] fit(m::PumasModel{…}, population::Vector{…}, param::@NamedTuple{…}, approx::FOCE{…})
    @ Pumas /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/Pumas/GJfPM/src/estimation/likelihoods.jl:4231
Some type information was truncated. Use `show(err)` to see complete types.

```

Best regards

---

<div class="post-metadata">

**Author:** ![patrick](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/patrick/32/206_2.png) [@patrick](https://discourse.pumas.ai/u/patrick)\
**Post date:** [March 6, 2025, 12:21pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/8 "2025-03-06T12:21:20Z")

</div>

> [@Aleem](#):
>
> `RF = exp(TRF + η_RF) / (1 + exp(TRF + η_RF))`

This is because you are summing TRF and η\_RF which is a number and a vector respectively. Either write η\_RF[1] or rewrite η\_RF to be a scalar distribution (Normal instead of MvNormal).

---

<div class="post-metadata">

**Author:** ![Aleem](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@Aleem](https://discourse.pumas.ai/u/Aleem)\
**Post date:** [March 6, 2025, 2:12pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/9 "2025-03-06T14:12:34Z")

</div>

Hi Patrick,

Thanks for your help!

Then the error became

```auto
ERROR: UndefVarError: `ILS` not defined

```

I tried define it in the @coviariates, but it did not work.

The model structure now is ,

```auto

# Define the model
model = @model begin
    @param begin
        TRF ∈ RealDomain(lower=-Inf, upper=Inf, init = -2.0)
        TG ∈ RealDomain(lower=-Inf, upper=Inf, init = -7.0)
        TD ∈ RealDomain(lower=-Inf, upper=Inf, init = -4.0)
        add_err ∈ RealDomain(lower=0, upper=10, init = 0.1)
        prop_err ∈ RealDomain(lower=0, upper=10, init = 0.1)
    end

    @random begin
        η_RF ~ Normal(0, 0.1)
    end

    @covariates ILS

    @pre begin
        RF = exp(TRF + η_RF) / (1 + exp(TRF + η_RF))
        G = exp(TG)
        D = exp(TD)
        CL = 92.2
        Q = 125
        V1 = 17.5
        V2 = 47.4
        Vmax = 2
        Km = 0.0075
        k30 = log(2) / 12
        k10 = CL / V1
        k12 = Q / V1
        k21 = Q / V2
    end

    @init begin
        C = 0
        P = 0
        Cin = 0
        Lsen = ILS - ILS * RF # Use ILS from the dataset
    end

    @dynamics begin
        C' = -(k12 + k10) * C + k21 * P
        P' = k12 * C - k21 * P
        Cin' = Vmax * (C / V1) / (Km + C / V1) - k30 * Cin
        Lsen' = G * Lsen - D * Lsen * Cin
    end

    @derived begin
        LS = @. Lsen + ILS * RF * exp(G * time) # Compute LS (lesion size)
        DV ~ @. Normal(LS, sqrt(add_err^2 + (prop_err * LS)^2))
    end
end

# Create the population object
pop = read_pumas(Dat;
                 id = :ID,
                 time = :TIME,
                 observations = [:DV],
                 covariates = [:ILS], # Include ILS (initial lesion size) as a covariate
                 amt = :AMT,
                 evid = :EVID,
                 cmt = :CMT,
                 rate = :RATE
)

# Fit the model
fit1 = fit(model, pop, init_params(model), FOCE())

```

Best wishes

---

<div class="post-metadata">

**Author:** ![patrick](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/patrick/32/206_2.png) [@patrick](https://discourse.pumas.ai/u/patrick)\
**Post date:** [March 6, 2025, 7:43pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/10 "2025-03-06T19:43:25Z")

</div>

```auto
# Define the model
model = @model begin
    @param begin
        TRF ∈ RealDomain(lower=-Inf, upper=Inf, init = -2.0)
        TG ∈ RealDomain(lower=-Inf, upper=Inf, init = -7.0)
        TD ∈ RealDomain(lower=-Inf, upper=Inf, init = -4.0)
        add_err ∈ RealDomain(lower=0, upper=10, init = 0.1)
        prop_err ∈ RealDomain(lower=0, upper=10, init = 0.1)
    end

    @random begin
        η_RF ~ Normal(0, 0.1)
    end

    @covariates ILS

    @pre begin
        RF = exp(TRF + η_RF) / (1 + exp(TRF + η_RF))
        G = exp(TG)
        D = exp(TD)
        CL = 92.2
        Q = 125
        V1 = 17.5
        V2 = 47.4
        Vmax = 2
        Km = 0.0075
        k30 = log(2) / 12
        k10 = CL / V1
        k12 = Q / V1
        k21 = Q / V2
        ils = ILS
    end

    @init begin
        C = 0
        P = 0
        Cin = 0
        Lsen = ils*(1 - RF) # Use ILS from the dataset
    end

    @dynamics begin
        C' = -(k12 + k10) * C + k21 * P
        P' = k12 * C - k21 * P
        Cin' = Vmax * (C / V1) / (Km + C / V1) - k30 * Cin
        Lsen' = G * Lsen - D * Lsen * Cin
    end

    @derived begin
        LS = @. Lsen + ILS * RF * exp(G * time) # Compute LS (lesion size)
        DV ~ @. Normal(LS, sqrt(add_err^2 + (prop_err * LS)^2))
    end
end

```

Please try the above where the covariate is defined in `@pre` with a new name. Covariates are currently not automatically available in `@init`, but we will track this as a potential improvement to Pumas.

---

<div class="post-metadata">

**Author:** ![Aleem](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@Aleem](https://discourse.pumas.ai/u/Aleem)\
**Post date:** [March 6, 2025, 9:22pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/11 "2025-03-06T21:22:06Z")

</div>

Thanks. Then the error became

```auto
[ Info: Checking the initial parameter values.
ERROR: MethodError: no method matching *(::Float64, ::typeof(time))

Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...)
   @ Base operators.jl:587
  *(::Real, ::Symbolics.ComplexTerm)
   @ Symbolics /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/SymbolicUtils/c0xQb/src/methods.jl:74
  *(::Number, ::Symbolics.ComplexTerm)
   @ Symbolics /Users/build/self-hosted-runners/macos_intel/on-the-machine/runner/_work/PumasSystemImages/PumasSystemImages/julia_depot/packages/SymbolicUtils/c0xQb/src/methods.jl:76
  ...

```

My code now is:

```auto
# Define the model
model = @model begin
    @param begin
        TRF ∈ RealDomain(lower=-10, upper=10, init = -2.0)
        TG ∈ RealDomain(lower=-10, upper=10, init = -7.0)
        TD ∈ RealDomain(lower=-10, upper=10, init = -4.0)
        add_err ∈ RealDomain(lower=0, upper=10, init = 0.1)
        prop_err ∈ RealDomain(lower=0, upper=10, init = 0.1)
    end

    @random begin
        η_RF ~ Normal(0, 0.1)
    end

    @covariates ILS

    @pre begin
        RF = exp(TRF + η_RF) / (1 + exp(TRF + η_RF))
        G = exp(TG)
        D = exp(TD)
        CL = 92.2
        Q = 125
        V1 = 17.5
        V2 = 47.4
        Vmax = 2
        Km = 0.0075
        k30 = log(2) / 12
        k10 = CL / V1
        k12 = Q / V1
        k21 = Q / V2
        ils = ILS
    end

    @init begin
        C = 0
        P = 0
        Cin = 0
        Lsen = ils * (1 - RF) # Use ILS from the dataset
    end

    @dynamics begin
        C' = -(k12 + k10) * C + k21 * P
        P' = k12 * C - k21 * P
        Cin' = Vmax * (C / V1) / (Km + C / V1) - k30 * Cin
        Lsen' = G * Lsen - D * Lsen * Cin
    end

    @derived begin
        LS = @. Lsen + ils * RF * exp(G * time) # Compute LS (lesion size)
        DV ~ @. Normal(LS, sqrt(add_err^2 + (prop_err * LS)^2))
    end
end

# Create the population object
pop = read_pumas(pancreasDat;
                 id = :ID,
                 time = :TIME,
                 observations = [:DV],
                 covariates = [:ILS], # Include ILS (initial lesion size) as a covariate
                 amt = :AMT,
                 evid = :EVID,
                 cmt = :CMT,
                 rate = :RATE
)

# Fit the model
fit1 = fit(model, pop, init_params(model), FOCE())

```

I changed all the ILS to ils here. I changed time to TIME but still got error, so then I changed it back. it seems that it cant detect time and then mutiply still?

Best wishes

---

<div class="post-metadata">

**Author:** ![patrick](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/patrick/32/206_2.png) [@patrick](https://discourse.pumas.ai/u/patrick)\
**Post date:** [March 6, 2025, 9:48pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/12 "2025-03-06T21:48:53Z")

</div>

You are looking for the reserved keyword `t` I believe. Please find the information on how to use time in the documentation of `@pre` ! [Defining NLME models in Pumas · Pumas](https://docs.pumas.ai/stable/basics/models/#@pre:-Pre-processing-of-input-to-dynamics-and-derived)

---

<div class="post-metadata">

**Author:** ![patrick](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/patrick/32/206_2.png) [@patrick](https://discourse.pumas.ai/u/patrick)\
**Post date:** [March 7, 2025, 5:41am UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/13 "2025-03-07T05:41:49Z")

</div>

Actually, as we went through the process internally, we came to the conclusion that this already works on the latest version of Pumas. Can you verify what version of Pumas you are using?

---

<div class="post-metadata">

**Author:** ![Aleem](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@Aleem](https://discourse.pumas.ai/u/Aleem)\
**Post date:** [March 7, 2025, 2:31pm UTC](https://discourse.pumas.ai/t/fitting-error-of-a-tumor-growth-model/1147/14 "2025-03-07T14:31:51Z")

</div>

Thanks a lot! It worked and fast enough 😀
