time_calc: Create time variables for usage in NONMEM analyses

View source: R/time_calc.r

time_calcR Documentation

Create time variables for usage in NONMEM analyses

Description

This function calculates the most important time variables based on multiple variables in a data frame.

Usage

time_calc(
  data,
  datetime,
  evid = NULL,
  addl = NULL,
  ii = NULL,
  amt = "AMT",
  id = "ID",
  dig = 2
)

Arguments

data

data frame to perform the calculations on

datetime

character identifying the date/time variable (POSIXct) within the data frame

evid

character identifying the event ID (EVID) within the data frame

addl

character identifying the additional dose levels (ADDL) within the data frame

ii

character identifying the interdose interval (II) within the data frame

amt

character identifying the amount variable (only needed if evid is not provided)

id

character identifying the ID or subject variable

dig

numeric indicating with how many digits the resulting times should be available

Details

The function calculates the TIME, TALD (time after last dose) and TAFD (time after first dose). The different time variables are calculated in hours, where a POSIXct for the datetime variable is expected. The function takes into account ADDL and II records when provided, to correctly identify the TALD. One must be cautious however when having ADDL/II and a complex dosing schedule (e.g. alternating dose schedules, more than 1 dose per day, multiple compounds administration). In general it is good practice to double check the output for multiple subjects in case of complex designs including ADDL/II.

Value

a data frame with the calculated times

Author(s)

Richard Hooijmaijers

Examples


dfrm <- data.frame(ID=rep(1,5), dt=Sys.time() + c(0,8e+5,1e+6,2e+6,3e+6),
                   AMT=c(NA,10,NA,0,NA), II=rep(24,5),EVID=c(0,1,0,1,0))
time_calc(dfrm,"dt","EVID")

amp.dm documentation built on March 13, 2026, 5:08 p.m.