normalize_pdf: Normalize a pdf

Description Usage Arguments Value Examples

View source: R/utils.R

Description

normalize_pdf normalizes a pdf so that the integral of the pdf is equal to 1

Usage

1
normalize_pdf(x, p_x)

Arguments

x

a vector corresponding to values of a random variable X (length strictly greater than 1)

p_x

a vector containing the density of the RV X at locations x

Value

The normalized pdf

Examples

1
2
3
4
5
6
x <- seq(from=-5,to=5,by=0.1)
p_x <- 2*dnorm(x)
res <- normalize_pdf(x,p_x)
plot(x,p_x)
lines(x,res$p_x)
lines(x,dnorm(x),col='red',lty=2)

exPrior documentation built on Nov. 15, 2019, 1:07 a.m.