[R] confidence bounds using contour plot

From: Pascal Hänggi <pascal.haenggi_at_hydrologie.unibe.ch>
Date: Wed, 25 Jun 2008 17:38:21 +0200


Hello

I'm trying to calculate 2d confindence bounds into a scatterplot using the function "kde2d" (package MASS) and a contour plot.

I found a similar post providing a solution - unfortunatly I do not realy understand which data I have to use to calculated the named "quantile":

Post URL: http://tolstoy.newcastle.edu.au/R/help/03b/5384.html

> (...)
>
>> Is there a way to plot a contour (empirical?) containing, say, 95% of the
>> values.
>
>Yes. You need a 2D density estimate (e.g. kde2d in MASS) then compute the
>density values at the points and draw the contour of the density which
>includes 95% of the points (at a level computed from the sorted values via
>quantile()).
>
>--
>Brian D. Ripley
>(...)

--
Example:

x <- rnorm(1000, mean = 0, sd = 1)
y <- rnorm(1000, mean = 1, sd = 1.3)
kerneld <- kde2d(x, y, n = 200, lims = c(-1.0, 1.0, 0.0, 2.0))

confidencebound <- quantile(kerneld$z, probs= 0.95)

plot(x, y, pch=19, cex=0.5)
contour(kerneld, levels = confidencebound, col="red", add = TRUE)
--

How can I calculate the right contour containing 95% of the values?

Thank's for your help.
Pascal

R 2.7.0, Win XP

 
--
  Pascal Hänggi
 
  Universität Bern
  Geographisches Institut, Gruppe für Hydrologie
  Hallerstrasse 12
  CH-3012 Bern
 
  +41 (0)31 631 54 71
  pascal.haenggi_at_hydrologie.unibe.ch
  http://www.hydrologie.unibe.ch
--

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 25 Jun 2008 - 15:40:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 25 Jun 2008 - 16:30:53 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive