R/calcPParms.R

Defines functions calcPParms

calcPParms <-
function(p, dat, tr = 'log10', upr = Inf) {
  # Intercept must be first term!
  which.int <- grep('int', names(p))
  if(length(which.int)>1) stop('calcPParms called with more than one intercept (int) term for p argument: ', names(p)[which.int])
  if(length(which.int) == 0) {
    p <- c(int = 0, p)
    which.int = 1
  }
  r <- rep(p[[which.int]], nrow(dat)) # Rep required in case int is the only parameter

  for(i in names(p)[-which.int]) {
    r <- r + p[[i]]*dat[[i]]
  }

  if(tr == 'log10') r <- 10^r
  if(tr == 'logistic') r <- (exp(r)/(1 + exp(r)))

  # Apply limit
  if (any(r > upr)) {
    warning('Some calculated primary parameters are at the limit. Check input parameters.')
  }
  r[r > upr] <- upr

  return(r)

}

logistic <-
function (x) {
  exp(x)/(1 + exp(x))
}

logit <-
function (p) {
  log(p/(1 - p))
}
sashahafner/ALFAM2 documentation built on Jan. 31, 2024, 11:16 a.m.