L1norm: L1norm for piecewise linear functions

View source: R/misc.R

L1normR Documentation

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)

Arguments

F

A stepfunction

G

Another stepfunction

eps

A tolerance parameter

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.

Value

A real number.

Author(s)

R. Koenker

Examples


# 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)


REBayes documentation built on Aug. 19, 2023, 5:10 p.m.