Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread David Winsemius
I do agree with the recommendation to consider car::dataEllipse() for plotting a best fit for the theoretical bivariate Normal situation. However, the bagplot function from Has Peter Wold: http://www.wiwi.uni-bielefeld.de/~wolf/#software is more likely to "line up" and be suitable for drawi

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread Michael Friendly
On 3/3/2012 12:34 PM, drflxms wrote: Thanx a lot Greg for the hint and letting me not alone with this! Tried ellipse and it works well. But I am looking for something more precise. The ellipse fits the real border to the nearest possible ellipse. I want the "real" contour, if possible. The 'co

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread drflxms
Please allow one (hopefully ;) last question: Do you think the code I adopted from Hänggi is valid in selecting a contour which encloses i.e. 68% of the scatter-plot data? - I am still not completely shore... still looking for the reason of the different result of Hänggis and Foresters code. Should

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread drflxms
Puhh, I am really happy to read that the idea was not completely sensless. This would have heavily damaged my anyway labile view of the world of statistics ;) In any case I need to get to know more about bivariate normal distributions! Any literature recommendations? Felix Am 03.03.12 22:13, schr

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread drflxms
Greg, extremely cool thoughts! Thank you for delving into it this deep. As I mentioned, I am a neurologist with unfortunately poor statistical training. You are professional statisticians. So I'd like to apologize for any unprofessional nomenclature and strange thoughts beforehand. As my previous

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread Greg Snow
To further explain. If you want contours of a bivariate normal, then you want ellipses. The density for a bivariate normal (with 0 correlation to keep things simple, but the theory will extend to correlated cases) is proportional to exp( -1/2 ( x1^2/v1 + x2^2/v2 ) so a contour of the distributi

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread peter dalgaard
On Mar 3, 2012, at 20:25 , drflxms wrote: > "Once you go into two dimensions, SD loses all meaning, and adding > nonparametric density estimation into the mix doesn't help, so just stop > thinking in those terms!" > > This makes me really think a lot! Is plotting the 0,68 confidence > interval i

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread Greg Snow
The key part of the ellipse function is: matrix(c(t * scale[1] * cos(a + d/2) + centre[1], t * scale[2] * cos(a - d/2) + centre[2]), npoints, 2, dimnames = list(NULL, names)) Where (if I did not miss anything) the variable 't' is derived from a chisquare distribution and the c

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread drflxms
Wow, David, thank you for these sources, which I just screened. bagplot looks most promising to me. I found it in the package ‘aplpack’ as well as in the R Graph Gallery http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=112 Ellipses are not exactly what I am heading for. I am looking

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread drflxms
Thank you very much for your thoughts! Exactly what you mention is, what I am thinking about during the last hours: What is the relation between the den$z distribution and the z distribution. That's why I asked for ecdf(distribution)(value)->percentile earlier this day (thank you again for your qu

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread David Winsemius
On Mar 3, 2012, at 12:34 PM, drflxms wrote: Thanx a lot Greg for the hint and letting me not alone with this! Tried ellipse and it works well. But I am looking for something more precise. The ellipse fits the real border to the nearest possible ellipse. I want the "real" contour, if possible.

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread peter dalgaard
On Mar 3, 2012, at 17:01 , drflxms wrote: > # this is the critical block, which I still do not comprehend in detail > z <- array() > for (i in 1:n){ >z.x <- max(which(den$x < x[i])) >z.y <- max(which(den$y < y[i])) >z[i] <- den$z[z.x, z.y] > } As far as I can tell, the po

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread drflxms
Thanx a lot Greg for the hint and letting me not alone with this! Tried ellipse and it works well. But I am looking for something more precise. The ellipse fits the real border to the nearest possible ellipse. I want the "real" contour, if possible. Meanwhile I found an interesting function named

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread Greg Snow
Look at the ellipse package (and the ellipse function in the package) for a simple way of showing a confidence region for bivariate data on a plot (a 68% confidence interval is about 1 SD if you just want to show 1 SD). On Sat, Mar 3, 2012 at 7:54 AM, drflxms wrote: > Dear all, > > I created a bi

Re: [R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread drflxms
OK, the following seems to work still do not understand exactly why... library(MASS) # parameters: n<-100 # generate samples: set.seed(138813) #seed <- .Random.seed x<-rnorm(n); y<-rnorm(n) # estimate non-parameteric density surface via kernel smoothing den<-kde2d(x, y, n=n) # store z values of

[R] contour for plotting confidence interval on scatter plot of bivariate normal distribution

2012-03-03 Thread drflxms
Dear all, I created a bivariate normal distribution: set.seed(138813) n<-100 x<-rnorm(n); y<-rnorm(n) and plotted a scatterplot of it: plot(x,y) Now I'd like to add the 2D-standard deviation. I found a thread regarding plotting arbitrary confidence boundaries from Pascal Hänggi http://www.mai