# Different plots on same code

**URL:** <https://discourse.pumas.ai/t/different-plots-on-same-code/140>\
**Category:** Simulation\
**Created:** [February 10, 2020, 7:32am UTC](https://discourse.pumas.ai/t/different-plots-on-same-code/140 "2020-02-10T07:32:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aishwarya](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Aishwarya](https://discourse.pumas.ai/u/Aishwarya)\
**Post date:** [February 10, 2020, 7:32am UTC](https://discourse.pumas.ai/t/different-plots-on-same-code/140/1 "2020-02-10T07:32:59Z")

</div>

On copying the same codes and running the simulation in another window, I tend to get different outputs.

```auto
using Pumas
using Plots
myfirstmodelinpumas = @model begin
    @param begin
        tvka ∈ RealDomain(lower=0)
        tvcl ∈ RealDomain(lower=0)
        tvvc ∈ RealDomain(lower=0)
        tvvp ∈ RealDomain(lower=0)
        tvQ ∈ RealDomain(lower=0)
        Ω ∈ PDiagDomain(5)
        σ_prop ∈ RealDomain(lower=0)
    end

    @random begin
      η ~ MvNormal(Ω)
    end

    @pre begin
        CL = tvcl * exp(η[1])
        Vc = tvvc * exp(η[2])
        Ka = tvka * exp(η[3])
        Q = tvQ * exp(η[4])
        Vp = tvvp * exp(η[5])
    end

     @dynamics begin
         depot' = -Ka*depot
         central' = Ka*depot - (CL/Vc)*central + (Q/Vp)*peripheral - (Q/Vc)*central
         peripheral' = -(Q/Vp)*peripheral + (Q/Vc)*central
     end

    @derived begin
        cp = @. central/Vc
        dv ~ @. Normal(cp, sqrt(cp*σ_prop^2))
    end
end

para = (tvka = 1,
          tvcl = 12.0,
          tvvc = 77.1,
          tvvp = 52.3,
          tvQ = 9.22,
          Ω = Diagonal([0.09,0.09,0.09,0.09,0.09]),
          σ_prop = 0.04)
          
evoral = DosageRegimen(120, time=0, cmt=1, ii=12, addl=5)
eviva = DosageRegimen(60, rate=40, time=1, cmt=2)
evcom = DosageRegimen(evoral, eviva)
ssotalol = Subject(id=1, evs=evcom)
obssotalol = simobs(myfirstmodelinpumas, ssotalol, para, obstimes=0:1:120)
plot(obssotalol)

```

 ![pumas 1](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/ce7c6d012de8a56ac3b03c58239f38545a7881c0.jpeg)  
 ![pumas 2](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/70563984df3e364b609ee0a99e0bab25654aeb28.jpeg)  
why does that happen?

---

<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:** [February 10, 2020, 8:23am UTC](https://discourse.pumas.ai/t/different-plots-on-same-code/140/2 "2020-02-10T08:23:41Z")

</div>

This happens because you haven’t specified the random effects. In that case, the random effects are drawn randomly and the simulated will therefore be different for each time you invoke the `simobs` functions. Hence, it’s not related to extra window.

---

<div class="post-metadata">

**Author:** ![Aishwarya](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Aishwarya](https://discourse.pumas.ai/u/Aishwarya)\
**Post date:** [February 10, 2020, 9:22am UTC](https://discourse.pumas.ai/t/different-plots-on-same-code/140/3 "2020-02-10T09:22:58Z")

</div>

Got it.  
Are there ways by which I can reduce the variability in the output.  
Or including a function that could fix a range to my random effects.?

---

<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:** [February 10, 2020, 9:33am UTC](https://discourse.pumas.ai/t/different-plots-on-same-code/140/4 "2020-02-10T09:33:18Z")

</div>

You can pass the exact random effects you want to use in the simulation. It’s the (optional) fourth argument to `simobs`. Hence, something like

```auto
obssotalol = simobs(myfirstmodelinpumas, ssotalol, para, (η=zeros(5),), obstimes=0:1:120)

```

would fix them all to zero and the top plots (cp) should be identical across invocations.

Alternatively, you can fix the global seed with

```auto
using Random
Random.seed!(SOMESEEDINTEGER)

```

Notice, that you’d also need to disable multithreading in `simobs` with the `ensemblealg = EnsembleSerial()` keyword argument if you want the simulation to be reproducible.

---

<div class="post-metadata">

**Author:** ![Aishwarya](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Aishwarya](https://discourse.pumas.ai/u/Aishwarya)\
**Post date:** [February 10, 2020, 9:47am UTC](https://discourse.pumas.ai/t/different-plots-on-same-code/140/5 "2020-02-10T09:47:25Z")

</div>

That answered my question.!  
Thanks Andreas.! 🙂
