Description Usage Arguments Details Author(s) References See Also Examples
View source: R/plot2dProbability.R
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.
1 2 | plot2dProbability(x1, x2, n = 100, p = 0.9, obs.only = FALSE,
bandwith, ...)
|
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
|
p |
numeric vector. The probabilities that the contours should
delineate. E.g. for |
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 |
... |
additional arguments. Passed to |
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.
Original code provided by Pascal H.
Haenggi, P., and R. Weingartner (2011). "Inter-annual variability of runoff and climate within the Upper Rhine River basin, 1808-2007". Hydrological Sciences Journal.
kde2d
from package MASS; contour
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.