Learn R Programming

REBayes (version 2.56)

L1norm: L1norm for piecewise linear functions

Description

Intended to compute the L1norm of the difference between two distribution functions.

Usage

L1norm(F, G, eps = 1e-06)

Value

A real number.

Arguments

F

A stepfunction

G

Another stepfunction

eps

A tolerance parameter

Author

R. Koenker

Details

Both F and G should be of class stepfun, and they should be non-defective distribution functions. There are some tolerance issues in checking whether both functions are proper distribution functions at the extremes of their support. For simulations it may be prudent to wrap L1norm in try.

Examples

Run this code

# Make a random step (distribution) function with Gaussian knots
rstep <- function(n){
        x <- sort(rnorm(n))
        y <- runif(n)
        y <- c(0,cumsum(y/sum(y)))
        stepfun(x,y)
        }
F <- rstep(20)
G <- rstep(10)
S <- L1norm(F,G)
plot(F,main = paste("||F - G|| = ", round(S,4)))
lines(G,col = 2)

Run the code above in your browser using DataLab