问题描述
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=NULL
或 sigma=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 函数看起来很奇怪”之外,还有更好的方法吗?
一些例子:
解决方法
问题太多了!
请尽量在每个帖子中只问一个问题。
但这里有一些关于 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
是顺序颠倒的图像。
代码提示:
-
要生成与现有点模式
X
具有相同点数并在同一窗口中的随机点模式,请使用Y <- runifpoint(ex=X)
。 -
要提取点模式
X
的标记,请使用a <- marks(X)
。要将新标记分配给点模式X
,请使用marks(X) <- b
。 -
要随机排列附加到点模式
X
中的点的标记,请使用Y <- rlabel(X)
。 要将新标记分配给点模式
X
,其中新标记是从给定的值向量m
中随机抽取并替换,请使用Y <- rlabel(X,m,permute=FALSE)
。