Model fitting giving error: gradient is exactly zero in θtd50

Hello,

Everyone on this is very quick to respond. Thank you for your help!

I am working on fitting an infusion model to a population.
The code works until I try to fit the simulated population where it gives me the error: gradient is exactly zero in θtd50. I am not sure why I would see this sort of errror.

Here is my model:

# Practice developing infusion model using Pumas
using Random, Pumas, PumasUtilities, CairoMakie, AlgebraOfGraphics, DataFramesMeta, DataFrames, CSV

## Model definition infusion
model_infusion = @model begin
    @metadata begin
        desc = "Dissolution model Infusion"
        timeu = u"minute"
    end
    @param begin
        "Maximum percent drug dissolved (percent)"
        θfdissmax ∈ RealDomain(lower=0)
        "Time required for 50 percent of the drug to dissolve (minutes)"
            θtd50 ∈ RealDomain(lower=0)
        "Additive RUV"
             σadd ∈ RealDomain(lower=0)
        "sigmoidicity factor"
           θkdiss ∈ RealDomain(lower=0)
    end
    @covariates dtd50
    @pre begin
         fdissmax = θfdissmax
             td50 = θtd50 * (1 + dtd50)
            kdiss = θkdiss
    end
    @derived begin
        fdiss = @. fdissmax * (1 - exp(-kdiss*t))
        """
        Percent dissolved in vitro
        """
        dv_fdiss ~ @. Normal(fdiss, σadd)
        
    end
end

## Initial parameters
param_infusion = (θfdissmax = 90.0, θtd50 = 30, σadd = 0.01, θkdiss = 0.1)

## Creating a Dataset
df_pop_infusion = map(i -> DataFrame(id = i, time = 1:1:120, dv_fdiss = missing, dtd50=0), 1:6)
df = vcat(DataFrame.(df_pop_infusion)...)
df[!, :dtd50] = ifelse.(df.id .== 2, -0.5, df.dtd50)
df[!, :dtd50] = ifelse.(df.id .== 3, 0.5, df.dtd50)
df[!, :dtd50] = ifelse.(df.id .== 4, 1, df.dtd50)
df[!, :dtd50] = ifelse.(df.id .== 5, 2, df.dtd50)
df[!, :dtd50] = ifelse.(df.id .== 6, 3, df.dtd50)
df_pop_infusion = df
pop_infusion = read_pumas(df_pop_infusion, observations=[:dv_fdiss], covariates=[:dtd50], event_data=false)

##Simulation
Random.seed!(1234)
sim_infusion = simobs(model_infusion, pop_infusion, param_infusion)
df_sim_infusion = DataFrame(sim_infusion) ### Change to dataframe from saving

##Estimation
@time est_infusion = fit(model_infusion, Subject.(sim_infusion), param_infusion, Pumas.NaivePooled())

As you are initializing the parameters with the true values, the fit will error as the initial likelihood will be infinity. Before fit, change the initial parameters to some different values and the fit shouldn’t error

I am sorry, my previous understanding was wrong. After second thought, I realized you are getting the error because the θtd50 parameter is not being used in generating the data and therefore, the fit is unable to find the most optimal value for the parameter. Remove θtd50 parameter from the @param and @pre block in your model and also from param_infusion.

Notice that the td50 parameter isn’t used anywhere and since it’s the only place where θtd50 is being used the θtd50 isn’t entering the likelihood function and hence it’s not identified.

Best
Andreas

ons. 29. jun. 2022 kl. 00.24 skrev Kevin Tobin via Pumas <notifications@pumas.discoursemail.com>:

Thank you that was the issue!