MonolixSuite in R
Auto Light Dark
Auto Light Dark

plotResidualsScatterPlot

[Monolix] Generate Scatter plots of the residuals

Plot the scatter plots of the residuals.

Usage

R
plotResidualsScatterPlot(
  obsName = NULL,
  residuals = c("indiv"),
  xaxis = c("time", "prediction"),
  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")).

xaxis

(character) List of x-axis to display: time ("time"), prediction ("prediction") (default c("time", "prediction") for continuous data, c("time") for discrete data).

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 "mode"). For continuous data only

  • level (integer) level for prediction intervals computation (default 90).

  • higherPercentile (integer) Higher percentile for empirical and predicted percentiles computation (default 90).

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

  • binsSettings a list of settings for bins:

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

    • is.fixedNbBins (logical) If TRUE define a fixed number of bins, else define a range for automatic selection (default TRUE).

    • nbBins (integer) Define a fixed number of bins (default 10).

    • binRange (vector(integer, integer)) Define a range for the number of bins (default c(5, 100)).

    • nbBinData (vector(integer, integer)) Define a range for the number of data points per bin (default c(10, 200)).

  • residuals (logical) - If TRUE display residuals (default TRUE).

  • cens (logical) - If TRUE display censored data (default TUE).

  • empPercentiles (logical) - If TRUE display empirical percentiles (default FALSE).

  • predPercentiles (logical) - If TRUE display predicted percentiles (default FALSE).

  • predInterval (logical) - If TRUE, Prediction interval is displayed (default FALSE).

  • outlierDots (logical) - If TRUE Add red dots indicating empirical percentiles that are outside prediction intervals (default TRUE).

  • outlierAreas (logical) - If TRUE Add red areas indicating empirical percentiles that are outside prediction intervals (default TRUE).

  • spline (logical) - If TRUE display spline (default FALSE).

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

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

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

  • xlog (logical) add (TRUE) / remove (FALSE) log scaling on x axis (default FALSE).

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

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

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

  • fontsize (integer) Plot text font size.

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

preferences

(optional) preferences for plot display, run getPlotPreferences("plotResidualsScatterPlot") 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.

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

Value

  • A ggplot object if one prediction type,

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

Details

Note that 'prediction interval' setting is not available in 2021 version for this connector.

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()
  runConditionalModeEstimation()

  plotResidualsScatterPlot()

Residual scatter plots from plotResidualsScatterPlot with default settings for the theophylline project. Two panels show IWRES, individual weighted residuals, versus time from 0 to 25 on the left and versus Individual predictions from about 1 to 10 on the right. Blue points scatter around 0, mostly between -1 and 1, with a few values reaching about -3 and 3, mainly at early times.
R

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

Residual scatter plots from plotResidualsScatterPlot with individual residuals and indivEstimate set to simulated. IWRES versus time on the left and versus Individual predictions on the right. Many more points are shown, from the simulated individual parameters, spread from about -4 to 5, with diagonal streaks visible in the right panel.
R

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

Residual scatter plots from plotResidualsScatterPlot with individual residuals and indivEstimate set to mode. IWRES versus time on the left and versus Individual predictions on the right. Blue points scatter around 0, mostly between -1 and 1, with a few values reaching about -3 and 3. This looks the same as the default plot.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsScatterPlot(xaxis = "prediction", residuals = "pop")

Residual scatter plot from plotResidualsScatterPlot with xaxis set to prediction and population residuals. PWRES, population weighted residuals, on the y-axis from about -1.7 to 3, versus Population predictions on the x-axis from about 1 to 11. Blue points scatter around 0 without a clear trend.
R

  plotResidualsScatterPlot(xaxis = "time", residuals = "pop")

Residual scatter plot from plotResidualsScatterPlot with xaxis set to time and population residuals. PWRES on the y-axis, from about -1.7 to 3, versus time on the x-axis from 0 to 25. Points form vertical columns at the sampling times and scatter around 0 without a clear trend.
R

  plotResidualsScatterPlot(residuals = "npde")

Two scatter plots from plotResidualsScatterPlot with residuals set to npde. Left, NPDE versus time from 0 to about 25. Right, NPDE versus population predictions from about 1 to 11. Points scatter evenly around zero, mostly between minus 2 and 2.5, with no visible trend.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsScatterPlot(settings = list(spline = T))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

Two scatter plots from plotResidualsScatterPlot with the spline setting on. IWRES versus time on the left and IWRES versus individual predictions on the right, each with an orange spline. The splines stay close to zero, with a small dip at early times, and most residuals lie between minus 2 and 2.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsScatterPlot(settings = list(empPercentiles = T, level = 90,
                                           binsSettings = list(is.fixedNbBins = T, nbBins = 5),
                                           binLimits = T))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's linetype values.

Two scatter plots from plotResidualsScatterPlot with empirical percentiles at the 90 percent level, 5 fixed bins and bin limits shown. IWRES versus time and versus individual predictions, with red vertical lines at the bin limits and blue lines joining the median and outer percentiles of each bin. Some percentile points are circled in red.
R

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

Four scatter plots from plotResidualsScatterPlot showing individual and population residuals with simulated individual estimates. IWRES versus time and versus individual predictions contain many points, ranging about minus 4 to 5. PWRES versus time and versus population predictions range about minus 1.7 to 3.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotResidualsScatterPlot(residuals = "indiv", xaxis = c("prediction"),
                           settings = list(indivEstimate = "mode"))

Scatter plot from plotResidualsScatterPlot of IWRES versus individual predictions, using the conditional mode as individual estimate. Predictions range from about 1 to 10, and residuals scatter around zero, mostly between minus 1 and 1, with a few points near minus 3 and plus 3.
R

  plotResidualsScatterPlot(xaxis = c("prediction"), residuals = c("indiv", "pop"))

Two scatter plots from plotResidualsScatterPlot with prediction on the x-axis. Left, IWRES versus individual predictions, mostly within minus 1 and 1. Right, PWRES versus population predictions, spread between about minus 1.7 and 3. Both scatter around zero without a clear trend.
R

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

Two scatter plots from plotResidualsScatterPlot with residuals set to npde, the same output as the earlier NPDE example. NPDE versus time and NPDE versus population predictions, with points scattered around zero, mostly between minus 2 and 2.5, and no visible trend.
R

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

  # Stratification
  plotResidualsScatterPlot(stratify = list(filter = list("SEX", "F")))

Two scatter plots from plotResidualsScatterPlot filtered to female subjects, SEX equals F. IWRES versus time and IWRES versus individual predictions show fewer points than the full data, mostly between minus 1 and 1, with one point near 3 and a few below minus 2.
R

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

Four panel scatter plot from plotResidualsScatterPlot split by WEIGHT groups cut at 75, labeled WEIGHT 54.6-75 and WEIGHT 75-86.4. IWRES versus time for each group, then IWRES versus individual predictions for each group. The lighter group has more points and a wider residual range, about minus 3.4 to 3.2.
R

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

Two scatter plots from plotResidualsScatterPlot with points colored by WEIGHT group, cut at 75. IWRES versus time and IWRES versus individual predictions, with green and pink points mixed across the whole range. No legend is shown, so the group of each color is not labeled.
R

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

Last updated: