ks包装中kde对象的尺寸,R [英] dimensions of kde object from ks package, R

查看:134
本文介绍了ks包装中kde对象的尺寸,R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R中的ks包,使用距离和深度信息估算2d空间利用率。我想做的是使用95%的轮廓输出来获得最大的垂直和水平距离。因此,从本质上讲,我希望能够获得所得95%轮廓的尺寸或尺寸。

I am using the ks package from R to estimate 2d space utilization using distance and depth information. What I would like to do is to use the 95% contour output to get the maximum vertical and horizontal distance. So essentially, I want to be able to get the dimensions or measurements of the resulting 95% contour.

下面是一段代码,例如,

Here is a piece of code with as an example,

require(ks)

dist<-c(1650,1300,3713,3718)
depth<-c(22,19.5,20.5,8.60)

dd<-data.frame(cbind(dist,depth))

## auto bandwidth selection
H.pi2<-Hpi(dd,binned=TRUE)*1
ddhat<-kde(dd,H=H.pi2)

plot(ddhat,cont=c(95),lwd=1.5,display="filled.contour2",col=c(NA,"palegreen"),
     xlab="",ylab="",las=1,ann=F,bty="l",xaxs="i",yaxs="i",
     xlim=c(0,max(dd[,1]+dd[,1]*0.4)),ylim=c(60,-3))  

有关如何执行此操作的任何信息将非常有帮助。

Any information about how to do this will be very helpful. Thanks in advance,

推荐答案

要从您的'kde'对象创建95%的轮廓多边形:

To create a 95% contour polygon from your 'kde' object:

library(raster)
im.kde <- image2Grid (list(x = ddhat$eval.points[[1]], y =  ddhat$eval.points[[2]], z = ddhat$estimate))
kr <- raster(im.kde)

在构造多边形之前,可能希望将栅格重新采样到更高的分辨率,并在创建多边形对象之前包括以下两行:

It is likely that one will want to resample this raster to a higher resolution before constructing polygons, and include the following two lines, before creation of the polygon object:

new.rast <- raster(extent(im.kde),res = c(50,50))
kr <- resample(kr, new.rast)

bin.kr <- kr
bin.kr[bin.kr < contourLevels(k, prob = 0.05)]<-NA
bin.kr[bin.kr > 0]<-1
k.poly<-rasterToPolygons(bin.kr,dissolve=T)

请注意,结果与霍桑·贝尔(Hawthorne Beier)的GME函数 kde相似但不相同。他确实使用了ks中的kde函数,但必须对输出多边形做一些稍有不同的事情。

Note that the results are similar, but not identical, to Hawthorne Beier's GME function 'kde'. He does use the kde function from ks, but must do something slightly different for the output polygon.

这篇关于ks包装中kde对象的尺寸,R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆