Pascal Martin
2010-May-04 14:33 UTC
[R] Kernel density estimate plot for 3-dimensional data
Hi! I have a problem with Kernel density estimate plot for 3-dimensional data in ks-package. Here the example: # load ks, spatstat # three-dimensional kernel density of B B <- pp3(runif(300), runif(300), runif(300), box3(c(0,1))) x <- unclass(B$data)$df H <- Hpi(x) fhat <- kde(x, H=H) plot(fhat) plot(fhat, axes=FALSE, box=FALSE, drawpoints=TRUE); axes3d(c('x','y','z')) If I try to insert my own coordinates instead of the artificial 3D-pattern, it does not work. It would be great, if anybody could help me! Thanks Pascal [[alternative HTML version deleted]]
Duncan Murdoch
2010-May-04 14:46 UTC
[R] Kernel density estimate plot for 3-dimensional data
On 04/05/2010 10:33 AM, Pascal Martin wrote:> Hi! > > I have a problem with Kernel density estimate plot for 3-dimensional data in ks-package. > Here the example: > > # load ks, spatstat > # three-dimensional kernel density of B > B <- pp3(runif(300), runif(300), runif(300), box3(c(0,1))) > x <- unclass(B$data)$df > H <- Hpi(x) > fhat <- kde(x, H=H) > plot(fhat) > plot(fhat, axes=FALSE, box=FALSE, drawpoints=TRUE); axes3d(c('x','y','z')) > > If I try to insert my own coordinates instead of the artificial 3D-pattern, it does not work. > It would be great, if anybody could help me!You need to be more explicit about what "does not work" means. The example above works (though I don't like the axes in the first plot; I prefer what you get with plot(fhat, box=FALSE)). What problem are you having? Duncan Murdoch
Pascal Martin
2010-May-04 15:04 UTC
[R] Kernel density estimate plot for 3-dimensional data
________________________________ An: Duncan Murdoch <murdoch.duncan@gmail.com> Gesendet: Dienstag, den 4. Mai 2010, 17:03:46 Uhr Betreff: AW: [R] Kernel density estimate plot for 3-dimensional data #B <- pp3(runif(300), runif(300), runif(300), box3(c(0,1))) creates a 3d pattern with random points. But I want it to create a Kernel density estimate plot with my coordinates. I show it in an example:> x<- scan()1: 1 2 3 4 5 6 7 8 9 10 11: Read 10 items> y<- scan()1: 10 9 8 7 6 5 4 3 2 1 11: Read 10 items> z<- scan()1: 6 5 7 4 8 3 9 2 10 1 11: Read 10 items> B<- pp3(x,y,z, c(0,10), c(0,10), c(0,10))> x <- unclass(B$data)$df > H <- Hpi(x)From this point, it shows an error in chol.default(S12) and accordingly the rest does not go on.> fhat <- kde(x, H=H)> plot(fhat) > plot(fhat, axes=FALSE, box=FALSE, drawpoints=TRUE); axes3d(c('x','y','z'))________________________________ Von: Duncan Murdoch <murdoch.duncan@gmail.com> CC: r-help@r-project.org Gesendet: Dienstag, den 4. Mai 2010, 16:46:03 Uhr Betreff: Re: [R] Kernel density estimate plot for 3-dimensional data On 04/05/2010 10:33 AM, Pascal Martin wrote:> Hi! > > I have a problem with Kernel density estimate plot for 3-dimensional data in ks-package. > Here the example: > > # load ks, spatstat > # three-dimensional kernel density of B > B <- pp3(runif(300), runif(300), runif(300), box3(c(0,1))) > x <- unclass(B$data)$df > H <- Hpi(x) > fhat <- kde(x, H=H) > plot(fhat) > plot(fhat, axes=FALSE, box=FALSE, drawpoints=TRUE); axes3d(c('x','y','z')) > > If I try to insert my own coordinates instead of the artificial 3D-pattern, it does not work.[[elided Yahoo spam]] You need to be more explicit about what "does not work" means. The example above works (though I don't like the axes in the first plot; I prefer what you get with plot(fhat, box=FALSE)). What problem are you having? Duncan Murdoch [[alternative HTML version deleted]]
Duncan Murdoch
2010-May-04 15:17 UTC
[R] Kernel density estimate plot for 3-dimensional data
On 04/05/2010 11:03 AM, Pascal Martin wrote:> #B <- pp3(runif(300), runif(300), runif(300), box3(c(0,1))) > creates a 3d pattern with random points. > But I want it to create a Kernel density estimate plot with my coordinates. > I show it in an example: > > > x<- scan() > 1: 1 2 3 4 5 6 7 8 9 10 > 11: > Read 10 items > > y<- scan() > 1: 10 9 8 7 6 5 4 3 2 1 > 11: > Read 10 items > > z<- scan() > 1: 6 5 7 4 8 3 9 2 10 1 > 11: > Read 10 items > > B<- pp3(x,y,z, c(0,10), c(0,10), c(0,10)) > > > x <- unclass(B$data)$df > > H <- Hpi(x) > > From this point, it shows an error in chol.default(S12) > and accordingly the rest does not go on. >Those points all lie in a plane (y = 11-x); I imagine that causes the density estimate to overflow. I get the same problem with your data, but not with non-planar data. Duncan Murdoch> > fhat <- kde(x, H=H) > > > plot(fhat) > > plot(fhat, axes=FALSE, box=FALSE, drawpoints=TRUE); axes3d(c('x','y','z')) > > > > ________________________________ > Von: Duncan Murdoch <murdoch.duncan at gmail.com> > An: Pascal Martin <pascal15martin at yahoo.de> > CC: r-help at r-project.org > Gesendet: Dienstag, den 4. Mai 2010, 16:46:03 Uhr > Betreff: Re: [R] Kernel density estimate plot for 3-dimensional data > > On 04/05/2010 10:33 AM, Pascal Martin wrote: > > Hi! > > > > I have a problem with Kernel density estimate plot for 3-dimensional data in ks-package. > > Here the example: > > > > # load ks, spatstat > > # three-dimensional kernel density of B > > B <- pp3(runif(300), runif(300), runif(300), box3(c(0,1))) > > x <- unclass(B$data)$df > > H <- Hpi(x) > > fhat <- kde(x, H=H) > > plot(fhat) > > plot(fhat, axes=FALSE, box=FALSE, drawpoints=TRUE); axes3d(c('x','y','z')) > > > > If I try to insert my own coordinates instead of the artificial 3D-pattern, it does not work. > > It would be great, if anybody could help me! > > You need to be more explicit about what "does not work" means. The > example above works (though I don't like the axes in the first plot; I > prefer what you get > with plot(fhat, box=FALSE)). What problem are you having? > > Duncan Murdoch > > > >
Maybe Matching Threads
- How to translate the 2D-density matrix (the output of bkde2D function) into matrix of datapoints' amounts?
- overlaid filled contour plots
- 3-d kernel smooth by the "kde" function
- Kernel Density estimation - locfit package
- How to get the datapoints of an density estimationwithlocfit?