简体   繁体   English

三元KDE的最大核密度的坐标

[英]Coordinates of greatest kernel density for trivariate KDE

I have calculated the kernel density of a 3-column matrix in R using the following code: 我使用以下代码计算了R 3列矩阵的内核密度:

ss<-read.table("data.csv",header=TRUE,sep=",")
x<-ss[,1]
y<-ss[,2]
z<-ss[,3]
ssdata<-c(x,y,z)
ssmat<-matrix(ssdata,,3)
rp<-kde(ssmat)
plot(rp)

What I need now are the (x,y,z) coordinates of the point of maximum kernel density. 我现在需要的是最大内核密度点的(x,y,z)坐标。 Based on the answer provided at on the R-help list , I understand that the kde() function plots the joint density of the three variables in a fourth dimension which is represented in the 3d plot by shading to indicate areas of greater point density. 根据R-help列表上提供的答案,我了解kde()函数将第三个维度的联合密度绘制在第四维上,该维度在3d图中通过阴影表示,以指示更大点密度的区域。 So in effect I am trying to locate the maximum value of this "fourth" dimension. 因此,实际上,我试图找到此“第四”维的最大值。 I suspect that this is a relatively simple problem but I haven't been able to find the answer. 我怀疑这是一个相对简单的问题,但我一直找不到答案。 Any ideas? 有任何想法吗?

You can extract the max value from the info returned from kde . 您可以从kde返回的信息中提取最大值。 To see all the stuff returned, use str(rp) . 要查看返回的所有内容,请使用str(rp)

## Get the indices
inds <- which(abs(rp$estimate - max(rp$estimate)) < 1e-10, arr.ind=T)
xyz <- mapply(function(a, b) a[b], rp$eval.points, inds)

## Add it to plot
plot(rp)
points3d(x=xyz[1], y=xyz[2], z=xyz[3], size=20, col="blue")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM