R/ttrans.R

Defines functions ttrans

Documented in ttrans

ttrans <-
function(d,p=-1,qu=NULL,beta=NULL){
  stopifnot(is.vector(d))
  stopifnot((!is.null(qu))|(!is.null(beta)))
  stopifnot((is.null(qu))|(is.null(beta)))

  ad<-abs(d)
  if (!is.null(qu)) beta <- stats::quantile(ad,qu, na.rm=TRUE)

  l<-pmin(ad,beta)
  above<-(!is.na(d))&(ad>beta)
  if (p!=0) l[above]<-l[above]+((ad[above]^p)-(beta^p))/(p*(beta^(p-1)))
  else l[above]<-l[above]+(log(ad[above])-log(beta))*beta
  l*sign(d)
}

Try the tailTransform package in your browser

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

tailTransform documentation built on April 4, 2025, 5:24 a.m.