MonolixSuite in R
Auto Light Dark
Auto Light Dark

plotObservedData

[Monolix - PKanalix] Generate Observed data plot

Plot the observed data.

Usage

R
plotObservedData(
  obsName = NULL,
  settings = list(),
  stratify = list(),
  preferences = list()
)

Arguments

obsName

(character) Name of the observation (if several OBS ID). By default the first observation is considered.

settings

List with the following settings: [CONTINUOUS - DISCRETE] Settings specific to continuous and discrete data

  • dots (logical) - If TRUE individual observations are displayed as dots (default TRUE).

  • lines (logical) - If TRUE individual observations are displayed as lines (default TRUE).

  • mean (logical) - If TRUE mean of observations is displayed (default FALSE for Monolix, TRUE for PKanalix).

  • error (logical) If TRUE error bar is displayed (default FALSE for Monolix, TRUE for PKanalix).

  • meanMethod (character) - When mean is set to TRUE, display arithmetic mean ("arithmetic") or geometric mean ("geometric"). Default value is "arithmetic".

  • errorMethod (character) - When error is set to TRUE, display standard deviation ("standardDeviation") or standard error ("standardError"). Default value is "standardDeviation".

  • useCensored (logical) If TRUE, use censored data to compute mean and error (default FALSE)

  • timeAfterLastDose (logical) If TRUE, display observations as relative to the previous dose for the x-axis (default FALSE) Can be applied only for continuous and discrete data with dose information, and if xvariable is different from "regressor".

  • xvariable (character) Choose information to use on x-axis, one of "time", "nominalTime" or a regressor name (default "time") For event data, plot against regressor value is not available.

  • binLimits (logical) - If TRUE, bins limits are displayed as vertical lines (default FALSE).

  • binsSettings a list of settings for time axis binning for observation statistics computation:

    • criteria (character) - Binning criteria, one of 'equalwidth', 'equalsize', or 'leastsquare' methods. (default "leastsquare").

    • is.fixedNbBins (logical) - If TRUE, a fixed number of bins is used (see nbBins). If FALSE (default), the number of bins is optimized using binRange and nbBinData.

    • nbBins (integer) - Number of bins (default 10). Ignored if is.fixedNbBins=FALSE.

    • binRange (vector(integer, integer)) - Minimum and maximum number of bins when bins are optimized (default c(5, 100)).

    • nbBinData (vector(integer, integer)) - Minimum and maximum number of data points per bin when bins are optimized (default c(10, 200) for Monolix and c(3, 200) for PKanalix).

[DISCRETE] Settings specific to discrete data

  • plot (character) Type of plot: "continuous" (default), "stacked" or "grouped".

  • histogramColors (vector) List of colors to use in histograms plots.

[EVENT] Settings specific to event data

  • eventPlot - Display Survival function ("survivalFunction") or mean number of events per subject ("averageEventNumber") (default "survivalFunction").

Other settings

  • cens (logical) - If TRUE censored data are displayed as dots (default TRUE).

  • dosingTimes (logical) - If TRUE, dosing times are displayed as vertical lines (default FALSE). Cannot be used if timeAfterLastDose=TRUE.

  • legend (logical) - If TRUE, plot legend is displayed (default FALSE).

  • grid (logical) - If TRUE, plot grid is displayed (default TRUE).

  • xlog (logical) - If TRUE, log-scale on x axis is used (default FALSE).

  • ylog (logical) - If TRUE, log-scale on y axis is used (default FALSE).

  • xlab (character) - Label on x axis (default "time").

  • ylab (character) - Label on y axis (default obsName).

  • ncol (integer) - Number of columns when using split (default 4).

  • xlim (c(double, double)) - Limits of the x axis.

  • ylim (c(double, double)) - Limits of the y axis.

  • fontsize (integer) - Font size of text elements (default 11).

  • units (logical) - If TRUE, units are added in axis labels (default TRUE) (only available with PKanalix).

  • scales (character) Should scales be fixed ("fixed"), free ("free", default), or free in one dimension ("free_x", "free_y").

stratify

List with the stratification arguments:

  • groups - Definition of stratification groups. By default, stratification groups are already defined as one group for each category for categorical covariates, and two groups of equal number of individuals for continuous covariates. To redefine groups, for each covariate to redefine, specify a list with:

    name

    character

    covariate name (e.g "AGE")

    definition

    (vector(continuous) || list>(categorical))

    For continuous covariates, vector of break values (e.g c(35, 65)). For categorical covariates, groups of categories as a list of vectors(e.g list(c("study101"), c("study201","study202")))

  • split (vector) - Vector of covariates used to split (i.e facet) the plot (by default no split is applied). For instance c("FORM","AGE").

  • mergedSplits (logical) - When "split" is used and mean=T, should the means of the different groups be displayed on the same plot (TRUE) or on different subplots (FALSE, default). Not available for count/categorical data. When mergedSplits=T, the "color" argument is ignored and the coloring is done according to the splitted groups.

  • filter (list< list> >) - List of pairs containing a covariate name and the vector of indexes or categories (for categorical covariates) of the groups to keep (by default no filtering is applied). For instance, list("AGE",c(1,3)) to keep the individuals belonging to the first and third age group, according to the definition in groups. For instance, list("FORM","ref") using the category name for categorical covariates.

  • color (vector) - Vector of covariates used for coloring (by default no coloring is applied). For instance c("FORM","AGE").

  • colors - Vector of colors to use when color argument is used. Takes precedence over colors defined in preferences. For instance c("#ebecf0","#cdced1","#97989c").

  • individualSelection - Ids to display (by default the 12 first ids are displayed) defined as:

    • indices (vector) - Indices of the individuals to display (by default, the 12 first individuals are selected). If occasions are present, all occasions of the selected individuals will be displayed. Takes precedence over ids. For instance c(5,6,10,11).

    • isRange (logical) - If TRUE, all individuals whose index is inside [min(indices), max[indices]] are selected (FALSE by default). Forced to FALSE if ids is defined.

    • ids (vector) - Names of the individuals to display. If occasions are present, all occasions of the selected individuals will be displayed. For instance c("101-01","101-02","101-03"). If ids are integers, can also be c(1,3,6). Ignored if indices is defined.

preferences

(optional) preferences for plot display, run getPlotPreferences("plotObservedData") to check available options.

Value

A ggplot object

See also

getPlotPreferences

Examples

R
  initializeLixoftConnectors(software = "pkanalix", force=T)
  project <- paste0(getDemoPath(), "/2.case_studies/project_aPCSK9_SAD.pkx")
  loadProject(project)

  # by default, individual profiles and mean curve are displayed
  plotObservedData()
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData default plot for the PKanalix aPCSK9 SAD project. DV_ug_mL in mg per L versus time in days, 0 to 84. Blue individual profiles with dots and lines peak from about 8 to 116 within the first 10 days. A black mean curve with standard deviation error bars peaks near 37. Red dots at days 56 and 84 mark censored data.
R


  # displaying dots and mean curve by dose group, merged on a single plot
  plotObservedData(settings=list(lines=F,
                            mean=T,
                            meanMethod="geometric",
                            ylog=T,
                            ylab="mAb concentration (ug/mL)"),
              stratify=list(split="DOSE_mg",
                            mergedSplits=T),
              preferences=list(observationStatistics=list(lineWidth=0.8),
                               obs=list(radius=2)))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData plot with log y axis, split by DOSE_mg with merged splits. mAb concentration in ug per mL versus time in days. Dots show individual observations and lines with error bars show the geometric mean of each of three dose groups, in blue, dark grey and green. The green group is highest, peaking near 70, and the blue group lowest, peaking near 10. Small red dots at 0.1 are censored data.
R


  # coloring by ID, without mean curve
  plotObservedData(settings=list(mean=F,error=F),
              stratify = list(color=c("id")))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData plot of individual profiles colored by id, without mean curve. DV_ug_mL in mg per L versus time in days, 0 to about 84. Each individual has its own color, with dots joined by lines. Peaks occur within about the first 10 days, ranging from about 8 to about 116, followed by a decline toward zero.
R


  # changing the settings to display only the mean curve with SE, with bin limits and dosing times
  plotObservedData(settings=list(dots=F,
                            lines=F,
                            mean=T,
                            error=T,
                            meanMethod="geometric",
                            errorMethod="standardError",
                            useCensored=T,
                            binLimits=T,
                            binsSettings=list(criteria="leastsquare", is.fixedNbBins=T, nbBins=20),
                            cens=F,
                            dosingTimes=T,
                            legend=T,
                            grid=F,
                            xlog=F,ylog=T,
                            xlab="Time since first dose (days)",
                            ylab="mAb concentration (ug/mL)",
                            xlim=c(0,96),
                            ylim=c(0.1,70),
                            fontsize=12,
                            units=F))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData plot showing only the geometric mean curve with standard error bars, log y axis. mAb concentration in ug per mL versus Time since first dose in days, 0 to 100. The mean rises to about 25 near day 7, then declines to about 0.2 at day 84. Vertical red lines mark the bin limits and a dashed black line at time 0 marks the dose. Legend at the bottom.
R


  # changing preferences for observations, censored observations and bin limits
  plotObservedData(settings=list(dots=T, lines=T, legend=T, dosingTimes=T, mean=F, error=F, ylog=T, cens=T),
              preferences=list(obs=list(color="#161617",
                                        radius=2,
                                        shape=18,
                                        lineWidth=0.2,
                                        lineType="dashed",
                                        legend="Observations"),
                               censObs=list(color="#cdced1",
                                            radius=2,
                                            shape=16,
                                            legend="Censored observations"),
                               dosingTimes=list(color="#fcba03",
                                                lineWidth=0.5,
                                                lineType="solid",
                                                legend="Time of doses")))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData plot with customized preferences, log y axis. DV_ug_mL in mg per L versus time in days. Observations are black diamonds joined by thin dashed lines per individual, censored observations are light grey dots at 0.1 near days 56 and 84, and an orange vertical line at time 0 marks the dose. Legend at the bottom lists Observations, Censored observations and Time of doses.
R


  # changing preferences for mean and bin limits
  plotObservedData(settings=list(dots=F, lines=F, legend=T, binLimits=T, grid=F),
              preferences=list(observationStatistics=list(color="#161617",
                                                          whiskersWidth=3,
                                                          lineWidth=0.7,
                                                          lineType="solid",
                                                          legend="mean and standard deviation over bins"),
                               binsValues=list(color="#cdced1",
                                               lineWidth=0.5,
                                               lineType="dashed",
                                               legend="bins")))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData plot with customized mean and bin preferences, no grid. DV_ug_mL in mg per L versus time in days. A thick black line shows the mean with wide standard deviation whiskers per bin, peaking at about 37 around days 3 to 7 and declining to near 0 by day 84. Grey dashed vertical lines mark the bins. Legend reads mean and standard deviation over bins, and bins.
R


  # color and split by DOSE_mg but grouping two doses levels together
  plotObservedData(settings=list(mean=F,error=F,ylim=c(0,120)),
              stratify = list(groups=list(name="DOSE_mg",definition=list(c("150mg"), c("300mg","800mg"))),
                              color="DOSE_mg",
                              split="DOSE_mg"))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData plot colored and split by DOSE_mg with redefined groups, in two panels titled DOSE_mg 150mg and DOSE_mg 300mg-800mg. DV_ug_mL in mg per L versus time in days, y axis 0 to 125. The 150mg panel shows blue profiles peaking below about 20. The 300mg-800mg panel shows dark grey profiles peaking up to about 116. Red dots mark censored data.
R

  
  # selecting only one individual
  plotObservedData(settings=list(mean=F,error=F),
                   stratify = list(individualSelection=list(indices=1)))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData plot of a single individual selected with indices equals 1. DV_ug_mL in mg per L versus time in days. The blue profile rises from about 2.5 to a peak near 20 at about day 3, then declines to about 0.4 at day 56. A red dot at day 84 marks a censored value.
R

  plotObservedData(settings=list(mean=F,error=F),
                   stratify = list(individualSelection=list(ids="1")))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData plot of the same single individual, here selected with ids equals 1, giving an identical result. DV_ug_mL in mg per L versus time in days. The blue profile peaks near 20 at about day 3 and declines to about 0.4 at day 56, with a red censored dot at day 84.
R



  #============= projects with several covariates to stratify
initializeLixoftConnectors(software = "pkanalix", force=T)
project <- file.path(getDemoPath(), "/2.case_studies/project_Theo_extravasc_SD.pkx")
loadProject(project)

# defining groups for AGE and HT, coloring by HT and filtering by AGE
plotObservedData(settings=list(mean=F,error=F),
            stratify = list(groups=list(list(name="AGE", definition=c(24, 34)),
                                        list(name="HT", definition=c(184.5))),
                            color="HT",
                            colors=c("#cdced1","#161617"),
                            filter=list("AGE",c(1,3))))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData plot for the Theo_extravasc_SD project with groups defined for AGE and HT, colored by HT and filtered by AGE. DV in mg per L versus time in hours, 0 to about 72. Profiles appear in black or light grey for the two HT groups, peaking at about 4 to 11.5 between about 5 and 12 hours. Red dots near 0 mark censored data.
R


# filter to keep only second sequence (TR) and FORM=test
plotObservedData(settings=list(mean=F,error=F),
            stratify = list(filter=list(list("SEQ",2),list("FORM","test"))))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData plot filtered to keep only the second sequence SEQ, TR, and FORM equals test. DV in mg per L versus time in hours. About 10 blue individual profiles peak at about 4 to 10 between about 5 and 14 hours and decline toward zero by 48 to 72 hours. Red dots near 0 mark censored data.
R




  #============= project with time-to-event data
initializeLixoftConnectors(software = "monolix", force=T)
project <- file.path(getDemoPath(), "/4.joint_models/4.2.continuous_noncontinuous/PKrtte_project.mlxtran")
loadProject(project)

# survival Kaplan-Meier curve
plotObservedData(obsName="Hemorrhaging")

plotObservedData Kaplan-Meier plot for the time-to-event observation Hemorrhaging in the PKrtte project. Survival function versus time, 0 to 120. The blue step curve decreases steadily from 1 to about 0.2 at time 120, where a red dot marks censoring.
R


# mean number of events
plotObservedData(obsName="Hemorrhaging",
                 settings=list(eventPlot="averageEventNumber"))

plotObservedData plot of the mean number of events per subject for Hemorrhaging, with eventPlot set to averageEventNumber. Blue step curve versus time, 0 to 120, increasing steadily from 0 to about 1.55 at time 120.
R


#============= project with categorical data
initializeLixoftConnectors(software = "monolix", force=T)
project <- file.path(getDemoPath(), "/4.joint_models/4.2.continuous_noncontinuous/warfarin_cat_project.mlxtran")
loadProject(project)

# display is the same as for continuous data by default
plotObservedData(obsName="Level")
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData default plot for the categorical observation Level in the warfarin_cat project, displayed like continuous data. Level, 1 to 3, versus time, 0 to 144. Blue lines join observations. All individuals start at level 3, drop to level 1 by about 24 to 48, then some return to level 2 or 3 from about 72 onward.
R


# display as stacked or as grouped
plotObservedData(obsName="Level", settings=list(plot="stacked"))

plotObservedData stacked bar plot for the categorical observation Level. Number of individuals versus time at 0, 24, 36, 48, 72, 96, 120 and 144, with bars split by level in three shades of blue. At time 0 all 30 individuals are at level 3, at 36 and 48 all 32 are at level 1, and levels 2 and 3 reappear from 72 onward. About 13 individuals remain at 144.
R

plotObservedData(obsName="Level", settings=list(plot="grouped"))

plotObservedData grouped bar plot for Level, with one bar per level side by side at each time. Number of individuals versus time, 0 to 144. Level 3 dominates at time 0 with 30 individuals, level 1 dominates from 36 to 120, with 32 at 36 and 48, and at 144 the three levels have about 4 to 5 individuals each.
R


# splitting by sex
plotObservedData(obsName="Level", 
                 settings=list(plot="stacked", ylim=c(0,30), legend=T),
                 stratify=list(split="sex"))

plotObservedData stacked bar plot of Level split by sex, with panels for sex 0 and sex 1 and a legend for Level 1, 2 and 3 in shades of blue. Number of individuals versus time, y axis 0 to 30. The sex 0 panel has only about 4 to 5 individuals per time, while sex 1 has about 26 to 27, falling to about 8 at 144. Both show level 3 at time 0 and only level 1 at 36 and 48.
R



#============== project with multiple-dose to show timeAfterLastDose
initializeLixoftConnectors(software = "monolix", force=T)
project <- file.path(getDemoPath(), "/6.PK_models/6.3.multiple_doses/addl_project.mlxtran")
loadProject(project)

# with "time after first dose" by default
plotObservedData()
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData default plot for the multiple-dose addl project, with time since the first dose on the x axis. y versus time, 0 to about 83. Blue individual profiles show values of about 2 to 6 before time 12, no observations between about 11 and 72, then higher values of about 5 to 15 from about 72 to 83.
R


# with "time since previous dose"
plotObservedData(settings=list(timeAfterLastDose=T))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData plot with timeAfterLastDose set to TRUE for the multiple-dose project. y versus time after last dose, 0 to about 11. Profiles from both observation periods are now overlaid on the same time-after-dose axis, starting between about 3 and 12 and decreasing to about 1.5 to 9.
R



#============= project with regressor to show regressor on x-axis
initializeLixoftConnectors(software = "monolix", force=T)
project <- file.path(getDemoPath(), "/7.miscellaneous/7.1.regression_variables/reg3_warfarinPD_linearInterp_project.mlxtran")
loadProject(project)
#> [ERROR] Cannot load the project from its file 'C:/Users/FranoMihaljevic/lixoft/monolix/monolix2024R1/demos/7.miscellaneous/7.1.regression_variables/reg3_warfarinPD_linearInterp_project.mlxtran', as this file could not be found.

# with "time" on x-axis by default
plotObservedData()
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData default plot with time on the x axis. Because the regressor project could not be loaded, it shows the same multiple-dose data as the earlier plot, y versus time 0 to about 83, with blue individual profiles in two observation periods, before about 11 and from about 72 to 83.
R


# with regressor "Cc" (concentration) on x-axis
plotObservedData(settings=list(xvariable="Cc"))
#> Error: Invalid setting 'xvariable': no regressor called 'Cc' in the dataset

#============= project with nominal time on x-axis
initializeLixoftConnectors(software = "pkanalix", force=T)
project <- file.path(getDemoPath(), "/1.basic_examples/project_nominal_time.pkx")
loadProject(project)

# with "actual time" by default
plotObservedData()
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

plotObservedData default plot for the PKanalix project_nominal_time project, with actual time on the x axis. CONC in mg per L versus time in hours, 0 to about 25. Blue individual profiles, with sampling times scattered around nominal values, peak at about 5 to 11.5 between about 1 and 3.5 hours. A black mean curve with standard deviation error bars peaks near 8.
R


# with nominal time on x-axis
plotObservedData(settings=list(xvariable="nominalTime"))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

Observed data plot from plotObservedData with xvariable set to nominalTime for a PKanalix project. Individual concentration-time profiles are drawn as blue points joined by lines, with a black mean curve and error bars. The x-axis is nominal time from 0 to about 24, the y-axis is CONC in mg per L. Concentrations peak near 8 to 11 around time 1 to 3, then decline to about 1 to 3 at time 24.
R

Last updated: