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

Description Usage Arguments Value Acknowledgements Note Author(s) See Also Examples

Description

Calculates the value for the ith point in a binned distribution

Usage

1
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

returns a 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

Note

Not restricted to uniform bin widths but due to linear interpolation gets less accurate as bin widths deviate from uniformity. The vectors must be in ascending order of bin centres bin break points. The density can be a frequency in that it doesn't have to sum to unity.

Out of character for the rest of the GenKern package this function does assume proper bins rather than ordinates, although if a density estimate has been generated using KernSec then the ordinate vector can be used as a first order approximation to bin centres.

Author(s)

David Lucy <d.lucy@lancaster.ac.uk> http://www.maths.lancs.ac.uk/~lucy/
Robert Aykroyd <r.g.aykroyd@leeds.ac.uk>http://www.amsta.leeds.ac.uk/~robert/

See Also

KernSur per density hist bkde bkde2D dpik

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 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

GenKern documentation built on May 2, 2019, 3:25 a.m.

Related to per in GenKern...