Skip to content

Commit 320969a

Browse files
committed
fitted.slrm has more features
1 parent 1ff9ce2 commit 320969a

6 files changed

Lines changed: 70 additions & 14 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: spatstat.model
2-
Version: 3.2-11.010
3-
Date: 2024-06-28
2+
Version: 3.2-11.011
3+
Date: 2024-06-29
44
Title: Parametric Statistical Modelling and Inference for the 'spatstat' Family
55
Authors@R: c(person("Adrian", "Baddeley",
66
role = c("aut", "cre", "cph"),

NEWS

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

2-
CHANGES IN spatstat.model VERSION 3.2-11.010
2+
CHANGES IN spatstat.model VERSION 3.2-11.011
33

44
OVERVIEW
55

66
o Package now depends on 'spatstat.univar'.
77

88
o Easier control over quadrature schemes.
9+
10+
o More options in fitted.slrm
911

1012
o Bug fix in predict.ppm.
1113

@@ -21,6 +23,14 @@ SIGNIFICANT USER-VISIBLE CHANGES
2123
New argument 'quad.args' is a list of arguments passed to 'quadscheme'
2224
to control the construction of the quadrature scheme.
2325

26+
o fitted.slrm
27+
New argument 'type' allows calculation of fitted probabilities, intensities
28+
or link function values.
29+
30+
o fitted.slrm
31+
New arguments 'dataonly' and 'leaveoneout' allow calculation of fitted
32+
values at the data points only, using leave-one-out calculation if desired.
33+
2434
BUG FIXES
2535

2636
o predict.ppm

R/slrm.R

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,30 @@ logLik.slrm <- function(object, ..., adjust=TRUE) {
431431
return(ll)
432432
}
433433

434-
fitted.slrm <- function(object, ...) {
435-
if(length(list(...)) > 0)
436-
warning("second argument (and any subsequent arguments) ignored")
437-
predict(object, type="probabilities")
434+
fitted.slrm <- function(object, ..., type="probabilities",
435+
dataonly=FALSE, leaveoneout=FALSE) {
436+
trap.extra.arguments(...)
437+
## predict at every pixel
438+
Z <- predict(object, type=type)
439+
if(!dataonly) {
440+
return(Z)
441+
}
442+
## require fitted values only at original point locations
443+
X <- response(object)
444+
if(!leaveoneout) {
445+
## just extract fitted values
446+
ZX <- safelookup(Z, X)
447+
return(ZX)
448+
}
449+
## leave-one-out calculation, directly
450+
nX <- npoints(X)
451+
ZX <- numeric(nX)
452+
for(i in seq_len(nX)) {
453+
model.i <- updateData(object, X[-i])
454+
Z.i <- predict(model.i)
455+
ZX[i] <- safelookup(Z.i, X[i])
456+
}
457+
return(ZX)
438458
}
439459

440460
intensity.slrm <- function(X, ...) {

inst/doc/packagesizes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines
1414
"2024-02-01" "3.2-9" 269 724 0 39028 1155
1515
"2024-02-02" "3.2-10" 269 724 0 39028 1155
1616
"2024-03-22" "3.2-11" 269 724 0 39028 1155
17-
"2024-06-28" "3.2-11.010" 269 726 0 39031 1155
17+
"2024-06-29" "3.2-11.011" 269 726 0 39051 1155

inst/info/packagesizes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines
1414
"2024-02-01" "3.2-9" 269 724 0 39028 1155
1515
"2024-02-02" "3.2-10" 269 724 0 39028 1155
1616
"2024-03-22" "3.2-11" 269 724 0 39028 1155
17-
"2024-06-28" "3.2-11.010" 269 726 0 39031 1155
17+
"2024-06-29" "3.2-11.011" 269 726 0 39051 1155

man/fitted.slrm.Rd

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
}
77
\description{
88
Given a fitted Spatial Logistic Regression model,
9-
this function computes the fitted probabilities for each pixel.
9+
this function computes the fitted probabilities for each pixel,
10+
or the fitted probabilities at each original data point.
1011
}
1112
\usage{
12-
\method{fitted}{slrm}(object, ...)
13+
\method{fitted}{slrm}(object, \dots, type="probabilities",
14+
dataonly=FALSE, leaveoneout=FALSE)
1315
}
1416
\arguments{
1517
\item{object}{
@@ -19,6 +21,23 @@
1921
\item{\dots}{
2022
Ignored.
2123
}
24+
\item{type}{
25+
Character string (partially) matching one of
26+
\code{"probabilities"}, \code{"intensity"} or \code{"link"}
27+
determining the quantity that should be predicted.
28+
}
29+
\item{dataonly}{
30+
Logical. If \code{TRUE}, then values will only be computed
31+
at the points of the data point pattern. If \code{FALSE}, then
32+
values will be computed at the pixels used to fit the model.
33+
}
34+
\item{leaveoneout}{
35+
Logical value
36+
specifying whether to perform a leave-one-out calculation
37+
when \code{dataonly=TRUE}. If \code{leaveoneout=TRUE},
38+
the fitted value at each data point \code{X[i]} is calculated
39+
by re-fitting the model to the data with \code{X[i]} removed.
40+
}
2241
}
2342
\details{
2443
This is a method for the generic function
@@ -27,12 +46,18 @@
2746
(objects of class \code{"slrm"}, usually obtained
2847
from the function \code{\link{slrm}}).
2948

30-
The algorithm computes
31-
the fitted probabilities of the presence of a random point in each pixel.
49+
By default, the algorithm computes
50+
the fitted probabilities of the presence of a random point in each
51+
pixel,
52+
and returns them as an image.
53+
54+
If \code{dataonly=TRUE}, the algorithm computes the fitted
55+
presence probabilities only at the locations of the original data points.
3256
}
3357
\value{
3458
A pixel image (object of class \code{"im"}) containing the
35-
fitted probability for each pixel.
59+
fitted probability for each pixel,
60+
or a numeric vector containing the fitted probability at each data point.
3661
}
3762
\seealso{
3863
\code{\link{slrm}},
@@ -42,6 +67,7 @@
4267
X <- rpoispp(42)
4368
fit <- slrm(X ~ x+y)
4469
plot(fitted(fit))
70+
fitted(fit, dataonly=TRUE)
4571
}
4672
\author{\adrian
4773
and \rolf.

0 commit comments

Comments
 (0)