r - Calculate probability of point on 2d density surface -


if calculate 2d density surface of 2 vectors in example:

library(mass) <- rnorm(1000) b <- rnorm(1000, sd=2) f1 <- kde2d(a, b, n = 100) 

i following surface

filled.contour(f1) 

enter image description here

the z-value estimated density.

my question is: possible calculate probability of single point, e.g. = 1, b = -4

[as i'm not statistician maybe wrong wording. sorry that. know - if possible @ - probability point occurs.]

thanks every comment!

if specify area, area has probability respect density function. of course single point not have probability different zero. have non-zero density @ point. then?

the density limit of integral of probability density integrated on area divided normal area measure normal area measure goes zero. (it actual rather hard state correctly, needed few tries , still not optimal).

all basic calculus. easy write routine calculate integral of density on area, although imagine mass has standard ways use more sophisticated integration techniques. here quick routine threw based on example:

library(mass) n <- 100 <- rnorm(1000) b <- rnorm(1000, sd=2) f1 <- kde2d(a, b, n = 100) lims <- c(min(a),max(a),min(b),max(b))  filled.contour(f1)  prob <- function(f,xmin,xmax,ymin,ymax,n,lims){   ixmin <- max( 1, n*(xmin-lims[1])/(lims[2]-lims[1]) )   ixmax <- min( n, n*(xmax-lims[1])/(lims[2]-lims[1]) )   iymin <- max( 1, n*(ymin-lims[3])/(lims[4]-lims[3]) )    iymax <- min( n, n*(ymax-lims[3])/(lims[4]-lims[3]) )   avg <- mean(f$z[ixmin:ixmax,iymin:iymax])   probval <- (xmax-xmin)*(ymax-ymin)*avg   return(probval) } prob(f1,0.5,1.5,-4.5,-3.5,n,lims) # [1] 0.004788993 prob(f1,-1,1,-1,1,n,lims) # [1] 0.2224353 prob(f1,-2,2,-2,2,n,lims) # [1] 0.5916984 prob(f1,0,1,-1,1,n,lims) # [1] 0.119455 prob(f1,1,2,-1,1,n,lims) # [1] 0.05093696 prob(f1,-3,3,-3,3,n,lims) # [1] 0.8080565 lims # [1] -3.081773  4.767588 -5.496468  7.040882 

caveat, routine seems right , giving reasonable answers, has not undergone anywhere near scrutiny give production function.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -