Calculates the probability of an obervations occurring in a 2D cell using HPDregionplot Given a sample calculates the bivariate region of highest marginal posterior density for two variables, using kde2d from MASS to calculate a bivariate density.

probFn2(x, y, prob = c(0.5, 0.75, 0.95), n = 21, h = c(bandwidth.nrd(x),
  bandwidth.nrd(y)), lims = NULL, na.rm = FALSE)

Arguments

x

a vector

y

a vector

prob

probability levels

n

number of points at which to evaluate the density grid

h

bandwidth of 2D kernel smoother (previous default value was c(1,1), which worked poorly with some plots with very small scales; if not specified, defaults to values in kde2d)

lims

limits, specified as (x.lower,x.upper,y.lower,y.upper) (passed to kde2d)

na.rm

logical; if true, any NA and NaN's are removed from x before calculations

...

any other argument

Value

a data.frame with three variables x, y coordinates of the grid points, vectors of length n. level contours corresponding to prob

Examples

# NOT RUN {
   y=rnorm(20)
   x  =rnorm(20)
   prob(x,y)
# }