生成聚集的spatstat标记? [英] generate clustered spatstat marks?

查看:120
本文介绍了生成聚集的spatstat标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人知道如何在spatstat中分配标记,以便它们倾向于在空间上聚集?我有一组经纬度坐标,我想将其分为4组.我想出了如何使用以下代码将标记/组随机分配给这些点:

I was wondering if anyone knows how to assign marks in spatstat so that they tend to cluster spatially? I have a set of lat long coordinates that I want to categorize into 4 groups. I have figured out how to randomly assign marks/groups to these points using the following code:

as.ppp(data, window ,marks=factor(sample(1:4,replace=TRUE)))

但是我不知道如何分配标记,以使各组趋向于占据彼此更近的点.更为复杂的是,我还希望每个组中的点数相同,每次指定数.有人有线索吗?提前致谢!

But I can't figure out how to assign the marks so that groups tend to occupy points closer to one another. As a further complication, I would also like the number of points within each group to be the same, specified number each time. Does anyone have any leads? Thanks in advance!

推荐答案

通常,在spatstat中,我们定义模型来描述/生成随机位置上的点,并可能生成带有随机标记的点.如果我对您的理解正确,那么您有固定的位置集,而您只是想分配随机标记.你有几分?如果没有太多点,一个简单的建议可能是生成一个多元正态分布变量,然后为第一个标记取n_1个最低值,为第二个标记取n_2个下一个值,依此类推.一个简单的示例,其中包含4个相等大小的点组:

Typically in spatstat we define models which describe/generate points at random locations and possibly with random marks. If I understand you correctly you have a fixed set of locations and you simply want to assign random marks. How many points do you have? If you don't have too many points a simple suggestion could be to generate a multivariate normally distributed variable and then take the n_1 lowest values for the first mark, the n_2 next values for the second mark, and so on. A simple example with 4 equal sized groups of points:

library(spatstat)
library(mvtnorm)
set.seed(42) # Make reproducible
X <- redwood # Example data
n <- npoints(redwood)
Xdist <- pairdist(X) # n x n matrix of distances in X
decay_rate <- 1 # Parameter for covariance sturcture
sigma <- exp(-decay_rate * Xdist)
m <- rmvnorm(1, rep(0, n), sigma)
breaks <- quantile(m, probs = c(0, .25, .5, .75, 1)) # breaks to cut marks in four equal sized groups
marks(X) <- cut(m, breaks = breaks, include.lowest=TRUE, labels = 1:4)
plot(X)

这篇关于生成聚集的spatstat标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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