Function spatstat.geom::ppp() creates a two-dimensional point-pattern object (ppp.object), i.e., an R object of S3 class 'ppp'. A point-pattern contains the \(x\)- and \(y\)-coordinates in an observation window (Chapter 25) and may contain
The S3 methods na.omit.ppp() and na.exclude.ppp()omits and excludes, respectively, the missing marks from a point-pattern. Both functions return a point-pattern.
If missingness exists in the marks, the 'na.action'-attribute of the marks is saved as an attribute of the returned point-pattern.
Example: functions na.omit.ppp() and na.exclude.ppp() on 'none'-markformat
Note that the S3 methods is.numeric.ppp() and spatstat.geom::is.multitype.ppp() behave differently for a point-pattern with 'dataframe'-markformat, e.g., betacells (Section 10.4).
Example: functions is.numeric.ppp() on 'dataframe'-markformat
spatstat.data::betacells |>is.numeric()# type area # FALSE TRUE
27.3Math-groupGeneric of numeric-marks
The S3 method Math.ppp() performs the transformations, in the Math-groupGeneric, on one or more numeric-marks of a point-pattern, and returns a point-pattern with the transformed marks. The \(x\)- and \(y\)-coords and the multi-type marks of the input point-pattern remain unchanged. This function serves a similar purpose to the S3 method spatstat.geom::Math.im().
Listing 27.5 applies log- and log1p-transformations on the point-pattern bronzefilter (Section 10.5) with 'vector'-markformat.
Listing 27.5: Example: log-transformations on 'vector'-markformat
Code
list(original = spatstat.data::bronzefilter,log = spatstat.data::bronzefilter |>log(),log1p = spatstat.data::bronzefilter |>log1p()) |>lapply(FUN = \(i) { i |> spatstat.geom::marks.ppp() |>summary.default() })# $original# Min. 1st Qu. Median Mean 3rd Qu. Max. # 0.013 0.120 0.160 0.167 0.200 0.467 # # $log# Min. 1st Qu. Median Mean 3rd Qu. Max. # -4.3428 -2.1203 -1.8326 -1.8989 -1.6094 -0.7614 # # $log1p# Min. 1st Qu. Median Mean 3rd Qu. Max. # 0.01292 0.11333 0.14842 0.15244 0.18232 0.38322
Listing 27.6 applies log-transformations on the numeric-marks in the point-pattern betacells (Section 10.4) with 'dataframe'-markformat.
Listing 27.6: Example: log-transformations on numeric-marks in 'dataframe'-markformat
Code
list(original = spatstat.data::betacells,log = spatstat.data::betacells |>log()) |>lapply(FUN = \(i) { i |> spatstat.geom::marks.ppp() |>with.default(expr = area) |>summary.default() })# $original# Min. 1st Qu. Median Mean 3rd Qu. Max. # 168.3 248.8 279.4 291.2 324.2 514.4 # # $log# Min. 1st Qu. Median Mean 3rd Qu. Max. # 5.126 5.517 5.633 5.653 5.782 6.243
Listing 27.7 applies log-transformation on the \(x\)- and \(y\)-coordinates-only point-pattern vesicles (Section 10.19).
Listing 27.7: Exception: log-transformations on 'none'-markformat
The S3 generic function density_marks() finds the kernel densitys (Becker, Chambers, and Wilks 1988) of the numeric-marks. Package groupedHyperframe (v0.3.2) implements the following S3 methods (Table 27.3),
The S3 generic function kerndens() extracts the $y element of a density object. Package groupedHyperframe (v0.3.2) implements the following S3 methods (Table 27.5),
The default method kerndens.default() is simply a wrapper of stats::density.default()$y.
Example: function kerndens.default()
d = faithful$eruptions |>density(bw ='sj')kd = faithful$eruptions |>kerndens(bw ='sj')stopifnot(identical(d$y, kd))
The S3 method kerndens.ppp() finds the kernel density estimates of one or more numeric-marks of a point-pattern. The S3 method kerndens.ppp() is simply a wrapper of the S3 method density_marks.ppp() (Section 27.4).
Exception: function kerndens.ppp() on 'none'-markformat
Note that the S3 method quantile.ppp() is completely different from the S3 method spatstat.explore::SpatialQuantile.ppp().
27.6 Nearest Neighbours of multi-type-marks, Alternative Interface
Function .nncross() is a wrapper of function spatstat.geom::nncross(., what = 'dist'), designed to provide an interface consistent with function spatstat.explore::Gcross(), etc. This design allows the internal batch-processing mechanism (Section 27.14) to be shared between Table 27.19 and Table 27.20.
Example: interface of functions .nncross() and spatstat.explore::Gcross()
.nncross |>args()# function (X, i, j, ...) # NULLspatstat.explore::Gcross |>args()# function (X, i, j, r = NULL, breaks = NULL, ..., correction = c("rs", # "km", "han")) # NULL
nn = spatstat.data::ants |> spatstat.geom::split.ppp() |>with.default(expr = { spatstat.geom::nncross.ppp(X = Cataglyphis, Y = Messor, what ='dist') })nn |>summary()# Min. 1st Qu. Median Mean 3rd Qu. Max. # 12.21 21.38 31.38 36.27 42.52 90.26
Alternative approaches are to use function .nncross(), specifying the parameters i and j
as integer indices corresponding to the levels of the multi-type-marks in ants (Section 10.2), i.e, 1L for 'Cataglyphis' and 2L for 'Messor', as in Listing 27.10.
Function .nncross() returns an invisibleNULL-value (Listing 27.12) if the character values supplied to the i and j parameters do not match any levels of the multi-type-marks in ants (Section 10.2).
Listing 27.12: Exception: function .nncross(), non-existing levels
The S3 generic function aggregate_marks() aggregates various statistics (other than the quantiles, Section 27.5) of the marks within a point-pattern, or within each point pattern of an object containing one or more point-patterns. Package groupedHyperframe (v0.3.2) implements the following S3 methods (Table 27.6),
The S3 method aggregate_marks.ppp() aggregates a set of fully customizable summary statistics, in the parameter FUN or expr, of the marks within a point-pattern. For each type of the mark-format of the input point-pattern,
markformat = 'none' (Section 27.7.1): returns an invisibleNULL-value.
markformat = 'vector' (Section 27.7.2): computes the summary statistics of the numeric- or multi-type-marks.
markformat = 'dataframe' (Section 27.7.3): aggregates the numeric- and/or multi-type-marks, according to a grouping structure determined by one-or-more multi-type-marks in the parameter by (Section 27.7.3.1), using the workhorse function stats::aggregate.data.frame().
The returned aggregated summary statistics can be vectorized for downstream use (Section 28.3).
The S3 method aggregate_marks.ppp() generalizes the aggregation-of-marks in the S3 method spatstat.geom::summary.ppp() (v3.6.1); the differences of the two functions are explained in Table 27.7. Listing 27.13 summarizes the S3 methods for the class 'summary.ppp' in the spatstat.* family of packages.
Table 27.7: Functions aggregate_marks.ppp() vs. spatstat.geom::summary.ppp() (v3.6.1)
aggregate_marks.ppp()
spatstat.geom::summary.ppp()
Summary of \(x\)- and \(y\)-Coordinates
Not Available
Available
Summary of Observation Window
Not Available
Available
Mark(s) Statistics
Fully customizable in parameters FUN or expr
Those available in function base::summary.default()
Listing 27.15 shows the S3 method spatstat.geom::summary.ppp() on a point-pattern without any mark.
Listing 27.15: Review: function spatstat.geom::summary.ppp() on 'none'-markformat
Code
spatstat.data::vesicles |> spatstat.geom::summary.ppp() |> spatstat.geom::print.summary.ppp()# Planar point pattern: 37 points# Average intensity 0.0001336176 points per square nm# # Coordinates are given to 12 decimal places# # Window: polygonal boundary# 2 separate polygons (1 hole)# vertices area relative.area# polygon 1 69 317963.0 1.150# polygon 2 (hole) 23 -41052.9 -0.148# enclosing rectangle: [22.6796, 586.2292] x [11.9756, 1030.7] nm# (563.5 x 1019 nm)# Window area = 276910 square nm# Unit of length: 1 nm# Fraction of frame area: 0.482
27.7.2'vector'-markformat
Listing 27.16, Listing 27.17 and Listing 27.18 aggregate the sample mean, or both the sample mean and the sample standard deviation sd, or the common summary statistics, of the numeric-mark in the point-pattern spruces (Section 10.17). The parameter z in Listing 27.17 represents the numeric-mark as a vector, and may be replaced by any other symbol of the user’s choice.
Listing 27.16: Example: sample mean
spatstat.data::spruces |>aggregate_marks(FUN = mean)# mean # 0.2503731
spatstat.data::spruces |>aggregate_marks(FUN = summary.default)# Min. 1st Qu. Median Mean 3rd Qu. Max. # 0.1600000 0.2200000 0.2450000 0.2503731 0.2700000 0.3700000
Listing 27.19 provides equivalent return as Listing 27.18 using the S3 method spatstat.geom::summary.ppp().
Listing 27.19: Review: function spatstat.geom::summary.ppp(), numeric-mark in 'vector'-markformat
Code
spatstat.data::spruces |> spatstat.geom::summary.ppp() |> spatstat.geom::print.summary.ppp()# Marked planar point pattern: 134 points# Average intensity 0.06296992 points per square metre# # Coordinates are given to 1 decimal place# i.e. rounded to the nearest multiple of 0.1 metres# # marks are numeric, of type 'double'# Summary:# Min. 1st Qu. Median Mean 3rd Qu. Max. # 0.1600 0.2200 0.2450 0.2504 0.2700 0.3700 # # Window: rectangle = [0, 56] x [0, 38] metres# Window area = 2128 square metres# Unit of length: 1 metre
Listing 27.20 and Listing 27.21 aggregate the (relative) frequencies of the multi-type-mark in the point-pattern ants (Section 10.2). The parameter z in Listing 27.21 represents the multi-type-mark as a vector, and may be replaced by any other symbol of the user’s choice.
Listing 27.20: Example: frequencies
spatstat.data::ants |>aggregate_marks(FUN = table)# Cataglyphis Messor # 29 68
Listing 27.21: Example: relative frequencies
spatstat.data::ants |>aggregate_marks(FUN = \(z) table(z)/length(z))# Cataglyphis Messor # 0.2989691 0.7010309
Listing 27.22: Review: function spatstat.geom::summary.ppp(), multi-type-mark in 'vector'-markformat
Code
spatstat.data::ants |> spatstat.geom::summary.ppp() |> spatstat.geom::print.summary.ppp()# Marked planar point pattern: 97 points# Average intensity 0.0002261486 points per square unit (one unit = 0.5 feet)# # Coordinates are integers# i.e. rounded to the nearest unit (one unit = 0.5 feet)# # Multitype:# frequency proportion intensity# Cataglyphis 29 0.2989691 6.761144e-05# Messor 68 0.7010309 1.585372e-04# # Window: polygonal boundary# single connected closed polygon with 11 vertices# enclosing rectangle: [-25, 803] x [-49, 717] units# (828 x 766 units)# Window area = 428922 square units# Unit of length: 0.5 feet# Fraction of frame area: 0.676
27.7.3'dataframe'-markformat
Listing 27.23 aggregates the numeric-mark area and multi-type-mark type in the point-pattern betacells (Section 10.4) using the statistics specified as R language in the parameter expr.
Listing 27.23: Example: numeric- and multi-type-mark in 'dataframe'-markformat
spatstat.data::betacells |>aggregate_marks(expr =list(area =summary.default(area),type =table(type) ))# $area# Min. 1st Qu. Median Mean 3rd Qu. Max. # 168.3 248.8 279.4 291.2 324.2 514.4 # # $type# type# off on # 70 65
Listing 27.25 provides equivalent return as Listing 27.23 using the S3 method spatstat.geom::summary.ppp().
Listing 27.25: Review: function spatstat.geom::summary.ppp(), numeric and multi-type-mark in 'dataframe'-markformat
Code
spatstat.data::betacells |> spatstat.geom::summary.ppp() |> spatstat.geom::print.summary.ppp()# Marked planar point pattern: 135 points# Average intensity 0.0001816677 points per square micron# # Coordinates are given to 2 decimal places# i.e. rounded to the nearest multiple of 0.01 microns# # Mark variables: type, area# Summary:# type area # off:70 Min. :168.3 # on :65 1st Qu.:248.8 # Median :279.4 # Mean :291.2 # 3rd Qu.:324.2 # Max. :514.4 # # Window: rectangle = [28.08, 778.08] x [16.2, 1007.02] microns# (750 x 990.8 microns)# Window area = 743115 square microns# Unit of length: 1 micron
27.7.3.1 Use of Parameter by
The S3 method aggregate_marks.ppp() accepts a two-sided formula for the parameter by, if the input point-pattern has 'dataframe'-markformat. The left-hand-side of the formula by contains the name(s) of one or more mark(s) to be summarized, e.g.,
The right-hand-side of the formula by contains the name(s) of one or more multi-type-mark(s) to indicate the grouping structure of the aggregation, e.g.,
Note that the S3 method spatstat.geom::summary.ppp() (v3.6.1) does not provide summary statistics by-group (Listing 27.25).
27.7.3.1.1 Aggregate by One Group
Listing 27.26 and Listing 27.27 aggregate the numeric-mark area by the multi-type-mark type of the point-pattern betacells (Section 10.4), using the sample mean, or both the sample mean and the sample standard deviation sd. The parameter z in Listing 27.27 represents the numeric-mark area in the left-hand-side of the formula by, and may be replaced by any other symbol of the user’s choice.
Listing 27.26: Example: sample mean of area-by-type
spatstat.data::betacells |>aggregate_marks(by = area ~ type, FUN = mean)# type area# 1 off 259.7214# 2 on 325.1169
Listing 27.27: Example: sample mean and sd of area-by-type
spatstat.data::betacells |>aggregate_marks(by = area ~ type, FUN = \(z) {c(mean =mean(z), sd =sd(z)) })# type area.mean area.sd# 1 off 259.72143 40.86083# 2 on 325.11692 60.71534
Listing 27.30 and Listing 27.31 aggregate one multi-type-mark season by another multi-type-mark group of the point-pattern gorillas (Section 10.11), using the (relative) frequencies. The parameter z in Listing 27.31 represents the multi-type-mark season in the left-hand-side of the formula by, and may be replaced by any other symbol of the user’s choice.
Listing 27.30: Example: frequencies of season-by-group
spatstat.data::gorillas |>aggregate_marks(by = season ~ group, FUN = table)# group season.dry season.rainy# 1 major 150 200# 2 minor 125 172
Listing 27.31: Example: relative frequencies of season-by-group
spatstat.data::gorillas |>aggregate_marks(by = season ~ group, FUN = \(z) table(z)/length(z))# group season.dry season.rainy# 1 major 0.4285714 0.5714286# 2 minor 0.4208754 0.5791246
appending a numeric mark hr.last (Section 27.9), the time difference in hours between the put-out out.date and the discovery dis.date, to the existing marks;
selecting a subset of points that represent 'forest' and/or 'grass' fires caused by railroads 'rrds' and/or recreation 'rec';
removing the points with any missing marks (Section 27.1);
performing log1p-transformations on the numeric-marks (Section 27.3) fnl.size and hr.last.
Listing 27.35 aggregates the log1p-transformed numeric-mark fnl.size by the interaction of two multi-type-marks fire.type and cause in the point-pattern nbfL (Listing 27.34), using the sample mean and the sample standard deviation sd. The parameter z in Listing 27.35 represents the log1p-transformed numeric-mark fnl.size in the left-hand-side of the formula by, and may be replaced by any other symbol of the user’s choice.
Listing 27.35: Example: sample mean and sd of log1p-transformed fnl.size-by-fire.type:cause
Listing 27.36 aggregates the log1p-transformed numeric-marks fnl.size and hr.last by the interaction of two multi-type-marks fire.type and cause in the point-pattern nbfL (Listing 27.34), using the sample mean and the sample standard deviation sd. The parameter z in Listing 27.36 represents the log1p-transformed numeric-marks fnl.size and hr.last, respectively, in the left-hand-side of the formula by, and may be replaced by any other symbol of the user’s choice. Note that the use of cbind() in the formula by follows that of the S3 method stats::aggregate.data.frame().
Listing 27.36: Example: sample mean and sd of log1p-transformed fnl.size-and-hr.last-by-fire.type:cause
The design of the S3 class 'ppp' specifies that if the marks are a data frame with only 1 column, then the marks will be converted to a vector.
This design choice was made a long time ago, in order to avoid problems that would otherwise occur in the rest of the spatstat code.
If we were to retrospectively change the specification, we would have a lot of work to do in the rest of the code, and the documentation.
On the other hand, function grouped_ppp() (Chapter 3, Section 19.1) relies on the support of ncol-1L'dataframe'-marks. As an ad hoc solution, the author defines
an (internal) derived class 'ppp_tzh' (initials of T. Zhan) that inherits from the S3 class 'ppp', and
an S3 method `[.ppp_tzh` that respects the ncol-1L'dataframe'-marks. The S3 method `[.ppp_tzh` is a teeny-tiny modification of the S3 method spatstat.geom::`[.ppp`. Permision from Dr. Baddeley? GPL-2?
Listing 27.39 retains the name of the mark hladr as the column name of the ncol-1L'dataframe'-marks (Listing 27.40), for downstream analysis.
Listing 27.39: Example: function grouped_ppp() with one mark
s_a = wrobel_lung |>grouped_ppp(formula = hladr ~ OS + gender + age | patient_id/image_id)
Listing 27.40: Example: support of ncol-1L'dataframe'-markformat, name of mark retained
The S3 generic syntactic sugar `append_marks<-`() appends an additional mark to the existing marks. Package groupedHyperframe (v0.3.2) implements the following S3 methods (Table 27.8),
The S3 method `append_marks<-.ppp`() appends an additional mark to (the existing marks of) an point-pattern.
Example: function `append_marks<-.ppp`(), no existing marks
ves = spatstat.data::vesicles(npt = spatstat.geom::npoints.ppp(ves))# [1] 37set.seed(12); append_marks(ves) =rlnorm(n = npt)ves |> spatstat.geom::print.ppp()# Marked planar point pattern: 37 points# marks are numeric, of storage type 'double'# window: polygonal boundary# enclosing rectangle: [22.6796, 586.2292] x [11.9756, 1030.7] nmset.seed(31); append_marks(ves) =replicate(n =2L, expr =rpois(n = npt, lambda =4), simplify =FALSE)ves |> spatstat.geom::print.ppp()# Marked planar point pattern: 37 points# Mark variables: m1, m2, m3 # window: polygonal boundary# enclosing rectangle: [22.6796, 586.2292] x [11.9756, 1030.7] nm
Example: function `append_marks<-.ppp`(), existing numeric-marks
spru = spatstat.data::sprucesset.seed(23); append_marks(spru) =rlnorm(n = spatstat.geom::npoints.ppp(spru))spru |> spatstat.geom::print.ppp()# Marked planar point pattern: 134 points# Mark variables: m1, m2 # window: rectangle = [0, 56] x [0, 38] metres
Example: function `append_marks<-.ppp`(), existing multi-type marks
ant = spatstat.data::antsset.seed(42); append_marks(ant) =rlnorm(n = spatstat.geom::npoints.ppp(ant))ant |> spatstat.geom::print.ppp()# Marked planar point pattern: 97 points# Mark variables: m1, m2 # window: polygonal boundary# enclosing rectangle: [-25, 803] x [-49, 717] units (one unit = 0.5 feet)
Listing 27.41 appends a new mark to the existing 'dataframe' marks of the point-pattern gorillas (Section 10.11). The new mark is automatically named m4 in addition to the three existing marks.
Listing 27.41: Example: function `append_marks<-.ppp`(), existing 'dataframe' marks
Listing 27.42 appends multiple new marks with user-specified mark names to the existing 'dataframe' marks of the point-pattern gorillas (Section 10.11).
Listing 27.42: Example: function `append_marks<-.ppp`(), existing 'dataframe' marks, multiple new marks
The S3 generic function .rmax() provides the default \(r_\text{max}\) used in functions from package spatstat.explore (v3.6.0.1) that return a function-value-table (fv.object, Chapter 15), i.e., the workhorse functions in Table 27.18 and Table 27.19. Package groupedHyperframe (v0.3.2) implements the following S3 methods (Table 27.9),
The S3 method .rmax.ppp() finds the default \(r_\text{max}\) used by various functions applicable to a point-pattern and returning a function-value-table. It is
Table 27.10: an off-label use of functions spatstat.explore::rmax.rule() and spatstat.geom::handle.r.b.args()
Table 27.10: Default \(r_\text{max}\) used in functions from package spatstat.explore (v3.6.0.1) that return an fv.object
Function kmeans.ppp() performs \(k\)-means clustering (Hartigan and Wong 1979) on a point-pattern. This is a “pseudo” S3 method, as the workhorse function stats::kmeans() shipped with R version 4.5.2 (2025-10-31) is not an S3 generic function. Note that to reproduce a \(k\)-means clustering using stats::kmeans(), readers must set the .Random.seed beforehand.
Function kmeans.ppp() has parameters
formula, \(x\)- and/or \(y\)- coordinate(s) and/or (one or more of the) numeric-marks
(optional) centers, number of clusters
(optional) clusterSize, “expected” number of points per cluster.
User should specify one of the two optional parameters centers and clusterSize. If both are specified, then parameter clusterSize takes priority and parameter centers is ignored.
Function kmeans.ppp() returns an object of S3 class 'pppkm', which inherits from the class 'ppp' with additional attributes,
attr(.,'f'), a factor indicating the \(k\)-means clustering indices.
Package groupedHyperframe (v0.3.2) implements the following S3 methods to the class 'pppkm' (Table 27.11),
Listing 27.43 performs 3L-means clustering on the \(x\)- and \(y\)-coordinates-only point-pattern vesicles (Section 10.19) by the \(x\)-coordinates.
Listing 27.43: Example: function kmeans.ppp(); cluster vesicles by ~ x
set.seed(12); spatstat.data::vesicles |>kmeans.ppp(formula =~ x, centers =3L)# Planar point pattern: 37 points# window: polygonal boundary# enclosing rectangle: [22.6796, 586.2292] x [11.9756, 1030.7] nm# with k-means clustering of 10, 15, 12 points
Listing 27.44 performs 3L-means clustering on vesicles (Section 10.19) by the \(x\)- and \(y\)-coordinates. Figure 27.1 visualizes the \(x\)- and \(y\)-coordinates and the 3L-means clustering indices.
Listing 27.44: Example: function kmeans.ppp(); cluster vesicles by ~ x + y
set.seed(21); vesicles_k2 = spatstat.data::vesicles |>kmeans.ppp(formula =~ x + y, centers =3L)vesicles_k2# Planar point pattern: 37 points# window: polygonal boundary# enclosing rectangle: [22.6796, 586.2292] x [11.9756, 1030.7] nm# with k-means clustering of 11, 10, 16 points
Listing 27.45: Figure: function plot.pppkm(); cluster vesicles by ~ x + y
Code
par(mar =c(0,0,1,0))vesicles_k2 |>plot.pppkm()
Figure 27.1: Cluster vesicles by ~ x + y
Listing 27.46 performs \(k\)-means clustering on vesicles (Section 10.19) by the \(x\)- and \(y\)-coordinates, with an expected cluster size of 10L.
Listing 27.46: Example: function kmeans.ppp(); cluster vesicles by ~ x + y and parameter clusterSize
set.seed(43); spatstat.data::vesicles |>kmeans.ppp(formula =~ x + y, clusterSize =10L)# Planar point pattern: 37 points# window: polygonal boundary# enclosing rectangle: [22.6796, 586.2292] x [11.9756, 1030.7] nm# with k-means clustering of 9, 10, 12, 6 points
Listing 27.47: Example: function kmeans.ppp(); cluster spruces by ~ x + marks
set.seed(30); spatstat.data::spruces |>kmeans.ppp(formula =~ x + marks, centers =3L)# Marked planar point pattern: 134 points# marks are numeric, of storage type 'double'# window: rectangle = [0, 56] x [0, 38] metres# with k-means clustering of 47, 39, 48 points
Listing 27.48: Example: function kmeans.ppp(); cluster spruces by ~ x + y + marks
set.seed(62); spatstat.data::spruces |>kmeans.ppp(formula =~ x + y + marks, centers =3L)# Marked planar point pattern: 134 points# marks are numeric, of storage type 'double'# window: rectangle = [0, 56] x [0, 38] metres# with k-means clustering of 40, 38, 56 points
The S3 method split.pppkm() (Listing 27.51) splits the \(k\)-means clustered point-pattern flu$pattern[[1L]] (Section 10.10) by its \(k\)-means clustering indices.
Listing 27.51: Example: function split.pppkm()
Code
set.seed(15); spatstat.data::flu$pattern[[1L]] |>kmeans.ppp(formula =~ x + y, centers =3L) |>split()# Point pattern split by factor # # 1:# Marked planar point pattern: 169 points# Multitype, with levels = M2, M1 # window: rectangle = [0, 3331] x [0, 3331] nm# # 2:# Marked planar point pattern: 157 points# Multitype, with levels = M2, M1 # window: rectangle = [0, 3331] x [0, 3331] nm# # 3:# Marked planar point pattern: 145 points# Multitype, with levels = M2, M1 # window: rectangle = [0, 3331] x [0, 3331] nm
All S3 methods in Table 27.14 return an object of S3 class 'pairwise_cor_spatial', which inherits from the class 'dist' defined in package stats shipped with R version 4.5.2 (2025-10-31). Such inheritance enables us to make use of existing S3 methods to class 'dist', e.g., stats:::print.dist(), stats:::as.matrix.dist(), stats:::format.dist() and stats:::labels.dist(). Table 27.15 explains the motivation of this inheritance, that the class 'pairwise_cor_spatial' shares intrinsic similarity in data structure as the class 'dist'.
Table 27.15: Similarity in Data Structure, 'pairwise_cor_spatial' & 'dist'
'pairwise_cor_spatial' object
'dist' object
Constant diagonal values
of 1; i.e., perfect correlation
of 0; i.e., zero distance
The S3 method pairwise_cor_spatial.ppp() finds the nonparametric Tjøstheim (1978)’s correlation coefficients from the pairwise-combinations of all numeric-marks in a point-pattern, e.g., finpines (Section 10.9).
The S3 method as.matrix.pairwise_cor_spatial() returns a matrix of pairwise Tjøstheim (1978)’s coefficients with diagonal values of 1. This matrix, however, is not a correlation matrix, because Tjøstheim (1978)’s correlation coefficient
is nonparametric, i.e., there is no definition of the corresponding covariance, standard deviation sd, nor the conversion cov2cor method;
does not provide a mathematical mechanism to ensure that this matrix is positive definite.
Example: function as.matrix.pairwise_cor_spatial()
Table 27.18, Table 27.19 and Table 27.20 delve into the intricate mechanics of the batch processes (Section 3.2), offering insights that will resonate with advanced R practitioners. Package groupedHyperframe (v0.3.2) implements the following S3 methods (Table 27.17),
identifies all eligible numeric-marks in the input point-pattern (ppp.object, Chapter 27);
applies the workhorse function from package spatstat.explore per numeric-mark;
returns a list of fv.objects, named in the fashion of <numeric-mark>.<suffix>, where <suffix> is determined by <fv.object> |> attr(which = 'fname'). Note that the returned object is not an fvlist (Chapter 16).
Table 27.18: Batch processes; eligible numeric-marks to fv.objects
identifies all eligible multi-type-marks in the input point-pattern (ppp.object, Chapter 27);
applies the workhorse function from package spatstat.explore per multi-type-mark;
returns a list of fv.objects, named in the fashion of <multitype-mark>.<suffix>, where <suffix> is determined by <fv.object> |> attr(which = 'fname'). Note that the returned object is not an fvlist (Chapter 16).
Table 27.19: Batch processes; eligible multi-type-marks to fvlists
identifies all eligible multi-type-marks in the input point-pattern (ppp.object, Chapter 27);
applies the workhorse function from package spatstat.explore per multi-type-mark;
returns a list of numericvectors, named in the fashion of <multitype-mark>.<suffix>, where <suffix> is the deparsed function call. Note that the returned object is not a vectorlist (Chapter 32).
Table 27.20: Batch processes; eligible multi-type-marks to numeric-vectors
The S3 methods in Table 27.18 and Table 27.19 are user-friendly wrappers of the low-level utility functions ppp_numeric2fv() and ppp_multitype2fv(), respectively.
Listing 27.52 identifies the eligible numeric-mark area in the point-pattern betacells (Section 10.4) for the workhorse function spatstat.explore::Emark(), and applies it.
Listing 27.53 identifies the eligible multi-type-mark type in the point-pattern betacells (Section 10.4), which contains (at least) the two levels of 'off' and 'on', for the workhorse function spatstat.explore::Gcross(), and applies it.
Listing 27.53: Example: function Gcross_.ppp(., i = 'off', j = 'on')
Listing 27.55 returns an invisibleNULL-value for the point-pattern ants (Section 10.2) without any numeric-mark for the workhorse function spatstat.explore::Emark().
Listing 27.55: Exception: function Emark_.ppp(), no numeric-mark
A similar batch mechanism already exists in package spatstat.explore (v3.6.0.1) for ppp.object with 'dataframe'-markformat. Table 27.21 shows the difference between the batch mechanism in Table 27.18 versus that in package spatstat.explore.
Table 27.21: Batch mechanism for ppp.object with 'dataframe'-markformat: Table 27.18 vs. package spatstat.explore
Listing 27.56 - Listing 27.58 show the differences and connections between the batch processes in Table 27.18 versus those in package spatstat.explore, using a point-pattern finpines (Section 10.9) with two numeric-marks.
Listing 27.56: Advanced: function markcorr_.ppp() vs. spatstat.explore::markcorr()
The S3 methods in Table 27.20 are user-friendly wrappers of the low-level utility function ppp2dist().
Listing 27.59 identifies the eligible multi-type-mark type in the point-pattern betacells (Section 10.4), which contains (at least) the two levels of 'off' and 'on', for the workhorse function .nncross() (Section 27.6), and applies it.
Listing 27.59: Example: function nncross_.ppp(., i = 'off', j = 'on')
Listing 27.60 identifies the eligible multi-type-mark group in the point-pattern gorillas (Section 10.11), which contains (at least) the two levels of 'major' and 'minor', for the workhorse function .nncross() (Section 27.6), and applies it;
Listing 27.60: Example: function nncross_.ppp(., i = 'major', j = 'minor')
Listing 27.61 identifies the eligible multi-type-mark season in the point-pattern gorillas (Section 10.11), which contains (at least) the two levels of 'rainy' and 'dry' for the workhorse function .nncross() (Section 27.6), and applies it.
Listing 27.61: Example: function nncross_.ppp(., i = 'rainy', j = 'dry')
Listing 27.62 determines that no eligible multi-type-mark exists in the point-pattern gorillas (Section 10.11) that contains both levels 'alpha' and 'beta', and therefore returns an invisibleNULL-value.
Listing 27.62: Exception: function nncross_.ppp(., i = 'male', j = 'female')
Listing 27.64 returns an invisibleNULL-value, since the input point-pattern spruces (Section 10.17) does not contain a multi-type-mark for the workhorse function .nncross() (Section 27.6).
Listing 27.64: Exception: function nncross_.ppp(), no multi-type-mark
Baddeley, Adrian, and Rolf Turner. 2005. “spatstat: An R Package for Analyzing Spatial Point Patterns.”Journal of Statistical Software 12 (6): 1–42. https://doi.org/10.18637/jss.v012.i06.
Becker, Richard A., John M. Chambers, and Allan R. Wilks. 1988. The New S Language. 1st ed. Boca Raton, FL: Chapman; Hall/CRC. https://doi.org/10.1201/9781351074988.
Diggle, Peter. 1985. “A Kernel Method for Smoothing Point Process Data.”Journal of the Royal Statistical Society: Series C 34 (2): 138–47. https://doi.org/10.2307/2347366.
Hartigan, John A., and M. A. Wong. 1979. “A \(K\)-Means Clustering Algorithm.”Journal of the Royal Statistical Society: Series C (Applied Statistics) 28 (1): 100–108. https://doi.org/10.2307/2346830.
Hubert, Lawrence J., and Reginald G. Golledge. 1982. “Measuring Association Between Spatially Defined Variables: Tjøstheim’s Index and Some Extensions.”Geographical Analysis 14 (3): 273–78. https://doi.org/10.1111/j.1538-4632.1982.tb00077.x.
Myllymäki, Mari, and Tomáš Mrkvička. 2024. “GET: Global Envelopes in R.”Journal of Statistical Software 111 (3): 1–40. https://doi.org/10.18637/jss.v111.i03.
Penttinen, Antti, Dietrich Stoyan, and Helena M. Henttonen. 1992. “Marked Point Processes in Forest Statistics.”Forest Science 38 (4): 806–24. https://doi.org/10.1093/forestscience/38.4.806.
Schlather, Martin, Jr Ribeiro Paulo J., and Peter J. Diggle. 2003. “Detecting Dependence Between Marks and Locations of Marked Point Processes.”Journal of the Royal Statistical Society Series B: Statistical Methodology 66 (1): 79–93. https://doi.org/10.1046/j.1369-7412.2003.05343.x.
Vallejos, R., F. Osorio, and M. Bevilacqua. 2020. Spatial Relationships Between Two Georeferenced Variables: With Applications in R. New York: Springer. http://srb2gv.mat.utfsm.cl/.
Van Lieshout, M. N. M., and A. J. Baddeley. 1999. “Indices of Dependence Between Types in Multivariate Point Patterns.”Scandinavian Journal of Statistics 26 (4): 511–32. https://doi.org/10.1111/1467-9469.00165.
Wälder, Olga, and Dietrich Stoyan. 1996. “On Variograms in Point Process Statistics.”Biometrical Journal 38 (8): 895–905. https://doi.org/10.1002/bimj.4710380802.