plot.fit: Plotting function for nls.predict and nlme.predict

View source: R/plot.fit.r

plot.fitR Documentation

Plotting function for nls.predict and nlme.predict

Description

Plots residual, predicted, or partial residial plots based on x generated by qP functions nlme.predict and nls.predict.

Usage

## S3 method for class 'fit'
plot(
  x,
  ...,
  newFunc,
  yLabel,
  xLabel,
  label.cex = 1.25,
  xLimits,
  yLimits,
  title,
  plot.title = TRUE,
  layout,
  aspect,
  mnplot = TRUE,
  seplot = TRUE,
  logX = FALSE,
  logY = FALSE,
  pointcol = gray[8],
  linecol = qp.blue,
  axis.lim.widener = 0.035,
  do.plot = TRUE,
  abline = NULL
)

Arguments

x

the output from nls.predict or nlme.predict, i.e. class 'fit'

...

any other arguments to be passed on to the lattice call

newFunc

the function to plot. If not suppliued will be taken from x

yLabel

same as ylab

xLabel

same as xlab

label.cex

fontmszie of axes labels

xLimits

same as xlim

yLimits

same as ylim

title

place a title above

plot.title

logical indicating if a plot title should be written

layout

will be passed on a lattice argument layout

aspect

lattice banking aspect

mnplot

logical indicating an average plot to be created as opposed to 'raw data

seplot

logical indicating is error bars need to be drawn

logX

logarithmic X axis?

logY

logarithmic Y axis?

pointcol

color of dots

linecol

color of

axis.lim.widener

scalar to stretch the x and y axis. Use in case data or predictions are not visible anymore

do.plot

Defaults to T (create the plot) if F it will output the prediction data

abline

will be passed on to the lattice call as is

Value

A plot

Examples

pkpdData = example.pkpdData()

DNase1 <- subset(DNase, Run == 1)

## using a selfStart model
fm1DNase1 <- nls(density ~ SSlogis(log(conc), Asym, xmid, scal), DNase1)
summary(fm1DNase1)

fm1DNase1.predict = nls.predict(density ~ conc,object = fm1DNase1)
plot(fm1DNase1.predict)
fm1DNase1.predict = nls.predict(density ~ conc,object = fm1DNase1)
plot(fm1DNase1.predict, logX = TRUE)

EFF.1comp.1abs <- function(dose, tob, cl, v, ka, keo)
{
  # Effect-site concentration for 1-compartment model, 1st-order absorption

  kel = cl / v

  # Define coefficients
  A = 1/(kel-ka) / (keo-ka)
  B = 1/(ka-kel) / (keo-kel)
  C = 1/(ka-keo) / (kel-keo)

  # Return effect-site concentration
  dose*ka*keo/v * (A*exp(-ka*tob) + B*exp(-kel*tob) + C*exp(-keo*tob))
}
fit.PD004.nlme = nlme.run(model = value ~ base +
 EFF.1comp.1abs(dose, time, cl * exp(cl.eta), v, ka, keo)
 , data = subset(pkpdData,type == "PD" & dose > 0 & value > 0.5),
                          fixed = base + cl + v + ka + keo ~ 1,
                          random = cl.eta ~ 1,
                          groups = ~ id,
                          start = c(base = 1, cl = 1, v = 10
                          , ka = 1, keo = 0.01),
                          problem = "True Model",
                          reference = 4)
summary(fit.PD004.nlme$object)
nlme.extract(fit.PD004.nlme$object)$table

# simple fit vs time
fit.PD004.pred.nlme = nlme.predict(func = value ~ time
   , fit.PD004.nlme$object)
plot(fit.PD004.pred.nlme)
fit.PD004.pred.nlme = nlme.predict(func = value ~ time
   , fit.PD004.nlme$object, method = "partial.residuals")
plot(fit.PD004.pred.nlme) ## this is the same: PARTIAL RESIDUALS
fit.PD004.pred.nlme = nlme.predict(func = value ~ time
   , fit.PD004.nlme$object, method = "prediction")
plot(fit.PD004.pred.nlme) ## 'simple' prediction for all xCovariate

## note that prediction and partial residual type of model fit
## plots are very different

# fit vs time by dose
fit.PD004.pred.nlme = nlme.predict(func = value ~ time | dose
   , fit.PD004.nlme$object)
plot(fit.PD004.pred.nlme)
fit.PD004.pred.nlme = nlme.predict(func = value ~ time | dose
   , fit.PD004.nlme$object, method = "residuals")
plot(fit.PD004.pred.nlme, yLimits = c(-1,1))
plot(fit.PD004.pred.nlme, yLimits = c(-1,1)
   , abline = list(h = 0, lty = 2))

qPharmetra/qpToolkit documentation built on May 24, 2023, 8:52 a.m.