【问题标题】:How to subset point patterns of a hyperframe using marks from a dataframe如何使用数据帧中的标记对超帧的点模式进行子集化
【发布时间】:2019-04-02 21:33:38
【问题描述】:

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

我可以通过地块级别因子对超帧进行子集化,比如说 a、b 和 c 植被类型,然后为每个地块运行 Lest,根据植被类型汇集输出,并绘制汇集的 Lest(第 684 页) Baddeley et al. 2015 提供了一个有用的例子)。

但是,我未能根据数据帧的特定标记对超帧的点模式进行子集化。我不确定我的数据结构是否会导致问题,所以我在下面包含了,或者我只是对将与超帧的多个点模式相关联的数据帧标记子集的代码感到困惑(这里是 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='')

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

【问题讨论】:

    标签: r spatstat


    【解决方案1】:


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

    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 in 这个例子)使用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")
    

    【讨论】:

    • 非常有帮助!我现在了解了如何使用子集函数在超帧中创建另一个 ppp 对象。简单而正是我所需要的。谢谢。
    • 太棒了。然后您可以继续接受答案,因此当人们搜索该网站时,该问题会被标记为已回答。
    猜你喜欢
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 2018-11-05
    • 2020-10-13
    相关资源
    最近更新 更多