R/nonmemboxcox.R

Defines functions nonmemboxcox

Documented in nonmemboxcox

#' Box-Cox transform typically used in NONMEM
#'
#' Parameters are typically treated as lognormally-distributed by NONMEM users.
#' Box-Cox transforms are typically applied to the exponentiated individual ETA parameters;
#' this means the parameter is neither Box-Cox distributed nor lognormally-distributed, but both.
#' To get the "Box-Cox Transform" as it would be relevant for CV% calculation, these properties
#' have to be considered.
#'
#' @param x random vector. Must be positive.
#' @param lambda shape parameter
#' @param theta centrality parameter
#' @param inv inverse transform
#'
#' @return Box-Cox transformed or untransformed vector
#' @export
#'
#' @examples
nonmemboxcox <- function(x,lambda,theta=1,inv=FALSE) {
  if (!inv) {
    normalized <- x/theta
    {
      if (lambda==0) bc1 <- log(normalized)
      else bc1 <- ((normalized^lambda) - 1)/lambda
    }
    return( log(theta) + bc1 )
  } else {
    normalized <- x - log(theta)
    {
      if (lambda==0) bc1 <- exp(normalized)
      else bc1 <- (normalized*lambda + 1)^(1/lambda)
    }
    return( theta*bc1 )
  }
}

Try the pmxcv package in your browser

Any scripts or data that you put into this service are public.

pmxcv documentation built on May 29, 2024, 7:28 a.m.