Learn R Programming

BNPdensity (version 2019.7.9)

dtnorm: Density truncated normal

Description

Computes the density.

Usage

dtnorm(x, mean = 0, sd = 1, lower = -Inf, upper = Inf, log = FALSE)

Arguments

Details

For internal use

References

Taken from

Examples

Run this code
# NOT RUN {
## The function is currently defined as
function (x, mean = 0, sd = 1, lower = -Inf, upper = Inf, log = FALSE) 
{
    ret <- numeric(length(x))
    ret[x < lower | x > upper] <- if (log) 
        -Inf
    else 0
    ret[upper < lower] <- NaN
    ind <- x >= lower & x <= upper
    if (any(ind)) {
        denom <- pnorm(upper, mean, sd) - pnorm(lower, mean, 
            sd)
        xtmp <- dnorm(x, mean, sd, log)
        if (log) 
            xtmp <- xtmp - log(denom)
        else xtmp <- xtmp/denom
        ret[x >= lower & x <= upper] <- xtmp[ind]
    }
    ret
  }
# }

Run the code above in your browser using DataLab