Skip to content

Commit 5c058fc

Browse files
committed
lppm recognises seg and tp
1 parent 4392dff commit 5c058fc

10 files changed

Lines changed: 75 additions & 46 deletions

File tree

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: spatstat.linnet
2-
Version: 3.4-0.019
3-
Date: 2026-01-17
2+
Version: 3.4-0.020
3+
Date: 2026-01-19
44
Title: Linear Networks Functionality of the 'spatstat' Family
55
Authors@R: c(person("Adrian", "Baddeley",
66
role = c("aut", "cre", "cph"),
@@ -25,7 +25,7 @@ Authors@R: c(person("Adrian", "Baddeley",
2525
person("Ottmar", "Cronie",
2626
role = "ctb"))
2727
Maintainer: Adrian Baddeley <Adrian.Baddeley@curtin.edu.au>
28-
Depends: R (>= 3.5.0), stats, graphics, grDevices, methods, utils, spatstat.data (>= 3.1-9), spatstat.univar (>= 3.1-6), spatstat.geom (>= 3.6-1.022), spatstat.random (>= 3.4-3), spatstat.explore (>= 3.6-0), spatstat.model (>= 3.5-0.012)
28+
Depends: R (>= 3.5.0), stats, graphics, grDevices, methods, utils, spatstat.data (>= 3.1-9), spatstat.univar (>= 3.1-6), spatstat.geom (>= 3.6-1.026), spatstat.random (>= 3.4-3), spatstat.explore (>= 3.6-0), spatstat.model (>= 3.5-0.023)
2929
Imports: Matrix, spatstat.utils (>= 3.2-1), spatstat.sparse (>= 3.1)
3030
Suggests: goftest, locfit, spatstat (>= 3.4)
3131
Description: Defines types of spatial data on a linear network

NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
CHANGES IN spatstat.linnet VERSION 3.4-0.019
2+
CHANGES IN spatstat.linnet VERSION 3.4-0.020
33

44
OVERVIEW
55

R/diaglppm.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Makes diagnostic plots based on residuals or energy weights
55
## for a point process model on a network
66
##
7-
## $Revision: 1.4 $ $Date: 2025/11/24 04:29:25 $
7+
## $Revision: 1.5 $ $Date: 2026/01/19 05:49:54 $
88
##
99

1010
diagnose.lppm <- function(object, ..., type="raw", which="all",
@@ -139,7 +139,7 @@ diagLppmEngine <- function(object, ..., type="eem", typename, opt,
139139
W <- Window(Q)
140140

141141
## quadrature points on the network
142-
U <- attr(Q, "plekken") %orifnull% lpp(U2D, L)
142+
U <- attr(Q, "situ") %orifnull% lpp(U2D, L)
143143

144144
##
145145
ppmfit <- as.ppm(object)

R/linequad.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# linequad.R
33
#
4-
# $Revision: 1.32 $ $Date: 2026/01/09 01:35:25 $
4+
# $Revision: 1.33 $ $Date: 2026/01/19 05:50:01 $
55
#
66
# create quadscheme for a pattern of points lying *on* line segments
77

@@ -350,8 +350,8 @@ linequad <- function(X, Y, ..., eps=NULL, nd=1000, random=FALSE) {
350350
weight = list(method=wmethod))
351351
## make quad scheme
352352
Qout <- quad(as.ppp(DAT), as.ppp(DUM), c(wdat, wdum), param=param)
353-
## add information
354-
attr(Qout, "plekken") <- superimpose(DAT, DUM, L=L)
353+
## add information: point locations 'in situ'
354+
attr(Qout, "situ") <- superimpose(DAT, DUM, L=L)
355355
##
356356
return(Qout)
357357
}

R/lppm.R

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Point process models on a linear network
55
#
6-
# $Revision: 1.68 $ $Date: 2025/12/19 07:50:29 $
6+
# $Revision: 1.69 $ $Date: 2026/01/19 05:49:47 $
77
#
88

99
lppm <- function(X, ...) {
@@ -126,12 +126,29 @@ predict.lppm <- local({
126126
X <- object$X
127127
fit <- object$fit
128128
L <- as.linnet(X)
129-
129+
130+
## functions to evaluate the local covariates
131+
LocalCoords <- list(seg = linfun(function(x,y,seg,tp) { seg }, L),
132+
tp = linfun(function(x,y,seg,tp) { seg }, L))
133+
130134
if(!is.null(locations)) {
131-
#' locations given; return a vector/matrix of predicted values
132-
if(is.lpp(locations)) locations <- as.ppp(locations)
135+
## determine whether 'locations' includes local coordinates
136+
if(is.data.frame(locations)) {
137+
## data frame of spatial locations
138+
gotlocal <- all(c("seg", "tp") %in% names(locations))
139+
} else if(is.lpp(locations)) {
140+
## point pattern on network
141+
gotlocal <- TRUE
142+
loci <- locations
143+
locations <- as.ppp(locations)
144+
attr(locations, "situ") <- loci
145+
} else {
146+
## other spatial data
147+
gotlocal <- FALSE
148+
}
133149
values <- predict(fit, locations=locations, covariates=covariates,
134-
type=type, se=se, new.coef=new.coef)
150+
type=type, se=se, new.coef=new.coef,
151+
extracovariates=if(!gotlocal) LocalCoords else NULL)
135152
return(values)
136153
}
137154

@@ -157,7 +174,8 @@ predict.lppm <- local({
157174
if(!is.multitype(fit)) {
158175
#' unmarked
159176
values <- predict(fit, locations=projloc, covariates=covariates,
160-
type=type, se=se, new.coef=new.coef)
177+
type=type, se=se, new.coef=new.coef,
178+
extracovariates=LocalCoords)
161179
if(!se) {
162180
out <- putvalues(values, lineimage, pixelcentres, projdata, L)
163181
} else {
@@ -175,7 +193,8 @@ predict.lppm <- local({
175193
markk <- factor(lev[k], levels=lev)
176194
locnk <- cbind(projloc, data.frame(marks=markk))
177195
values <- predict(fit, locations=locnk, covariates=covariates,
178-
type=type, se=se, new.coef=new.coef)
196+
type=type, se=se, new.coef=new.coef,
197+
extracovariates=LocalCoords)
179198
if(!se) {
180199
out[[k]] <- putvalues(values, lineimage, pixelcentres, projdata, L)
181200
} else {
@@ -512,6 +531,6 @@ eem.lppm <- function(fit, ...) {
512531

513532
residuals.lppm <- function(object, type="raw", ...) {
514533
res <- residuals(as.ppm(object), type=type, ...)
515-
attr(res, "plekken") <- attr(quad.ppm(object), "plekken")
534+
attr(res, "situ") <- attr(quad.ppm(object), "situ")
516535
return(res)
517536
}

R/lurklppm.R

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ lurking.lpp <- lurking.lppm <- function(object, covariate,
5151
co <- cl$covariate
5252
covname <- if(is.name(co)) as.character(co) else
5353
if(is.expression(co)) format(co[[1]]) else
54-
if(is.character(co) &&
55-
length(co) == 1 &&
56-
co %in% c("x", "y")) paste(co, "coordinate") else NULL
54+
if(is.character(co) && length(co) == 1) {
55+
switch(co,
56+
x = "x coordinate",
57+
y = "y coordinate",
58+
seg = "segment number",
59+
tp = "tp coordinate",
60+
NULL)
61+
} else NULL
5762
}
5863

5964
#' spatial covariates
@@ -107,6 +112,8 @@ lurking.lpp <- lurking.lppm <- function(object, covariate,
107112
quadpoints <- union.quad(Q)
108113
Z <- is.data(Q)
109114
wts <- w.quad(Q)
115+
## positions on the network
116+
situ <- attr(Q, "situ")
110117
## subset of quadrature points used to fit model
111118
subQset <- getglmsubset(object2D)
112119
if(is.null(subQset)) subQset <- rep.int(TRUE, n.quad(Q))
@@ -115,30 +122,39 @@ lurking.lpp <- lurking.lppm <- function(object, covariate,
115122
#' trap case where covariate = "<name>"
116123
if(is.character(covariate) && (length(covariate) == 1)) {
117124
#' covariate is a single string
118-
is.cartesian <- covariate %in% c("x", "y")
119-
if(!is.cartesian) {
125+
is.coordinate <- covariate %in% c("x", "y", "seg", "tp")
126+
if(!is.coordinate) {
120127
#' not a reserved name; convert to an expression and evaluate later
121128
covariate <- str2expression(covariate)
122129
}
123130
} else {
124-
is.cartesian <- FALSE
131+
is.coordinate <- FALSE
125132
}
126133

127134
#################################################################
128135
## compute the covariate
129136
covunits <- NULL
130-
if(is.cartesian) {
131-
#' covariate is name of cartesian coordinate
137+
if(is.coordinate) {
138+
#' covariate is name of a spatial or local coordinate
132139
switch(covariate,
133140
x = {
134141
covvalues <- quadpoints$x
135142
covrange <- Frame(quadpoints)$xrange
143+
covunits <- unitname(quadpoints)
136144
},
137145
y = {
138146
covvalues <- quadpoints$y
139147
covrange <- Frame(quadpoints)$yrange
148+
covunits <- unitname(quadpoints)
149+
},
150+
seg = {
151+
covvalues <- coords(situ)$seg
152+
covrange <- range(covvalues)
153+
},
154+
tp = {
155+
covvalues <- coords(situ)$tp
156+
covrange <- c(0,1)
140157
})
141-
covunits <- unitname(quadpoints)
142158
} else if(is.im(covariate)) {
143159
covvalues <- covariate[quadpoints, drop=FALSE]
144160
covrange <- internal$covrange %orifnull% range(covariate, finite=TRUE)

inst/doc/packagesizes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines
4242
"2025-07-24" "3.3-1" 150 328 0 13326 3270
4343
"2025-09-24" "3.3-2" 150 328 0 13356 3270
4444
"2025-11-29" "3.4-0" 160 370 0 14990 3270
45-
"2026-01-17" "3.4-0.019" 162 374 0 15471 3270
45+
"2026-01-19" "3.4-0.020" 162 374 0 15506 3270

inst/info/packagesizes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines
4242
"2025-07-24" "3.3-1" 150 328 0 13326 3270
4343
"2025-09-24" "3.3-2" 150 328 0 13356 3270
4444
"2025-11-29" "3.4-0" 160 370 0 14990 3270
45-
"2026-01-17" "3.4-0.019" 162 374 0 15471 3270
45+
"2026-01-19" "3.4-0.020" 162 374 0 15506 3270

man/lppm.Rd

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,10 @@ lppm(X, ...)
101101
lppm(X ~ marks * x)
102102
}
103103
\references{
104-
Ang, Q.W. (2010)
105-
\emph{Statistical methodology for events on a network}.
106-
Master's thesis, School of Mathematics and Statistics, University of
107-
Western Australia.
108-
109-
Ang, Q.W., Baddeley, A. and Nair, G. (2012)
110-
Geometrically corrected second-order analysis of
111-
events on a linear network, with applications to
112-
ecology and criminology.
113-
\emph{Scandinavian Journal of Statistics} \bold{39}, 591--617.
114-
115-
McSwiggan, G., Nair, M.G. and Baddeley, A. (2012)
116-
Fitting Poisson point process models to events
117-
on a linear network. Manuscript in preparation.
104+
McSwiggan, G. (2019)
105+
Spatial point process methods for linear networks
106+
with applications to road accident analysis.
107+
PhD thesis, University of Western Australia.
118108
}
119109
\keyword{spatial}
120110
\keyword{models}

man/predict.lppm.Rd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
}
2525
\item{locations}{
2626
Optional. Locations at which predictions should be computed.
27-
Either a data frame with two columns of coordinates,
28-
or a binary image mask.
27+
Either a point pattern (class \code{"lpp"} or \code{"ppp"}),
28+
a data frame containing spatial coordinates,
29+
or a binary image mask, or a pixel image.
2930
}
3031
\item{covariates}{
3132
Values of external covariates required by the model.
@@ -78,11 +79,14 @@
7879
(If the model is multitype, the result is a list of such pixel
7980
images, one for each possible type of point.)
8081
\item
81-
If \code{locations} is a data frame, the result is a
82+
If \code{locations} is a data frame containing
83+
spatial coordinates \code{x} and \code{y}, and/or
84+
local coordinates \code{seg} and \code{tp}, the result is a
8285
numeric vector of predicted values at the locations specified by
8386
the data frame.
8487
\item
85-
If \code{locations} is a binary mask, the result is a pixel image
88+
If \code{locations} is a binary mask or pixel image,
89+
the result is a pixel image
8690
with predicted values computed at the pixels of the mask.
8791
(If the model is multitype, the result is a list of such pixel
8892
images, one for each possible type of point.)

0 commit comments

Comments
 (0)