# Simulating TTE Model

**URL:** <https://discourse.pumas.ai/t/simulating-tte-model/571>\
**Category:** Simulation\
**Created:** [January 2, 2022, 1:03am UTC](https://discourse.pumas.ai/t/simulating-tte-model/571 "2022-01-02T01:03:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![skalaria](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@skalaria](https://discourse.pumas.ai/u/skalaria)\
**Post date:** [January 2, 2022, 1:03am UTC](https://discourse.pumas.ai/t/simulating-tte-model/571/1 "2022-01-02T01:03:57Z")

</div>

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:

```auto
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

```auto
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

---

<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:** [January 2, 2022, 1:34am UTC](https://discourse.pumas.ai/t/simulating-tte-model/571/2 "2022-01-02T01:34:14Z")

</div>

Welcome to the community, Shamir!

> [@skalaria](#):
>
> ```auto
> 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)
> 
> ```

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

```julia
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: MethodError`usually indicates that you passed the wrong arguments to a function. Look at a simple example below

```julia
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!

---

<div class="post-metadata">

**Author:** ![skalaria](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@skalaria](https://discourse.pumas.ai/u/skalaria)\
**Post date:** [January 2, 2022, 4:40am UTC](https://discourse.pumas.ai/t/simulating-tte-model/571/3 "2022-01-02T04:40:54Z")

</div>

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

```auto
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](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/ee9b48877f3930662ca2ca2ee7d229cfc7536bd4.png)

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

```auto
##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

---

<div class="post-metadata">

**Author:** ![benjaminrich](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/benjaminrich/32/156_2.png) [@benjaminrich](https://discourse.pumas.ai/u/benjaminrich)\
**Post date:** [January 3, 2022, 4:22pm UTC](https://discourse.pumas.ai/t/simulating-tte-model/571/4 "2022-01-03T16:22:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![skalaria](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@skalaria](https://discourse.pumas.ai/u/skalaria)\
**Post date:** [January 3, 2022, 10:27pm UTC](https://discourse.pumas.ai/t/simulating-tte-model/571/6 "2022-01-03T22:27:18Z")

</div>

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
