MonolixSuite in R
Auto Light Dark
Auto Light Dark

plotResidualsDistribution

[Monolix] Generate Distribution of the residuals

Plot the distribution of the residuals.

Usage

R
plotResidualsDistribution(
  obsName = NULL,
  residuals = c("indiv", "npde"),
  plots = c("pdf", "cdf"),
  settings = list(),
  preferences = list(),
  stratify = list()
)

Arguments

obsName

(character) Name of the observation (in dataset header). By default the first observation is considered.

residuals

(character) List of residuals to display: population residuals ("pop"), individual residuals ("indiv"), normalized prediction distribution error ("npde") (default c("indiv", "npde)).

plots

Type of plots: probability density distribution ("pdf"), cumulative density distribution ("cdf") (default c("pdf", "cdf")).

settings

List with the following settings

  • indivEstimate (character) Calculation of individual estimates: conditional mean ("mean"), conditional mode with EBE's ("mode"), conditional distribution ("simulated") (default "simulated").

  • useCensored (logical) Choose to use BLQ data (TRUE) or to ignore it (FALSE) to compute the statistics (default TRUE). For continuous data only.

  • censoring (character) BLQ data can be simulated ('simulated'), or can be equal to the limit of quantification ('loq') (default 'simulated'). For continuous data only.

  • legend (logical) add (TRUE) / remove (FALSE) plot legend (default FALSE).

  • grid (logical) add (TRUE) / remove (FALSE) plot grid (default TRUE).

  • ncol (integer) number of columns when facet = TRUE (default 4).

  • fontsize (integer) Plot text font size.

preferences

(optional) preferences for plot display, run getPlotPreferences("plotResidualsDistribution") to check available displays.

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").

  • 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.

Value

  • A ggplot object if one prediction type,

  • A TableGrob object if multiple plots (output of grid.arrange)

See also

getChartsData getPlotPreferences

Examples

R
  initializeLixoftConnectors(software = "monolix")
  project <- file.path(getDemoPath(), "1.creating_and_using_models",
                       "1.1.libraries_of_models", "theophylline_project.mlxtran")
  loadProject(project)

  runPopulationParameterEstimation()
  runConditionalDistributionSampling()

  plotResidualsDistribution()

Default plotResidualsDistribution output with four panels. Histograms of IWRES and NPDE with density on the y axis and a dashed theoretical standard normal curve, followed by the empirical cumulative distribution of IWRES and NPDE as a blue line versus the dashed theoretical curve, probability 0 to 1. Empirical and theoretical distributions agree closely.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsDistribution(residuals = "indiv", settings = list(indivEstimate = "simulated"))

Residuals distribution for individual residuals with indivEstimate simulated. Left, a histogram of IWRES with density up to about 0.55 against a dashed standard normal curve peaking at 0.4. Right, the empirical cumulative distribution of IWRES in blue, close to the dashed theoretical curve, with a slightly heavier left tail.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsDistribution(residuals = "indiv", settings = list(indivEstimate = "mode"))
#> Warning: Conditional Mode Estimation was not run, individual predictions based on conditional mean computed with MCMC will be displayed instead.

Residuals distribution for IWRES requested with indivEstimate mode, which falls back to the conditional mean as the warning says. Left, a histogram with fewer wide bins, sharply peaked around 0 with density up to about 0.68 versus the dashed normal curve at 0.4. Right, the blue empirical cumulative distribution is steeper than the dashed theoretical curve.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsDistribution(residuals = "pop", plots = "pdf")

Histogram of population residuals PWRES with density on the y axis, from plotResidualsDistribution with residuals pop and plots pdf. Bars span about -1.7 to 3, with most mass between -1.3 and 0.9 and a small secondary group between 2 and 3, overlaid on a dashed standard normal density curve.
R

  plotResidualsDistribution(residuals = "npde", plots = "cdf")

Cumulative distribution plot of NPDE, from plotResidualsDistribution with residuals npde and plots cdf. The blue empirical curve, probability 0 to 1 versus NPDE from -4 to 4, follows the dashed theoretical normal curve closely, with small step deviations above NPDE of 1.
R

  plotResidualsDistribution(stratify = list(filter=list("SEX", "F")))

Residuals distribution filtered to SEX F, four panels. Histograms of IWRES and NPDE with dashed normal density curves, then cumulative distributions of IWRES and NPDE. IWRES matches the theoretical curves well, while the NPDE histogram ranges only from about -2 to 1 and its blue cumulative curve lies left of the dashed theoretical curve.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsDistribution(stratify = list(split = "WEIGHT",
                                            groups = list(name = "WEIGHT", definition = c(75))))

Residuals distribution split by WEIGHT at 75, giving eight narrow panels. For IWRES and NPDE, density histograms and cumulative distribution curves are each shown for the lower and upper weight groups, against dashed theoretical normal curves. Facet titles and x axis tick labels are truncated and overlapping because the panels are so narrow.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsDistribution(residuals = "indiv", settings = list(legend = T),
                            stratify = list(split = c("SEX", "WEIGHT"),
                                            groups = list(name = "WEIGHT", definition = 70)))

IWRES distribution split by SEX and WEIGHT cut at 70, with legend enabled. Two density histograms and two cumulative distribution panels for groups SEX F WEIGHT 54.6 to 70 and SEX M WEIGHT 70 to 86.4. A bottom legend identifies the dashed line as theoretical distribution and blue bars as empirical distribution. Both groups agree well with the theory.
R

#> TableGrob (2 x 1) "arrange": 2 grobs
#>   z     cells    name              grob
#> 1 1 (1-1,1-1) arrange   gtable[arrange]
#> 2 2 (2-2,1-1) arrange gtable[guide-box]

  plotResidualsDistribution()

Default plotResidualsDistribution output with four panels. Density histograms of IWRES and NPDE with dashed standard normal curves, followed by empirical cumulative distributions of IWRES and NPDE in blue versus dashed theoretical curves. The empirical distributions agree closely with the theoretical ones.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsDistribution(residuals = c("indiv", "npde"), settings = list(indivEstimate = "simulated"))

Residuals distribution for IWRES and NPDE with indivEstimate simulated, four panels. Density histograms of IWRES and NPDE with dashed normal density curves, then blue empirical cumulative distributions of IWRES and NPDE against dashed theoretical curves. This output is identical to the default plot.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsDistribution(residuals = c("pop", "indiv"), settings = list(indivEstimate = "mode"))
#> Warning: Conditional Mode Estimation was not run, individual predictions based on conditional mean computed with MCMC will be displayed instead.

Residuals distribution for PWRES and IWRES, with IWRES based on the conditional mean because the conditional mode was not run. Four panels show density histograms of PWRES and IWRES with dashed normal curves, then their cumulative distributions. The IWRES histogram is sharply peaked near 0 and its cumulative curve is steeper than the theoretical one.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsDistribution(plots = c("pdf", "cdf"))

Residuals distribution with plots pdf and cdf, four panels. Density histograms of IWRES and NPDE with dashed standard normal curves, then blue empirical cumulative distributions of IWRES and NPDE versus dashed theoretical curves. This output is identical to the default plot.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsDistribution(plots = c("cdf"))

Residuals distribution with plots cdf only, two panels. Blue empirical cumulative distribution curves of IWRES and NPDE, probability 0 to 1, each compared with a dashed theoretical normal cumulative curve. Both follow the theoretical curve closely, with small deviations in the tails.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsDistribution(residuals = "npde")

Residuals distribution for NPDE only, two panels. Left, a density histogram of NPDE from about -1.9 to 2.7 with a dashed standard normal curve. Right, the blue empirical cumulative distribution of NPDE versus the dashed theoretical curve, which agree closely.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]


Last updated: