Overview

Description

Compute and display percentiles of the empiricial distribution of longitudinal data.

Usage

prctilemlx(r, band=list(number=8,level=80),y.lim=NULL,plot=TRUE)

Arguments

r
a data frame with a column id, a column time and a column with values. The times should be the same for each individual.
band
a list with two fields
y.lim
vector of length 2, giving the y coordinate range
plot
if plot=TRUE the empirical distribution is displayed, if plot=FALSE, the values of the percentiles are returned

Value

If plot=TRUE: a ggplot object

If plot=FALSE: a list with fields

q
a vector of percentiles of length band$number+1,
color
a vector of colors used for the plot of length band$number,
y
a data frame with the values of the empirical percentiles computed at each time point.


Examples

Some basic examples

We simulate longitudinal data for \(N=2000\) individuals using simulx

myModel <- inlineModel("
[LONGITUDINAL]
input = {ka, V, Cl}
EQUATION:
C = pkmodel(ka,V,Cl)

[INDIVIDUAL]
input = {ka_pop, V_pop, Cl_pop, omega_ka, omega_V, omega_Cl}
DEFINITION:
ka = {distribution=lognormal, reference=ka_pop, sd=omega_ka}
V  = {distribution=lognormal, reference=V_pop,  sd=omega_V }
Cl = {distribution=lognormal, reference=Cl_pop, sd=omega_Cl}
")

N=2000

pop.param   <- c(
  ka_pop  = 1,    omega_ka  = 0.5,
  V_pop   = 10,   omega_V   = 0.4,
  Cl_pop  = 1,    omega_Cl  = 0.3)
  
res <- simulx(model     = myModel,
              parameter = pop.param,
              treatment = list(time=0, amount=100),
              group     = list(size=N, level='individual'),
              output    = list(name='C', time=seq(0,24,by=0.5)))

res$C is a dataframe with \(2000 \times 241=482000\) rows and 3 columns

res$C[1:10,]
##    id time        C
## 1   1  0.0 0.000000
## 2   1  0.5 2.723992
## 3   1  1.0 4.638236
## 4   1  1.5 5.961186
## 5   1  2.0 6.852971
## 6   1  2.5 7.430953
## 7   1  3.0 7.781127
## 8   1  3.5 7.966491
## 9   1  4.0 8.033176
## 10  1  4.5 8.014946

we can compute and display the empirical percentiles of \(C\) using the default settings (i.e. percentiles of order 10%, 20%, … 90%)

p1   <- prctilemlx(res$C)
print(p1)

The 3 quartiles (i.e. percentiles of order 25%, 50% and 75%) are displayed by selecting a 50% interval splitted into 2 subintervals

p2 <- prctilemlx(res$C, band=list(number=2, level=50))
print(p2)

A one 90% interval can be displayed using only one interval

p3 <- prctilemlx(res$C, band=list(number=1, level=90))
print(p3)

or 75 subintervals in order to better represent the continuous distribution of the data within this interval

p4 <- prctilemlx(res$C, band=list(number=75, level=90))
print(p4)

A List of data frames is returned and the percentiles are not plotted by setting plot=FALSE

p5 <- prctilemlx(res$C, band=list(number=4, level=80), plot=FALSE)
print(names(p5))
## [1] "proba" "color" "y"
print(p5$proba)
## [1] 0.1 0.3 0.5 0.5 0.7 0.9
print(p5$color)
## [1] "#A020F033" "#A020F080" "#A020F0FF" "#A020F080" "#A020F033"
print(p5$y[1:5,])
##   time      10%      30%      50%      50%      70%       90%
## 1  0.0 0.000000 0.000000 0.000000 0.000000 0.000000  0.000000
## 2  0.5 1.784384 2.800470 3.719333 3.719333 5.025148  7.396058
## 3  1.0 2.982454 4.416886 5.684956 5.684956 7.361150 10.209911
## 4  1.5 3.721209 5.367016 6.619320 6.619320 8.378780 11.246125
## 5  2.0 4.185181 5.843230 7.063313 7.063313 8.780274 11.406965


Using prctilemlx with groups

We now define 4 treatment groups:

Ng=400
g1 <- list(size=Ng, level='individual', treatment = list(time=0, amount=60))
g2 <- list(size=Ng, level='individual', treatment = list(time=0, amount=100))
g3 <- list(size=Ng, level='individual', treatment = list(time=3, amount=60))
g4 <- list(size=Ng, level='individual', treatment = list(time=3, amount=100))

t.out <- seq(0,24,by=0.5)
res <- simulx(model     = myModel,
              parameter = pop.param,
              group     = list(g1, g2, g3, g4),
              output    = list(name='C', time=t.out))

By default, column “group” is used - if it exists - to make subplots

labels <- c("60 mg - 0h ", "100 mg - 0h", "60 mg - 3h ", "100 mg - 3h")
resC <- res$C
prctilemlx(resC, label=labels) + theme(legend.position = "none")

facet_wrap is used by prctilemlx with the default settings to produce these subplots. These default settings can be modified using facet_wrap explicitely

prctilemlx(resC, label=labels) + theme(legend.position = "none")  + facet_wrap(~ group, nrow=1)

A single plot is produced with group=“none” as input argument

prctilemlx(resC, group="none")