plot2dProbability: Plot contours of constant probability of bivariate...

Description Usage Arguments Details Author(s) References See Also Examples

View source: R/plot2dProbability.R

Description

The probability density is first estimated using the bivariate normal kernel kde2d from package MASS. Contours of constant probability are then drawn on the scatterplot with the observations.

Usage

1
2
plot2dProbability(x1, x2, n = 100, p = 0.9, obs.only = FALSE,
                  bandwith, ...)

Arguments

x1

numeric vector. The first variable.

x2

numeric vector. The second variable.

n

integer or integer vector of length two. Defines the number of grid points to discretise the plane with the observations. Passed to kde2d.

p

numeric vector. The probabilities that the contours should delineate. E.g. for p=0.9 the contours encompass the smallest region such that the probability of a new observation falling in this region equals 0.9.

obs.only

logical. Integrate the complete pdf over the domain of the observations or only at the location of the observations?

bandwith

real number or vector of length two. Defines the bandwith for the normal kernel. Passed to kde2d.

...

additional arguments. Passed to plot.default.

Details

Missing values in x1 and x2 are not allowed. If obs.only=TRUE the kernel density is sampled at the location of the points defined by x1 and x2. The quantiles of these density values (with probability 1-p) are then used to draw the contours. For obs.only=FALSE the complete density function is integrated.

Author(s)

Original code provided by Pascal H.

References

Haenggi, P., and R. Weingartner (2011). "Inter-annual variability of runoff and climate within the Upper Rhine River basin, 1808-2007". Hydrological Sciences Journal.

See Also

kde2d from package MASS; contour

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## two independent Gaussian random variables
x1 <- rnorm(1000,mean=0,sd=1)
x2 <- rnorm(1000,mean=1,sd=2)
plot2dProbability(x1,x2,p=c(0.5,0.7,0.9),pch=19,cex=0.5)

## manually select the bandwith
plot2dProbability(x1,x2,p=c(0.5,0.7,0.9),pch=19,cex=0.5,bandwith=5)
plot2dProbability(x1,x2,p=c(0.5,0.7,0.9),pch=19,cex=0.5,bandwith=0.05)

## a non-normal distribution
x1 <- c(runif(500,0,1),runif(500,1,5))
x2 <- c(runif(500,0,5),runif(500,4,5))
plot2dProbability(x1,x2,p=c(0.5,0.7,0.9),pch=19,cex=0.5)

hydro-giub/hydroBE documentation built on Sept. 20, 2019, 9:27 a.m.