compute.cwres(xpose4generic)R Documentation

Compute the Conditional Weighted Residuals

Description

This function computes the conditional weighted residuals (CWRES) from a NONMEM run. CWRES are an extension of the weighted residuals (WRES), but are calculated based on the first-order with conditional estimation (FOCE) method of linearizing a pharmacometric model (WRES are calculated based on the first-order (FO) method). The function requires a NONMEM table file and an extra output file that must be explicitly asked for when running NONMEM, see details below.

Usage

compute.cwres(run.number,
              tab.prefix="cwtab",
              sim.suffix="",
              est.tab.suffix=".est",
              deriv.tab.suffix=".deriv",
              old.file.convention=FALSE,
              id="ALL",
              printToOutfile=TRUE,
              onlyNonZero=TRUE,
              ...)

xpose.calculate.cwres(object,
                      cwres.table.prefix = "cwtab",
                      tab.suffix = "",
                      sim.suffix = "sim",
                      est.tab.suffix=".est",
                      deriv.tab.suffix=".deriv",
                      old.file.convention=FALSE,
                      id = "ALL",
                      printToOutfile = TRUE,
                      onlyNonZero = FALSE,
                      classic = FALSE,
                      ...)

Arguments

run.number The run number of the NONMEM from which the CWRES are to be calculated.
tab.prefix The prefix to two NONMEM file containing the needed values for the computation of the CWRES, described in the details section.
sim.suffix The suffix ,before the ".", of the NONMEM file containing the needed values for the computation of the CWRES, described in the details section. For example, the table files might be named cwtab1sim.est and cwtab1sim.deriv, in which case sim.suffix="sim".
est.tab.suffix The suffix, after the ".", of the NONMEM file containing the estimated parameter values needed for the CWRES calculation.
deriv.tab.suffix The suffix, after the ".", of the NONMEM file containing the derivatives of the model with respect to the random parameters needed for the CWRES calculation.
old.file.convention For backwards compatibility. Use this if you are using the previous file convention for CWRES (table files named cwtab1, cwtab1.50, cwtab1.51, ... , cwtab.58 for example).
id Can be either "ALL" or a number matching an ID label in the datasetname. Value is fixed to "ALL" for xpose.calculate.cwres.
printToOutfile Logical (TRUE/FALSE) indicating whether the CWRES values calculated should be appended to a copy of the datasetname. Only works if id="ALL". If chosen the resulting output file will be datasetname.cwres. Value is fixed to TRUE for xpose.calculate.cwres.
onlyNonZero Logical (TRUE/FALSE) indicating if the return value (the CWRES values) of compute.cwres should include the zero values associated with non-measurement lines in a NONMEM data file.
object An xpose.data object.
cwres.table.prefix The prefix to the NONMEM table file containing the derivative of the model with respect to the etas and epsilons, described in the details section.
tab.suffix The suffix to the NONMEM table file containing the derivative of the model with respect to the etas and epsilons, described in the details section.
classic Indicates if the function is to be used in the classic menu system.
... Other arguments passed to basic functions in code.

Details

compute.cwres
This function is the computational 'brains' of the CWRES computation and does not require an Xpose data object to work. The function simply reads in the following two files:

      paste(tab.prefix,run.number,sim.suffix,est.tab.suffix,sep="")
      paste(tab.prefix,run.number,sim.suffix,deriv.tab.suffix,sep="")

Which might be for example:

      cwtab1.est
      cwtab1.deriv

and (depending on the input values to the function) returns the CWRES in vector form as well as creating a new table file named:

      paste(tab.prefix,run.number,sim.suffix,sep="")

Which might be for example:

      cwtab1

xpose.calculate.cwres
This function is a wrapper around the function compute.cwres. It computes the CWRES for the model file associated with the Xpose data object input to the function. If possible it also computes the CWRES for any simulated data associated with the current Xpose data object. If you have problems with this function try using compute.cwres and then rereading your dataset into Xpose.

Value

compute.cwres Returns a vector containing the values of the CWRES.
xpose.calculate.cwres Returns an Xpose data object that contains the CWRES. If simulated data is present, then the CWRES will also be calculated for that data.

Setting up the NONMEM model file

In order for this function to calculate the CWRES, NONMEM must be run while requesting certain tables and files to be created. How these files are created differs depending on if you are using $PRED or ADVAN as well as the version of NONMEM you are using. These procedures are known to work for NONMEM VI but may be different for NONMEM V. We have attempted to indicate where NONMEM V may be different, but this has not been extensively tested!

This procedure can be done automatically using Perl Speaks NONMEM (PsN) and we highly recommend using PsN for this purpose. After installing PsN just type 'execute [modelname] -compute_cwres'. See http://psn.sourceforge.net for more details.

There are five main insertions needed in your NONMEM control file:

    1. $ABB COMRES=X.

    Insert this line directly after your $DATA line. The value of X is the number of ETA() terms plus the number of EPS() terms in your model. For example for a model with three ETA() terms and two EPS() terms the code would look like this:

           $DATA temp.csv IGNORE=@
           $ABB COMRES=5
           $INPUT ID TIME DV MDV AMT EVID
           $SUB ADVAN2 TRANS2
    

    2. Verbatim code.

    3. INFN routine.

    4. cwtab*.deriv table file.

    A special table file needs to be created to print out the values contained in the COMRES variables. In addition the ID, IPRED, MDV, DV, PRED and RES data items are needed for the computation of the CWRES. The following code should be added to the NONMEM model file. In this example we continue to assume that we are using a model with three ETA() terms and two EPS() terms, extra terms should be added for new ETA() and EPS() terms in the model file. We also assume the model file is named something like 'run1.mod', thus the prefix to these file names 'cwtab' has the same run number attached to it (i.e. 'cwtab1'). This should be changed for each new run number.

           $TABLE ID COM(1)=G11 COM(2)=G21 COM(3)=G31
           COM(4)=H11 COM(5)=H21 
           IPRED MDV NOPRINT ONEHEADER FILE=cwtab1.deriv
    

    5. $ESTIMATION.

    To compute the CWRES, the NONMEM model file must use (at least) the FO method with the POSTHOC step. If the FO method is used and the POSTHOC step is not included then the CWRES values will be equivalent to the WRES. The CWRES calculations are based on the FOCE approximation, and consequently give an idea of the ability of the FOCE method to fit the model to the data. If you are using another method of parameter estimation (e.g. FOCE with interaction), the CWRES will not be calculated based on the same model linearization procedure.

Author(s)

Andrew Hooker

References

Hooker A, Staatz CE, Karlsson MO. Conditional weighted residuals, an improved model diagnostic for the FO/FOCE methods. PAGE 15 (2006) Abstr 1001 [http://www.page-meeting.org/?abstract=1001].

See Also

absval.cwres.vs.cov.bw, absval.cwres.vs.pred.by.cov, absval.cwres.vs.pred, autocorr.cwres, ind.plots.cwres.hist, ind.plots.cwres.qq, cwres.dist.hist, cwres.dist.qq, cwres.vs.cov, cwres.vs.idv.bw, cwres.vs.idv, cwres.vs.pred.bw cwres.wres.vs.pred cwres.wres.vs.idv basic.gof.cwres

Examples

## Not run: 
## Capture CWRES from cwtab5.est and cwtab5.deriv
cwres <- compute.cwres(5)
mean(cwres)
var(cwres)

## Capture CWRES from cwtab1.est and cwtab1.deriv, do not print out, allow zeroes
cwres <- compute.cwres("1", printToOutFile = FALSE,
  onlyNonZero = FALSE)

## Capture CWRES for ID==1
cwres.1 <- compute.cwres("1", id=1)

## xpdb5 is an Xpose data object
## We expect to find the required NONMEM run and table files for run
## 5 in the current working directory
xpdb5 <- xpose.data(5)

## Compare WRES, CWRES
xpdb5 <- xpose.calculate.cwres(xpdb5)
cwres.wres.vs.idv(xpdb5) 

## End(Not run)

[Package xpose4generic version 4.0.2 Index]