如何使用数据帧中的标记对超帧的点模式进行子集化

How to subset point patterns of a hyperframe using marks from a dataframe

我有一个 93 行的超帧。每行包含 class ppp 的树干图以及地块级分组因子。标记数据框提供点特定数据,例如每个点的直径、种类和高度。 我需要根据标记的数据帧对点模式进行子集化,然后 运行 L est 函数,这需要汇集数据。我找到了单点模式子集标记的示例和基于超帧的列子集超帧的示例,但我还没有看到从具有多个标记的数据帧中调用因子级别的超帧子集点模式的示例。任何指导将不胜感激。

我可以按地块级因素对超帧进行子集化,假设 a、b 和 c 植被类型,然后 运行 每个地块的最小值,根据植被类型汇集输出,并绘制pooled Lest(Baddeley et al. 2015 的第 684 页提供了一个有用的示例)。

然而,我未能根据数据帧的特定标记对超帧的点模式进行子集化。我不确定我的数据结构是否会导致问题,所以我在下面包括了,或者我是否只是混淆了与超帧的多点模式相关联的数据帧的子集标记的代码(此处为 R 新手。列表中的列表变得混乱)。

数据构建:

    z.list <- mapply(as.ppp, X = df.list, W = window.list, SIMPLIFY=FALSE) 
     #df.list contains x,y coordinates, followed by columns of point specific 
      #data. 
    h <- hyperframe(X=z.list)
    H <- cbind.hyperframe(h, plot.df1)#combine the point pattern and marks 
     #with plot level data

数据结构:

     str(H)
    'hyperframe':    93 rows and 14 columns 
     $ X : objects of class ppp 
     $ PLOTID : factor 0102U001 0104U001 0104U002 ... 
     $ Group1 : integer 1 2 1 ... 
     $ Group2 : numeric 2.0 2.5 2.0 ... 

    str(H[1,]$X) #str of the ppp of the hyperframes first row
    List of 1
    $ X:List of 6
    ..$ window    :List of 5
    .. ..$ type  : chr "polygonal"
    .. ..$ xrange: num [1:2] 516441 516503
    .. ..$ yrange: num [1:2] 3382698 3382804
    .. ..$ bdry  :List of 1
    .. .. ..$ :List of 2
    .. .. .. ..$ x: num [1:4] 516503 516502 516441 516442
    .. .. .. ..$ y: num [1:4] 3382698 3382804 3382804 3382698
    .. ..$ units :List of 3
    .. .. ..$ singular  : chr "metre"
    .. .. ..$ plural    : chr "metres"
    .. .. ..$ multiplier: num 1
    .. .. ..- attr(*, "class")= chr "unitname"
    .. ..- attr(*, "class")= chr "owin"
    ..$ n         : int 107
    ..$ x         : num [1:107] 516501 516473 516470 516474 516474 ...
    ..$ y         : num [1:107] 3382801 3382723 3382726 3382734 3382732 ...
    ..$ markformat: chr "dataframe"
    ..$ marks     :'data.frame':    107 obs. of  3 variables:
    .. ..$ DBH_Class: Factor w/ 16 levels "11.25","13.75",..: 7 5 13 12 8 4 9 
    .. ..$ Ingrowth : Factor w/ 7 levels "DD","I_DD","I_LD_MY",..: 7 6 6 7 
    .. ..$ PlotID    : Factor w/ 93 levels "0102U001","0104U001",..: 1 1 1 1 
    ..- attr(*, "class")= chr "ppp"
    - attr(*, "class")= chr [1:5] "ppplist" "solist" "anylist" "listof" ...

以上对我来说似乎是正确的,但我注意到虽然标记是用 str 函数打印的,但 is.multipoint 输出为 FALSE。不确定这是否是我的问题的一部分。 以下内容非常适合位于超帧行中的情节级别因素。

    H$L <- with(H, Lest((X),rmax=40))
    L.VT.split <- split(H$L, H$VEG_TYPE) #plot level factor
    L.VT.pool <- anylapply(L.VT.split, pool)
    plot(L.VT.pool,cbind(pooliso, pooltheo, hiiso,loiso)-r~r,
      shade=c("hiiso","loiso"),equal.scales=TRUE, main='')

但是如何使用数据帧中的标记执行相同的操作呢?


我不确定我是否完全理解这个问题,但我会尽力提供 无论如何,一些有用的提示...

对于 H 中的每一行,您都有一个包含标记的点模式 data.frame 中的信息(三列称为 DBH_ClassIngrowthPlotID)。以下是一些具有该结构的假数据:

library(spatstat)
set.seed(42)
df1 <- data.frame(x = runif(3), y = runif(3), DBH_Class = factor(1:3),
                  Ingrowth = LETTERS[1:3], PlotID = letters[1:3])
X1 <- as.ppp(df1, W = square(1))
df2 <- data.frame(x = runif(3), y = runif(3), DBH_Class = factor(1:3),
                  Ingrowth = LETTERS[1:3], PlotID = letters[1:3])
X2 <- as.ppp(df2, W = square(1))
H <- hyperframe(X = list(X1 = X1, X2 = X2))
H
#> Hyperframe:
#>       X
#> 1 (ppp)
#> 2 (ppp)
plot(H$X, which.marks = "Ingrowth")

通过特定标记(Ingrowth 在 这个例子)使用 subset:

X1B <- subset(X1, Ingrowth == "B")

HX 列中的每个模式都相同:

H$XB <- with(H, subset(X, Ingrowth == "B"))
H
#> Hyperframe:
#>       X    XB
#> 1 (ppp) (ppp)
#> 2 (ppp) (ppp)
plot(H$XB, which.marks = "Ingrowth")