# NIBR data analysis

**URL:** <https://discourse.pumas.ai/t/nibr-data-analysis/630>\
**Category:** How-to\
**Created:** [February 22, 2022, 11:56pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630 "2022-02-22T23:56:46Z")\
**Posts on this page:** 16\
**Page:** 3

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/michael/32/818_2.png) [@Michael](https://discourse.pumas.ai/u/Michael)\
**Post date:** [February 24, 2022, 6:51pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/41 "2022-02-24T18:51:56Z")

</div>

> [@vijay](#):
>
> `[pk_log_plots..., avg_pk_plots...]`

`vcat(pk_log_plots, avg_pk_plots)` would be more efficient usually.

---

<div class="post-metadata">

**Author:** ![bobbrown](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@bobbrown](https://discourse.pumas.ai/u/bobbrown)\
**Post date:** [February 24, 2022, 7:35pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/42 "2022-02-24T19:35:35Z")

</div>

@Michael I tried your suggestion. see below:

```auto
all_plots = vcat(pk_log_plots, avg_pk_plots) #also tried embedding this command in report().
report(all_plots, 
      title = "Individual Semi-Log Exploratory Plots", 
      output = "./practice/nibr/data/plots",
      header = "Single Ascending Dose",
      footer = "Confidential")

```

```auto
7-element Vector{Any}:
 Figure()
 Figure()
 Figure()
 Figure()
 Figure()
 Figure()
 FigureAxisPlot()

[ Info: Calculating required `inspect` results.
ERROR: LoadError: Unknown argument type `Figure`.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] (::PumasReports.var"#categorise#4"{Vector{Any}, Vector{Any}, Vector{Any}, Vector{Any}})(f::Figure)
    @ PumasReports /builds/PumasAI/PumasSystemImages-jl/.julia/packages/PumasReports/1jlEU/src/PumasReports.jl:293
  [3] foreach(f::PumasReports.var"#categorise#4"{Vector{Any}, Vector{Any}, Vector{Any}, Vector{Any}}, itr::Tuple{Figure})
    @ Base ./abstractarray.jl:2141
  [4] PumasReports.ModelBundle(args::Tuple{Figure}; inspect::Bool, infer::Bool)
    @ PumasReports /builds/PumasAI/PumasSystemImages-jl/.julia/packages/PumasReports/1jlEU/src/PumasReports.jl:294
  [5] PumasReports.ModelBundle(args::Figure; inspect::Bool, infer::Bool)
    @ PumasReports /builds/PumasAI/PumasSystemImages-jl/.julia/packages/PumasReports/1jlEU/src/PumasReports.jl:333
  [6] (::PumasReports.var"#14#15"{Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol, Symbol}, NamedTuple{(:inspect, :infer), Tuple{Bool, Bool}}}})(::Tuple{Int64, Figure})
    @ PumasReports ./none:0
  [7] iterate
    @ ./generator.jl:47 [inlined]
  [8] collect(itr::Base.Generator{Base.Iterators.Enumerate{Vector{Any}}, PumasReports.var"#14#15"{Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol, Symbol}, NamedTuple{(:inspect, :infer), Tuple{Bool, Bool}}}}})
    @ Base ./array.jl:678
  [9] #_named_objects#13
    @ /builds/PumasAI/PumasSystemImages-jl/.julia/packages/PumasReports/1jlEU/src/PumasReports.jl:343 [inlined]
 [10] report(fitted_models::Vector{Any}; output::String, title::String, version::VersionNumber, date::Dates.DateTime, author::String, categorical::Vector{Any}, force::Bool, inspect::Bool, infer::Bool, clean::Bool, header::String, footer::String, plot_fontsize::Int64, plot_resolution::Tuple{Int64, Int64})
    @ PumasReports /builds/PumasAI/PumasSystemImages-jl/.julia/packages/PumasReports/1jlEU/src/PumasReports.jl:177
 [11] top-level scope
    @ ~/data/code/practice/nibr/data/dataprep

```

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/michael/32/818_2.png) [@Michael](https://discourse.pumas.ai/u/Michael)\
**Post date:** [February 24, 2022, 7:44pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/43 "2022-02-24T19:44:02Z")

</div>

> [@bobbrown](#):
>
> ```auto
> 7-element Vector{Any}:
> Figure()
> Figure()
> Figure()
> Figure()
> Figure()
> Figure()
> FigureAxisPlot()
> 
> ```

The last element in that `all_plots` vector will be what’s confusing `report`. It’s a `FigureAxisPlot` object rather than the expected `Figure` that report accepts. Was your `avg_pk_plots` created with `paginate = true`? You can either set `paginate = true` or “split apart” the output of `summary_observations_vs_time` like so:

```julia
avg_pk_plots, _, _ = summary_observations_vs_time(...)

```

which will just keep the `Figure` part of `FigureAxisPlot` and drop the `Axis` and `Plot`.

This is something that could probably be automated by `report` internally. I’ll have a look at adding support for that in a future release of `Pumas`.

---

<div class="post-metadata">

**Author:** ![bobbrown](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@bobbrown](https://discourse.pumas.ai/u/bobbrown)\
**Post date:** [February 24, 2022, 8:00pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/44 "2022-02-24T20:00:35Z")

</div>

> [@vijay](#):
>
> `[pk_log_plots..., avg_pk_plots...]`

@Michael paginate=false for the avg plots. See below.

```auto
#
pk_log_plots = observations_vs_time(pop_nca, 
                                axis = (xlabel = "Time (hours)", 
                                        ylabel = "Concentration (μg/mL)",
                                        yscale=log10, ytickformat=x -> string.(round.(x; digits=1)), 
                                        yticks = [0.1, 1, 10],
                                        ygridwidth = 3, 
                                        yminorticksvisible = true,
                                        yminorgridvisible = true,
                                        yminorticks = IntervalsBetween(10),
                                        xminorticksvisible = true,
                                        xminorgridvisible = true,
                                        xminorticks = IntervalsBetween(5),
                                        limits = (nothing, nothing, nothing, 20),
                                        spinewidth = 2),
                                        columns = 4, rows = 3,
                                        paginate = true,
                                        markersize = 8,
                                        markercolor = :blue,
                                        linewidth = 2,
                                        color = :green,
                                        facet = ( combinelabels = true,))
#
pk_log_plots[1]
pk_log_plots[6]

avg_pk_plots = summary_observations_vs_time(pop_nca, 
                                axis = (xlabel = "Time, hr", 
                                        ylabel = "Concentration, ug/L",
                                        xlim = (0,72),
                                        xticks = 0:12:72),
                                markersize = 1,
                                paginate = false,
                                columns = 3, rows = 2,
                                facet = (combinelabels = true,))
#
all_plots = vcat(pk_log_plots, avg_pk_plots)
report(all_plots, 
      title = "Individual Semi-Log Exploratory Plots", 
      output = "./practice/nibr/data/plots",
      header = "Single Ascending Dose",
      footer = "Confidential")

```

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/michael/32/818_2.png) [@Michael](https://discourse.pumas.ai/u/Michael)\
**Post date:** [February 24, 2022, 8:19pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/45 "2022-02-24T20:19:54Z")

</div>

Setting `paginate = true` should be what’s needed for that `summary_observations_vs_time` plot to work correctly in `report`.

---

<div class="post-metadata">

**Author:** ![bobbrown](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@bobbrown](https://discourse.pumas.ai/u/bobbrown)\
**Post date:** [February 24, 2022, 8:35pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/46 "2022-02-24T20:35:03Z")

</div>

@Michael That worked! Thank you. Is there a way to make the size of the plots constant. You saw my code above.  
See the last plot.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/9a0a642da71b7ad31c6b541c2b29833e3ede1ada.png)

---

<div class="post-metadata">

**Author:** ![bobbrown](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@bobbrown](https://discourse.pumas.ai/u/bobbrown)\
**Post date:** [February 24, 2022, 10:58pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/47 "2022-02-24T22:58:00Z")

</div>

@julius I tried your trick, In general it seems to work. Changing the range of the yaxis for semi-log plot seems to be a challenge. Tried few approaches to make the ylims between 0.01, 100; yticks [0.1,1,10,100]. The code runs without any error; but plot is unaffected. The top part of the plot is chopped off (see below).

```auto
pk_log_plots = observations_vs_time(pop_nca, 
                                axis = (xlabel = "Time (hours)", 
                                        ylabel = "Concentration (μg/mL)",
                                        yscale=log10, 
                                        ytickformat=x -> string.(round.(x; digits=1)), 
                                        xlims = (0,72),
                                        xticks = (0:12:72),
                                        ylims = (0.01,100),
                                        yticks = [0.1, 1, 10, 100],
                                        #yticks = (0.01:10:100),
                                        #yticks = LogTicks(IntegerTicks()),
                                        ygridwidth = 3, 
                                        yminorticksvisible = true,
                                        yminorgridvisible = true,
                                        yminorticks = IntervalsBetween(10),
                                        xminorticksvisible = true,
                                        xminorgridvisible = true,
                                        xminorticks = IntervalsBetween(5),
                                        limits = (nothing, nothing, nothing, 20),
                                        spinewidth = 2),
                                        columns = 2, rows = 2,
                                        paginate = true,
                                        markersize = 8,
                                        markercolor = :blue,
                                        linewidth = 2,
                                        color = :green,
                                        facet = ( combinelabels = true,))
#

```

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/91430a62beebf7641c08f8eb97afcac7c16b6d81.jpeg)

---

<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:** [February 25, 2022, 12:01am UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/48 "2022-02-25T00:01:12Z")

</div>

> [@bobbrown](#):
>
> Tried few approaches to make the ylims between 0.01, 100; yticks [0.1,1,10,100].

as in my previous post, use `limits = (nothing, nothing, nothing , 100)` instead, where each argument is the `xlow, xhigh, ylow, yhigh`

---

<div class="post-metadata">

**Author:** ![bobbrown](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@bobbrown](https://discourse.pumas.ai/u/bobbrown)\
**Post date:** [February 25, 2022, 12:10am UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/49 "2022-02-25T00:10:31Z")

</div>

Worked like a charm. Thank you.

---

<div class="post-metadata">

**Author:** ![bobbrown](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@bobbrown](https://discourse.pumas.ai/u/bobbrown)\
**Post date:** [February 25, 2022, 2:55pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/50 "2022-02-25T14:55:27Z")

</div>

@vijay @Michael any advice on the squished graph on the last page?

> [@NIBR data analysis](https://discourse.pumas.ai/t/nibr-data-analysis/630/46):
>
> @Michael That worked! Thank you. Is there a way to make the size of the plots constant. You saw my code above. See the last plot.

---

<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:** [February 25, 2022, 3:12pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/51 "2022-02-25T15:12:03Z")

</div>

it has to do with the combination of `paginate`, `limit` and `facet`. Can you try running this code that I posted earlier

```julia
using Pumas
using PumasUtilities
using Dates
using CairoMakie
using AlgebraOfGraphics
using DataFramesMeta
df = CSV.read("Single_Ascending_Dose_Dataset2.csv", DataFrame, missingstrings = ["NA"])
df = @rsubset df :TIME >= 0
@rtransform! df route = "ev"
## map NCA data from CSV
ncapop = read_nca(df,
                id = :ID, time = :NOMTIME, amt = :AMT, route = :route,
                observations = :LIDV, 
                group = [:DOSE])

#plot means               
avg_pk_plots = summary_observations_vs_time(ncapop, 
                                  color = :black, linewidth = 2, whiskerwidth = 8,
                                  paginate = true,
                                  limit = 1,
                                  axis = (xlabel = "Time (hours)", 
                                            ylabel = "Concentration (μg/mL)",
                                            yscale=log10, ytickformat=x -> string.(round.(x; digits=1)), 
                                            yticks = [0.1, 1, 10],
                                            ygridwidth = 3, 
                                            yminorgridcolor = :darkgrey,
                                            yminorticksvisible = true,
                                            yminorgridvisible = true,
                                            yminorticks = IntervalsBetween(10),
                                            xminorticksvisible = true,
                                            xminorgridvisible = true,
                                            xminorticks = IntervalsBetween(5),
                                            limits = (nothing, nothing, nothing, 30),
                                            spinewidth = 2),
                                    #facet = ( combinelabels = true,),
                                    figure = (resolution = (800,800),
                                                        fontsize = 22),)
                                  
pk_log_plots = observations_vs_time(ncapop, paginate = true, color = :black,
                                axis = (xlabel = "Time (hours)", 
                                        ylabel = "Concentration (μg/mL)",
                                        yscale=log10, ytickformat=x -> string.(round.(x; digits=1)), 
                                        yticks = [0.1, 1, 10],
                                        ygridwidth = 3, 
                                        yminorticksvisible = true,
                                        yminorgridvisible = true,
                                        yminorticks = IntervalsBetween(10),
                                        xminorticksvisible = true,
                                        xminorgridvisible = true,
                                        xminorticks = IntervalsBetween(5),
                                        limits = (nothing, nothing, nothing, 20),
                                        spinewidth = 2),
                                        columns = 4, rows = 4,
                                        facet = ( combinelabels = true,))

report([pk_log_plots..., avg_pk_plots...],
      title = "Summary and Individual Semi-Log Exploratory Plots", 
      output = "./practice/nibr/data/plots",
      header = "Single Ascending Dose",
      footer = "Confidential")

```

---

<div class="post-metadata">

**Author:** ![bobbrown](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@bobbrown](https://discourse.pumas.ai/u/bobbrown)\
**Post date:** [February 25, 2022, 5:35pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/52 "2022-02-25T17:35:32Z")

</div>

@vijay I ran your code. The last page graphs being different persists. My code also rendered similar discrepancy.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/b6310ac54233d871d12aeb5ad9b22d0b114e0c22.png)

For the avg plots, you opted for one plot per page. That works sure. But I was trying 2x2 format to be concise.  
Bob

---

<div class="post-metadata">

**Author:** ![bobbrown](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@bobbrown](https://discourse.pumas.ai/u/bobbrown)\
**Post date:** [February 26, 2022, 12:39pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/53 "2022-02-26T12:39:40Z")

</div>

@vijay I tried to consolidate your suggested data formatting code, like so. It worked, it took me a good 30min to figure out that `>` requires a dot and the other commands do not. I do see other commands such as ‘transform’ also are to be performed per row, but they do not require a dot. Anyway it works for me. except for the graph on the last page.

```auto
df = @chain df begin
        @subset(:TIME .>= 0.0)
        @transform(:ROUTE = "ev")
        @transform(:AMT_UG = :AMT * 1000)
        @select(:ID,:TIME,:NOMTIME,:AMT_UG,:CONC = :LIDV,:CMT,:EVID,:WEIGHTB,:SEX,:DOSE,:ROUTE)
end

```

---

<div class="post-metadata">

**Author:** ![bobbrown](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@bobbrown](https://discourse.pumas.ai/u/bobbrown)\
**Post date:** [February 26, 2022, 12:47pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/54 "2022-02-26T12:47:46Z")

</div>

@vijay the above code for avg PK profiles produces a plot for each dose. I am used to facet\_wrap() type command. I did not know which argument to use to switch-off a facet plot. That is, to have the avg plots across all doses on one plot.  
Bob

---

<div class="post-metadata">

**Author:** ![donaldlee3](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/donaldlee3/32/165_2.png) [@donaldlee3](https://discourse.pumas.ai/u/donaldlee3)\
**Post date:** [May 4, 2022, 4:15am UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/55 "2022-05-04T04:15:43Z")

</div>

@vijay @storopoli There appears to be one extra minortick while plotting logscale. Is there a way to fix this?

---

<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:** [May 4, 2022, 11:14pm UTC](https://discourse.pumas.ai/t/nibr-data-analysis/630/56 "2022-05-04T23:14:35Z")

</div>

it would be good to see this in a visual. There are many plots in this thread. Can you please markup and show where exactly?

[Previous page](https://discourse.pumas.ai/t/nibr-data-analysis/630.md?page=2)
