Simulating TTE Model

Hello,

I am trying to simulate from a TTE model I created. However, I keep getting the error message below:
“LoadError: MethodError: no method matching simobstte(::Pumas.FittedPumasModel”

This my model code:

brain_tte_exp_trt_sex = @model begin
  @param begin
    λ₁    ∈ RealDomain(lower=0)
    β_comb ∈ RealDomain(lower=-10)
    β_drug ∈ RealDomain(lower=-10)
    β_male ∈ RealDomain(lower=-10)
  end
  @covariates TRT SEX
  @pre begin
    _λ₀ = λ₁*exp((TRT == "COMB")*β_comb +  (TRT == "DRUG_X")*β_drug) * exp((SEX == "Male")*β_male)
  end
  @vars begin
    λ =  _λ₀ 
  end
  @dynamics begin
    Λ' = λ
  end
  @derived begin
    STATUS ~ @. TimeToEvent(λ, Λ)
  end
end

ft_brain_tte_exp_trt_sex = fit(brain_tte_exp_trt_sex,
               brain_tte,
               brain_tte_param,
               Pumas.NaivePooled())

This is my simulation code. I am trying to simulate a dataset that includes event data up to 1000 days for each subject. I have an data frame (brain_sim_data) with Subject ID, the relevant covariates, and empty columns for TIME and STATUS

dropout_sims = simobstte(ft_brain_tte_exp_trt_sex,
                   coef(ft_brain_tte_exp_trt_sex),
                   brain_data_sim,
                   NamedTuple();
                  minT = 0, maxT=1000, nT = 10, repeated=false)

Also, is there a way to output the cumulative hazard without actually running simulations? And if not, how can I output the cumulative hazard.
This is my first time in a while using Pumas, so apologies if I am missing something simple!

Regards,
Shamir

Welcome to the community, Shamir!

You are passing in your fitted object as the first argument, can you instead try to pass in your model as the first argument?

dropout_sims = simobstte(brain_tte_exp_trt_sex,
                   coef(ft_brain_tte_exp_trt_sex),
                   brain_data_sim,
                   NamedTuple();
                  minT = 0, maxT=1000, nT = 10, repeated=false)

The error message which has with LoadError: MethodErrorusually indicates that you passed the wrong arguments to a function. Look at a simple example below

julia> f(a, b) = a + b
f (generic function with 1 method)

julia> f(2, 3)
5

julia> f(2, "hello")
ERROR: MethodError: no method matching +(::Int64, ::String)
Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...) at operators.jl:560
  +(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} at int.jl:87
  +(::Union{Int16, Int32, Int64, Int8}, ::BigInt) at gmp.jl:534
  ...
Stacktrace:
 [1] f(a::Int64, b::String)
   @ Main ./REPL[1]:1
 [2] top-level scope
   @ REPL[3]:1

Hope that helps!

Thanks Vijay for that insight; that definitely makes sense! Unfortunately when I passed the model object first, I still get the following error:

LoadError: MethodError: no method matching simobstte(::PumasModel{ParamSet{NamedTuple{(:λ₁, :Κ, :β_comb, :β_drug, :β_male, :β_ecog), NTuple{6, RealDomain{Int64, TransformVariables.Infinity{true}, Int64}}}}, var"#33#47", var"#34#48", var"#36#50", var"#38#52", ODEProblem{Nothing, Tuple{Nothing, Nothing}, false, Nothing, ODEFunction{false, ModelingToolkit.ODEFunctionClosure{var"#39#53", var"#40#54"}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Vector{Symbol}, Symbol, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, var"#41#55", var"#44#58", ModelingToolkit.ODESystem}, ::Vector{Subject{NamedTuple{(:STATUS,), Tuple{Vector{Union{Missing, Float64}}}}, Pumas.ConstantCovar{NamedTuple{(:SEX, :TRT, :PH_ECOG_cat), Tuple{String, String, String}}}, Vector{Pumas.Event{Float64, Float64, Float64, Float64, Float64, Float64, Int64}}, Vector{Float64}}}, ::NamedTuple{(:λ₁, :Κ, :β_comb, :β_drug, :β_male, :β_ecog), NTuple{6, Float64}}, ::NamedTuple{(), Tuple{}}; maxT=1095, nT=100, repeated=false)
Closest candidates are:
  simobstte(::PumasModel, ::Subject, ::NamedTuple, ::Union{Nothing, NamedTuple}; minT, maxT, nT, repeated, rng, diffeq_options) at /builds/PumasAI/PumasSystemImages-jl/.julia/packages/Pumas/XHa5R/src/estimation/likelihoods.jl:181
  simobstte(::PumasModel, ::AbstractVector{T} where T<:Subject, ::NamedTuple) at /builds/PumasAI/PumasSystemImages-jl/.julia/packages/Pumas/XHa5R/src/estimation/likelihoods.jl:281 got unsupported keyword arguments "maxT", "nT", "repeated"
  simobstte(::PumasModel, ::AbstractVector{T} where T<:Subject, ::NamedTuple, ::Vector{var"#s55"} where var"#s55"<:NamedTuple; rng, minT, maxT, repeated, diffeq_options) at /builds/PumasAI/PumasSystemImages-jl/.julia/packages/Pumas/XHa5R/src/estimation/likelihoods.jl:267 got unsupported keyword argument "nT"

I think there maybe something wrong with my “population” dataset. This is what the dataset looks like:
image

This is the code I am reading in the dataset and identifying the necessary variables:

##Simulation for Validation
brain_data_sim = DataFrame(CSV.File("/mnt/data/code/PHAR758_project/data/brain_data_sim.csv";missingstring = ""))
brain_sim_tte = read_pumas(brain_data_sim,
    id = :USUBJID, time = :TIME,
    observations = [:STATUS],
    covariates = [:SEX, :TRT],
    event_data=false)
    
### dropout simulation
dropout_sims = simobstte(brain_tte_wei_trt,
                   brain_sim_tte,
                   coef(ft_brain_tte_wei_trt),
                   NamedTuple();
                   maxT=1095, nT = 100, repeated=false)

Thanks again for all your help!

~Shamir

Could you try removing the nt = 100 argument and see what happens?

Thanks Benjamin for the advice! I was able to run the code and get a simulated dataset.

In this dataset, I only had one observed time and all subjects were listed to have an event. I am assuming this is because we removed nT=100? If I wanted to get an output that is more longitudinal, does my input dataset have to have multiple rows (time = (0,10,20,30, etc). per subject?

Also, is there anyway to output the cumulative hazard in addition to the event times?

Thanks,
Shamir