Problem: Based on a n x 2 data matrix i want a kernel estimate of the bivariate density. However, i also wish to specify wich points the density should be calculated at. I can offcourse just write the full kernel density estimate as a R-code, but surely there must already exist some package for this operation? The package density(), seems to create a new matrix (depending on n), where the density is estimated. But i dont know how to specify the points for this package. -- View this message in context: http://n4.nabble.com/density-estimates-for-fixed-points-tp1556081p1556081.html Sent from the R help mailing list archive at Nabble.com.
On Feb 15, 2010, at 8:08 AM, geir wrote:> > Problem: > Based on a n x 2 data matrix i want a kernel estimate of the bivariate > density.> However, i also wish to specify wich points the density should be > calculated at. > > I can offcourse just write the full kernel density estimate as a R- > code, but > surely there must already exist some package for this operation? > > The package density(),Where did you get said package? (I tried CRAN, BioC and R-Forge without success.) Or are you perhaps confused about the difference between functions and packages, as the use of "()" after a "package" name might suggest?? Aside from that concern, try: library(MASS) ?kde2D Lets you determine the grid. Or: RSiteSearch("2D grid") # 153 hits with a fairly wide range of potential solutions> seems to create a new matrix (depending on n), where > the density is estimated. But i dont know how to specify the points > for this > package. > >-- David Winsemius, MD Heritage Laboratories West Hartford, CT
Sorry, i did indeed mean function - not package. kde2d lets you determine the grid - you choose "n" and "lims", which gives you and n x n matrix for which the density is estimated (Seems like the output is meant for graphical purposes). But i have a matrix consisting of points (x,y) where i want the corresponding density estimates f(x,y). i cant see how i can do this using "n" and "lims". I have tried to search for simil problems, but so fare i havent found any (may be because its too trivial?). -- View this message in context: http://n4.nabble.com/density-estimates-for-fixed-points-tp1556081p1556204.html Sent from the R help mailing list archive at Nabble.com.
On Feb 15, 2010, at 10:02 AM, geir wrote:> > Sorry, i did indeed mean function - not package. > > kde2d lets you determine the grid - you choose "n" and "lims", which > gives > you and n x n matrix for which the density is estimated (Seems like > the > output is meant for graphical purposes). But i have a matrix > consisting of > points (x,y) where i want the corresponding density estimates f(x,y).Exactly the sort of data situation that kde2d expects.> i cant > see how i can do this using "n" and "lims".As far as I can tell kde2D does exactly what you asked. (And there were 150+ other citations that might be worth looking at with my second suggestion, if I have have misunderstood your request.) My suggestion would be to work through the examples on the kde2d help page, examine the objects created (since "x" and "y" will then have two meanings in their respective objects) and then come back if you are still confused. When you do come back, you should bring with you a sample dataset for testing purposes and show an example of how you think your output should look.> > I have tried to search for simil problems, but so fare i havent > found any > (may be because its too trivial?). > --David Winsemius, MD Heritage Laboratories West Hartford, CT
Trafim Vanishek posted a similar problem: "Joint density approximation?" (without any solution for kde2d). Here is an example to illustrate my problem. Originally data is for example: a=runif(10) (yes, the number of data should be larger) b=runif(10) c=kde2d(a,b,n=10,lims=c(0,1,0,1)) attach(c) The equally spaced vectors x and y returned are: x = [1] 0.0000000 0.1111111 0.2222222 0.3333333 0.4444444 0.5555556 0.6666667 [8] 0.7777778 0.8888889 1.0000000 y = [1] 0.0000000 0.1111111 0.2222222 0.3333333 0.4444444 0.5555556 0.6666667 [8] 0.7777778 0.8888889 1.0000000 and the corresponding density estimates for any combination of these coordinates is a 10 x 10 matrix z. I want the density estimates for the points in a k x 2 matrix like for example A=[(0,7,0.3),(0.1,0.2),...,(0.5,0.9)]^T which is not equally spaced, (and i do not need the density of every combination of these coordinates). So that the output is f(0.7,0.3), f(0.1,0.2), ... ,f(0.5,0.9), where "f" is the kernel estimator based on a and b. Geir -- View this message in context: http://n4.nabble.com/density-estimates-for-fixed-points-tp1556081p1557231.html Sent from the R help mailing list archive at Nabble.com.