微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 spatstat 进行点模式分类:如何选择合适的带宽?

如何解决使用 spatstat 进行点模式分类:如何选择合适的带宽?

我仍在努力寻找对双变量点模式进行分类的最佳方法

Point pattern classification with spatstat: what am I doing wrong?

我现在使用@Adrian 的建议和 sigma=bw.diggle 分析了我的数据集的 110 个样本(因为我想要自动选择带宽)。 f一个“资源选择函数”(RSF),它描述了癌症点过程的强度和协变量(这里是免疫核密度)之间的关系:

Cancer <- split(cells)[["tumor"]]
Immune <- split(cells)[["bcell"]]
Dimmune <- density(Immune,sigma=bw.diggle)
f <- rhohat(Cancer,Dimmune)

我对我得到的一些结果有疑问。十几个 rho 函数看起来很奇怪(中断,单峰)。更改为sigma=NULLsigma=bw.scott(更平滑)后,功能变得“更好”(参见下面的示例)。我还尝试了以下操作:

  cells # bivariate point pattern with marks "tumor" and "bcell"
  o.marks<-cells$marks  # original marks
    #A) randomly re-assign original marks
  a.marks <- sample(cells$marks)
    #B) replace marks randomly with a 50/50 proportion
  b.marks<-as.factor(sample(c("tumor","bcell"),replace=TRUE,size=length(o.marks))) 
    #C) random (homogenIoUs?) pattern with the original number of points 
  randt<-runifpoint(npoints(subset(cells,marks=="tumor")),win=cells$window) 
  randb<-runifpoint(npoints(subset(cells,marks=="bcell")),win=cells$window)
  cells<-superimpose(tumor=randt,bcell=randb)
    #D) tumor points are associated with bcell points (is "clustered" a right term?)
  Cancer<-rpoint(npoints(subset(cells,Dimmune,win=cells$window)
    #E) tumor points are segregated from bcell points
  reversedD<-Dimmune
  density.scale.v<-sort(unique((as.vector(Dimmune$v)[!is.na(as.vector(Dimmune$v))]))) # density scale
  density.scale.v.rev<-rev(density.scale.v)# reversed density scale
  new.image.v<-Dimmune$v
  # Loop over matrix
  for(row in 1:nrow(Dimmune$v)) {
    for(col in 1:ncol(Dimmune$v)) {
      if (is.na(Dimmune$v[row,col])==TRUE){next}
      number<-which(density.scale.v==Dimmune$v[row,col])
      new.image.v[row,col]<-density.scale.v.rev[number]}
  }
  reversedD$v<-new.image.v # reversed density
  Cancer<-rpoint(npoints(subset(cells,reversedD,win=cells$window)

@Adrian 在下面的帖子中给出了生成逆密度热图的更好方法

我无法为 rpoint 密度生成 bw.diggle 模式,因为它产生负数。因此我替换了负数 Dimmune$v[which(Dimmune$v<0)]<-0 并且可以运行 rpoint 然后。正如@Adrian 在下面的帖子中所解释的那样,这是正常现象,可以通过使用 density.ppp 选项 positive=TRUE 更轻松地解决

我首先使用了 bw.diggle,因为 hopskel.test 为我的所有模式指示“聚类”。现在我将使用 bw.scott 进行分析,但这个决定是否有道理?除了“RSF 函数看起来很奇怪”之外,还有更好的方法吗?

一些例子:

示例 10:

sample10 bw.diggle vs bw.scott

样本 20:

sample20 bw.diggle vs bw.scott

样品 110:

sample110 bw.diggle vs bw.scott

解决方法

问题太多了!

请尽量在每个帖子中只问一个问题。

但这里有一些关于 spatstat 的技术问题的答案。

负值: density.ppp 的帮助解释了由于数值效应可能会出现小的负值。要强制密度值为非负值,请在对 positive=TRUE 的调用中使用参数 density.ppp。例如density(Immune,bw.diggle,positive=TRUE)

反转图像:要反转图像 Z 中值的顺序,您可以使用以下代码:

V <- Z
A <- order(Z[])
V[][A] <- Z[][rev(A)]

那么 V 是顺序颠倒的图像。

,

代码提示:

  1. 要生成与现有点模式 X 具有相同点数并在同一窗口中的随机点模式,请使用 Y <- runifpoint(ex=X)

  2. 要提取点模式 X 的标记,请使用 a <- marks(X)。要将新标记分配给点模式 X,请使用 marks(X) <- b

  3. 要随机排列附加到点模式 X 中的点的标记,请使用 Y <- rlabel(X)

  4. 要将新标记分配给点模式 X,其中新标记是从给定的值向量 m 中随机抽取并替换,请使用 Y <- rlabel(X,m,permute=FALSE)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。