Learn R Programming

pi0 (version 1.4-1)

pdf.dist: Distance between densities

Description

Compute the distance between two density functions

Usage

pdf.dist(f1, f2, method = c("Hellinger", "abdif"))

Arguments

f1,f2

Two functions of one argument, both of which are densities defined over the whole real line.

method

character; specifying the definition of distance. Current choices are Hellinger and abdif, the latter of which is the integrated absolute differences between the two function.

Value

a numeric scalar which is the computed distance, or NA_real_ if any problem occurs.

Details

Numerical integration is performed from -Inf to Inf. Hence, the two functions must be able to accept arguments over the whole real line.

Examples

Run this code
# NOT RUN {
# Hellinger distance betwee standard normal and log-normal
pdf.dist(dnorm, dlnorm, 'Hell') # 0.5981035

# absolute difference between standard normal and standard cauchy
f2=function(x)dt(x,1)
pdf.dist(dnorm, f2, 'abd')  #[1] 0.5023312
# }

Run the code above in your browser using DataLab