normalize: Normalize two pdfs

Description Usage Arguments Examples

View source: R/normalize.R

Description

Normalize two pdfs

Usage

1
normalize(x, tt, props = NULL)

Arguments

x

Probability density function(s) evaluated at grid x. Input should be either a vector or matrix. If input is a matrix, each column represents a single pdf.

tt

a numeric grid defined in x.

props

the value each density should integrate to.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
tt <- seq(0, 9, length.out = 1e4)
# 2 poper densities
x1 <- cbind(dexp(tt, .5), dexp(tt, 2))
# still 2 poper densities
x2 <- normalize(10*x1, tt)
# 2 densities that integrate to .5
x3 <- normalize(x1, tt, props = c(.5, .5))
# plot the results
matplot(tt, cbind(x1, x2, x3), type = "l", ylab = "density",
        col = rep(1:3, each = 2), lty = rep(1:2, 3), las = 1, bty = "n")
legend("topright", legend = rep(paste0("x", 1:3), each = 2),
       col = rep(1:3, each = 2), lty = rep(1:2, 3), bty = "n")

DstarM documentation built on Aug. 29, 2020, 1:06 a.m.