GenKern (version 1.2-60)

per: Locate value for ith percentage point in a binned distribution

Description

Calculates the value for the ith point in a binned distribution

Usage

per(den, vals, point, na.rm=FALSE, neg.rm=FALSE)

Arguments

den
vector of frequency or density values
vals
vector of values corresponding to the centres of the bins in den, or the bin break points
point
percentage point of the distribution ie: 0.50 is median
na.rm
behaviour for NA's in the vector of density values: FALSE (default) per() will fail with warning if NA's are detected, TRUE per() will assume that these values are really zeros
neg.rm
per() will also fail if any member of the density vector is negative (which can happen occasionally from density functions based on FFT), set this to TRUE to treat these values as zeros

Value

x
value of vals corresponding to the point position

Acknowledgements

Written in collaboration with A.M.Pollard <mark.pollard@rlaha.ox.ac.uk> with the financial support of the Natural Environment Research Council (NERC) grant GR3/11395

See Also

KernSur per density hist bkde bkde2D dpik

Examples

Run this code
# make up some x-y data
x <- seq(1,100)
y <- dnorm(x, mean=40, sd=10)
plot(x,y)                   
# mark the median, 0.1 and 0.9 positions with vertical lines
abline(v=per(y,x,0.5))
abline(v=per(y,x,0.9))
abline(v=per(y,x,0.1)) 
# for a bimodal distribution which doesn't sum to one
x <- c(1:5) 
y <- c(2,3,4,3,4)
per(y,x,0.5) # should return 3.25
# change the previous example to bin extremes
x <- c(1:6)
per(y,x,0.5) # should return 3.75

Run the code above in your browser using DataLab