# I almost run same codes but got two different plots while simulating , may i know how it happen

**URL:** <https://discourse.pumas.ai/t/i-almost-run-same-codes-but-got-two-different-plots-while-simulating-may-i-know-how-it-happen/65>\
**Category:** Simulation\
**Created:** [November 13, 2019, 8:09am UTC](https://discourse.pumas.ai/t/i-almost-run-same-codes-but-got-two-different-plots-while-simulating-may-i-know-how-it-happen/65 "2019-11-13T08:09:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sai\_matcha](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/sai_matcha/32/297_2.png) [@sai\_matcha](https://discourse.pumas.ai/u/sai_matcha)\
**Post date:** [November 13, 2019, 8:09am UTC](https://discourse.pumas.ai/t/i-almost-run-same-codes-but-got-two-different-plots-while-simulating-may-i-know-how-it-happen/65/1 "2019-11-13T08:09:25Z")

</div>

1 st run

```auto
mymodel = @model begin
    @param begin
      tvcl ∈ RealDomain(lower=0, init = 1)
      tvv1 ∈ RealDomain(lower=0, init = 40)
      tvv2 ∈ RealDomain(lower=0, init= 100)
      tvq ∈ RealDomain(lower=0, init=3)
      σ_prop ∈ RealDomain(lower = 0, init= 0.04)
      #Ω ∈ PDiagDomain( init = [0.09])
     end

  @random begin
    η ~ MvNormal(Matrix{Float64}(0.09I, 1, 1))
  end

  @pre begin
    CL = tvcl * exp(η[1])
    V1 = tvv1
    V2 = tvv2
    Q = tvq

  end
  #@covariates Wt

    @dynamics begin
        Central' = - (CL/V1)*Central + Q*(Peripheral/V2) - Q*(Central/V1)
        Peripheral' = Q*(Central/V1) - Q*(Peripheral/V2)
    end
    @vars begin
        cent= Central/V1
        Perip=Peripheral/V2
end
  @derived begin
      conc = cent
      dv ~ @. Normal(conc, sqrt(conc^2*σ_prop)+eps())
    end
end
param= init_param(mymodel)
data = CSV.read("D:\\NONMEMnights\\mould\\julia\\12.3.2\\2comp_iv_data.csv", missingstring=".")
Newdata = read_pumas(data,id=:id, time=:TIME, dvs=[:dv])
sim=simobs(mymodel, Newdata, param)
plot(sim)
![arun1|493x318](upload://y36mTTNyHbZihWwsbCExwXPC1QU.png) 

```

2nd run

```auto
md = CSV.read("D:\\NONMEMnights\\mould\\julia\\12.3.2\\2comp_iv_data.csv", missingstring=".")

trans = read_pumas(md, id=:id, time=:TIME, dvs=[:dv],)

dian = @model begin
  @param begin
    tvcl ∈ RealDomain(lower=0, init = 1.0)
    tvv ∈ RealDomain(lower=0, init = 20)
    tvQ ∈ RealDomain(lower = 0, init= 1)
    tvv2 ∈ RealDomain(lower = 0, init = 100)
    Ω ∈ PDiagDomain(init=[0.09])
    σ_prop ∈ RealDomain(lower=0,init=0.04)
  end
#end
  @random begin
# η ~ MvNormal(Matrix{Float64}(0.01I, 1, 1))
η ~ MvNormal(Ω)
    #η ~ MvNormal(Ω)
  end
#end
  @pre begin
    CL = tvcl * exp(η[1])
    V = tvv
    V2 = tvv2
    Q = tvQ
  end
#end
 #@covariates WT
#end
  #@dynamics ImmediateAbsorptionModel
    @dynamics begin
        # Depot' = -Ka*Depot
            Central' = Q*(Peripheral/V2) - (CL/V)*Central - Q*(Central/V)

         Peripheral' = Q*(Central/V)-Q*(Peripheral/V2)
    end
#end
@vars begin
       Cent := Central/V
       Peri := Peripheral/V2
   end
  @derived begin
      cp = Cent
     # dv ~ @. Normal(cp,sqrt(cp^2*σ_prop))
      dv ~ @. Normal(cp, sqrt(cp^2*σ_prop)+eps())
    end
end

param =init_param(dian)

sims = simobs(dian,trans,param)
plot(sims)
![run2|576x361](upload://2PWmTP5WIBeDN8r0gG8p9l9ibqU.png) 

```

---

<div class="post-metadata">

**Author:** ![sai\_matcha](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/sai_matcha/32/297_2.png) [@sai\_matcha](https://discourse.pumas.ai/u/sai_matcha)\
**Post date:** [November 13, 2019, 8:10am UTC](https://discourse.pumas.ai/t/i-almost-run-same-codes-but-got-two-different-plots-while-simulating-may-i-know-how-it-happen/65/2 "2019-11-13T08:10:53Z")

</div>

![arun1](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/eea3b3e40c7bb3859587eeef418f7f064c6bdbf4.png) 1st run  
 ![run2](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/13e371c5835054e40ee300f6c4e38cbdb02a14d0.png) 2nd run

---

<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:** [November 13, 2019, 10:49am UTC](https://discourse.pumas.ai/t/i-almost-run-same-codes-but-got-two-different-plots-while-simulating-may-i-know-how-it-happen/65/3 "2019-11-13T10:49:53Z")

</div>

Dear Sai,

In a Pumas model, whatever variables are generated/assigned in the `@vars` block, `@observed` and `@derived` block make it to the output of the model when simulating (think of it like $TABLE in NM).

The fundamental reason for the difference in output is the way you specified the `@vars` block. In the first run, you had the variables in the `@vars` block being assigned with a `=`, but in the second one they are being assigned with `:=`. You can read about the difference here [https://docs.pumas.ai/dev/basics/models/#@vars:-Variable-Aliases-1](https://docs.pumas.ai/dev/basics/models/#@vars:-Variable-Aliases-1). But essentially anything aliased with a `:=` does not get carried to the output. Hence you did not get a plot.

with regards to the difference in concentrations levels, since this is a simulation, we can say that the difference in concentration levels is random (but in the same ballpark)

---

<div class="post-metadata">

**Author:** ![sai\_matcha](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/sai_matcha/32/297_2.png) [@sai\_matcha](https://discourse.pumas.ai/u/sai_matcha)\
**Post date:** [November 13, 2019, 12:43pm UTC](https://discourse.pumas.ai/t/i-almost-run-same-codes-but-got-two-different-plots-while-simulating-may-i-know-how-it-happen/65/4 "2019-11-13T12:43:54Z")

</div>

Thankyou Vijay

Saikumar Matcha
