timeScale: Time scale

timeScaleR Documentation

Time scale

Description

Evaluate the time elapsed between two bounds (x1, x2) into a scaled domain given a rate model and condtions that represent its variables.

Usage

timeScale(
  x1,
  x2,
  model,
  conditions,
  param = list(),
  control = list(),
  interpolation = "constant",
  inverse = FALSE,
  assignConstant = c("lower", "lower")
)

Arguments

x1

numeric vector of initial time from which evaluate the scaling

x2

numeric vector of final time until which evaluate the scaling

model

character corresponding to the name of the rate model (see the details section).

conditions

data.frame with columns named time and variables expected to correspond to those of the model (see the details section).

param

list of parameters of the model.

control

list of arguments that control the behaviour of the model.

interpolation

character corresponding to the name of the interpolating method for conditions. Available methods only include constant at the moment and is the default value.

inverse

logical indicating if the inverse operation (i.e. scaled time to time transformation) should be performed.

assignConstant

character vector of length 2 indicating how to assign scaled time x1 and x2 to time when it remains constant on a time interval. Choices are lower and upper for both end of the interval. The default values are assignConstant = c("lower","lower").

Details

Both x1 and x2 must be in the time range provided by conditions.

model is a function defined by the user that return the rate at which time elapse in the new scale. It takes variables, model parameters (param as a list) and optional arguments (under a list named control). All arguments of the model that is not either param or control are considered variables; therefore, any number of variables and any name can be chosen, with the exception of the word time). The model should accept numeric vectors of the same length as variable and return a value greater or equal to zero. Some models are already included in the package and can serve as template (modelGDD, modelLinear, modelBriere1999).

conditions is a data.frame that contains one column named time and other columns with the same name as the model variables. It represents the evolution of the model variable through time. Checks are made when calling timeScale and timeShift to ensure conditions and the model are compatible. Other checks are made on conditions, including that time must be a strictly increasing numeric, but not necessarily of regular interval. Units of times must simply match the definition of the model, but day is a good choice. Conditions values are considered constant in time until the next measurement.

For the inverse option, a specified scaled time can be associated on an interval of time instead of a unique value, if the rate specified by the model is zero. The time (z1 and z2) associated to x1 and x2 are calculated using timeShift, values are calculated separately using the first and second element of assignConstant.

Value

Return a vector of the same length as x1 and x2 representing the scaled time (or time if inverse = TRUE) elapsed between those values.

Examples

conditions <- data.frame(time = seq(0,30,length.out = 10), temp = rnorm(10, 25, 5))
model <- "modelLinear"
param = list(a = 1, T0 = 10)
x1 = rep(0,10)
x2 = seq(11,20,length.out = 10)
z2 <- timeScale(x1, x2, model = model, conditions = conditions, param = param)
z1 <- rep(0,10,length.out = 10)
timeScale(z1, z2, model = model, conditions = conditions, param = param, inverse = TRUE)


aleblancbio/timescale documentation built on Aug. 27, 2022, 3:01 p.m.