R/dutpn.R

Defines functions dutpn

Documented in dutpn

dutpn<-function(x, sigma=1, lambda=0, type=1, log=FALSE)
{
	if(type!=1 & type!=2 & type!=3 & type!=4) stop("type must be 1, 2, 3 or 4")
	if (is.null(x)) 
        stop("x must be specified")
    if (is.null(sigma)) 
        stop("sigma must be specified")
    if (is.null(lambda)) 
        stop("lambda must be specified")
    if (sigma <= 0) 
        stop("sigma must be positive")
    if (any(x <= 0)) 
        stop("x's must be positive")
	if(type==1) lf = -log(sigma)-2*log(x)-pnorm(lambda,log.p=TRUE)+dnorm((1-x)/(sigma*x)-lambda,log=TRUE)
	if(type==2) lf = -log(sigma)-2*log1p(-x)-pnorm(lambda,log.p=TRUE)+dnorm(x/(sigma*(1-x))-lambda,log=TRUE)
	if(type==3) lf = -log(sigma)-log(x)-pnorm(lambda,log.p=TRUE)+dnorm(log(x)/sigma+lambda,log=TRUE)
	if(type==4) lf = -log(sigma)-log1p(-x)-pnorm(lambda,log.p=TRUE)+dnorm(log1p(-x)/sigma+lambda,log=TRUE)
	if (!log) 
        lf = exp(lf)
    lf
}

Try the tpn package in your browser

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

tpn documentation built on Sept. 28, 2023, 1:06 a.m.