# Fitting multiple observalbles

**URL:** <https://discourse.pumas.ai/t/fitting-multiple-observalbles/102>\
**Category:** Estimation\
**Created:** [December 17, 2019, 6:07pm UTC](https://discourse.pumas.ai/t/fitting-multiple-observalbles/102 "2019-12-17T18:07:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alewolf](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/alewolf/32/24_2.png) [@alewolf](https://discourse.pumas.ai/u/alewolf)\
**Post date:** [December 17, 2019, 6:07pm UTC](https://discourse.pumas.ai/t/fitting-multiple-observalbles/102/1 "2019-12-17T18:07:21Z")

</div>

I have a data set with multiple observable values:  
Ctot, Cfree, and Blocker

Leaving Blocker out for the time being. My dose doses Ctot and Cfree is supposed to be a diminishing fraction of Ctot.

I built a simple model -

```auto

WhyDrop = @model begin

    @param begin
        
      θ ∈ RealDomain(lower=0.0001,init=1, upper=200000) 
      Ω ∈ RealDomain(init=0.09)
      σ_prop ∈ RealDomain(init=0.09, lower=0.01, upper=1)
    end

    @random begin
      η ~ Normal(Ω)
    end

    @pre begin
        k = θ[1]*exp(η[1])
    end
    
    @covariates begin
        CLS
        V1S
    end

    @init begin
        X = 1
    end

    @dynamics begin
        a1' = -CLS*ctot
        X' = -k*X            
     end
    
    @vars begin
        ctot := a1/V1S
        cfree:= X*ctot
    end
    
    @derived begin
        A1 = a1
        Cfree = cfree
        
        Ctot ~ @.Normal(ctot,sqrt(ctot^2*σ_prop+ eps()))  
        dv ~ @.Normal(Cfree,sqrt(Cfree^2*σ_prop+ eps()))
        
    end
end

```

My Pumas\_data is generated as:

```auto
dfP1=read_pumas(df9 ,id=:Subject, evid=:evid, time=:Time,amt=:Dosenmol, cmt=:cmt, rate=:Ratenmolday, cvs=[:CLS,:V1S], dvs=[:Ctot,:dv])

```

My question are simple:

1. How do I make sure my dose is applied to Ctot and not Cfree? I tried to define a :cmt in the df9 filling it with a1 instead of numbers but readPumas requires an integer. Is there any way to ensure that the dose goes to a1, other than making a1 the first equation?

2. I assume that fitting will be do by matching column names in the PumasFrame to the name of variable in the model? Is there anything else that I need to do to ensure that the data is matching to the right model variable when I have more than one observable?

Finally, whem I try to fit the model.  
Using BayesMCMC() yieds result, but using FOCEI() or LapalceI() results in error:

```auto

param5=init_param(SEABCMAWhy5)
res5 = fit(SEABCMAWhy5,dfP1,param5,Pumas.LaplaceI())

```

PosDefException: matrix is not positive definite; Cholesky factorization failed.  
Is this due to multiple observables? The documentations says LaplaceI should work, but it gives the same error as FOCEI.

Thanks,

A

---

<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:** [December 18, 2019, 3:34am UTC](https://discourse.pumas.ai/t/fitting-multiple-observalbles/102/2 "2019-12-18T03:34:23Z")

</div>

You can specify the `cmt` as a `Symbol` and not just a number (see below, `cmt = :a1`). This allows you to keep the ordering of the `@dyanmics` independent of the `cmt` numbering. Using your model above, I added the following lines of code (note the dose and covariate values are arbitrary numbers). You can check with this simulation and try different options out to see what works for you.

```auto
s1 = Subject(id=1, evs=DosageRegimen(100,cmt=:a1), cvs=(CLS=1,V1S=1))
param5=init_param(WhyDrop)
sims = simobs(WhyDrop, s1, param5)

plot(sims)

```

---

<div class="post-metadata">

**Author:** ![alewolf](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/alewolf/32/24_2.png) [@alewolf](https://discourse.pumas.ai/u/alewolf)\
**Post date:** [December 18, 2019, 6:04pm UTC](https://discourse.pumas.ai/t/fitting-multiple-observalbles/102/3 "2019-12-18T18:04:09Z")

</div>

So - this works well in this case, but does not seems to work well when I do:

```auto
sims5=simobs(Whydrop,dfP1)

```

because dfP1 can not be built using symbol for “:cmt”

```auto
df9.Dosenmol = df9.Dosemg.*(1E9/150E6)#./20
df9.Ratenmolday = df9.Ratemgday.*(1E9/150E6)
df9.SEABCMAnmolL = df9.SEABCMAngml./150
df9.Ctot = df9.PKngml./150
df9[!,:cmt] .= :a1
rename!(df9,Dict(:SEABCMAnmolL=>:dv))

dfP1=read_pumas(df9 ,id=:Subject, evid=:evid, time=:Time,amt=:Dosenmol, cmt=:cmt, rate=:Ratenmolday, cvs=[:CLS,:V1S], dvs=[:Ctot,:dv])

```

returns the following error:

MethodError: no method matching Int64(::Symbol)  
Closest candidates are:  
Int64(!Matched::Union{Bool, Int32, Int64, UInt32, UInt64, UInt8, Int128, Int16, Int8, UInt128, UInt16}) at boot.jl:710  
Int64(!Matched::Ptr) at boot.jl:720  
Int64(!Matched::Float32) at float.jl:700  
…

Stacktrace:  
[1] Subject(::SubDataFrame{DataFrame,DataFrames.Index,Array{Int64,1}}, ::Array{Symbol,1}, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Array{Symbol,1}, ::Array{Symbol,1}, ::Bool) at C:\Users\awolf-yadlin.juliapro\JuliaPro\_v1.2.0-1\packages\Pumas\0Bex7\src\data\_parsing\data\_types.jl:251  
[2] (::getfield(Pumas, Symbol("##37#38")){Symbol,Symbol,Symbol,Symbol,Symbol,Symbol,Symbol,Symbol,Symbol,Bool,Array{Symbol,1}})(::SubDataFrame{DataFrame,DataFrames.Index,Array{Int64,1}}) at .\none:0  
[3] collect(::Base.Generator{GroupedDataFrame{DataFrame},getfield(Pumas, Symbol("##37#38")){Symbol,Symbol,Symbol,Symbol,Symbol,Symbol,Symbol,Symbol,Symbol,Bool,Array{Symbol,1}}}) at .\generator.jl:47  
[4] #read\_pumas#36(::Array{Symbol,1}, ::Array{Symbol,1}, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Symbol, ::Bool, ::typeof(read\_pumas), ::DataFrame) at C:\Users\awolf-yadlin.juliapro\JuliaPro\_v1.2.0-1\packages\Pumas\0Bex7\src\data\_parsing\data\_read.jl:63  
[5] (::getfield(Pumas, Symbol("#kw##read\_pumas")))(::NamedTuple{(:id, :evid, :time, :amt, :cmt, :rate, :cvs, :dvs),Tuple{Symbol,Symbol,Symbol,Symbol,Symbol,Symbol,Array{Symbol,1},Array{Symbol,1}}}, ::typeof(read\_pumas), ::DataFrame) at .\none:0  
[6] top-level scope at In[542]💯

This can only be fixed by:

```auto
df9[!,:cmt] .= 1

```

I hope this clarify my issue is probably arising from pumas\_read and not from building subjects or populations from scratch. Dose that makes sense?

Ale

---

<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:** [December 18, 2019, 6:18pm UTC](https://discourse.pumas.ai/t/fitting-multiple-observalbles/102/4 "2019-12-18T18:18:06Z")

</div>

Aha… let me check…
