Skip to content

Commit 08fea35

Browse files
committed
Handle SE calculation for GAM fits
1 parent 6582ee3 commit 08fea35

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed

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-1.006
3-
Date: 2023-03-15
2+
Version: 3.2-1.007
3+
Date: 2023-03-16
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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
CHANGES IN spatstat.model VERSION 3.2-1.006
2+
CHANGES IN spatstat.model VERSION 3.2-1.007
33

44
OVERVIEW
55

@@ -9,6 +9,20 @@ OVERVIEW
99

1010
o Minor changes to documentation.
1111

12+
o Bug fixes.
13+
14+
BUG FIXES
15+
16+
o predict.ppm
17+
Standard error calculation ('se=TRUE') crashed if the fitted model
18+
was a generalised additive model (fitted with 'use.gam=TRUE').
19+
Fixed.
20+
21+
o effectfun
22+
Standard error calculation ('se.fit=TRUE') crashed if the fitted model
23+
was a generalised additive model (fitted with 'use.gam=TRUE').
24+
Fixed.
25+
1226
CHANGES IN spatstat.model VERSION 3.2-1
1327

1428
OVERVIEW

R/predict.ppm.R

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -490,30 +490,43 @@ predict.ppm <- local({
490490
if(type == "intensity")
491491
z <- PoisSaddle(z, fitin(model))
492492

493-
##
494493
if(needSE) {
495-
## extract variance-covariance matrix of parameters
496-
vc <- vcov(model, new.coef=new.coef)
497-
## compute model matrix
498-
fmla <- rhs.of.formula(formula(glmfit))
494+
## compute standard error, needed for some purpose
495+
if(inherits(glmfit, "gam")) {
496+
## compute SE using predict.gam
497+
if(!is.null(new.coef))
498+
warning("new.coef ignored in standard error calculation")
499+
SE <- predict(glmfit, newdata=newdata, type="response",
500+
se.fit=TRUE)[[2]]
501+
} else {
502+
## Use vcov.ppm
503+
## extract variance-covariance matrix of parameters
504+
vc <- vcov(model, new.coef=new.coef)
505+
## compute model matrix
506+
fmla <- rhs.of.formula(formula(glmfit))
499507
# mf <- model.frame(fmla, newdata, ..., na.action=na.pass)
500508
# mm <- model.matrix(fmla, mf, ..., na.action=na.pass)
501-
mf <- model.frame(fmla, newdata, na.action=na.pass)
502-
mm <- model.matrix(fmla, mf, na.action=na.pass)
503-
if(nrow(mm) != nrow(newdata))
504-
stop("Internal error: row mismatch in SE calculation")
505-
## compute relative variance = diagonal of quadratic form
506-
if(ncol(mm) != ncol(vc))
507-
stop("Internal error: column mismatch in SE calculation")
508-
vv <- quadform(mm, vc)
509-
## standard error
510-
SE <- lambda * sqrt(vv)
509+
mf <- model.frame(fmla, newdata, na.action=na.pass)
510+
mm <- model.matrix(fmla, mf, na.action=na.pass)
511+
if(nrow(mm) != nrow(newdata))
512+
stop("Internal error: row mismatch in SE calculation")
513+
## compute relative variance = diagonal of quadratic form
514+
if(ncol(mm) != ncol(vc))
515+
stop("Internal error: column mismatch in SE calculation")
516+
vv <- quadform(mm, vc)
517+
## standard error
518+
SE <- lambda * sqrt(vv)
519+
}
520+
521+
## Save desired quantities depending on SE
511522
if(se)
512523
zse <- SE
524+
513525
if(interval == "confidence") {
514526
z <- lambda + outer(SE, ci.q, "*")
515527
colnames(z) <- ci.names
516-
}
528+
}
529+
517530
}
518531

519532
## ############################################################

inst/doc/packagesizes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ date version nhelpfiles nobjects ndatasets Rlines srclines
44
"2023-01-26" "3.1-2" 267 706 0 38848 1155
55
"2023-02-14" "3.2-0" 269 709 0 38930 1155
66
"2023-02-15" "3.2-1" 269 709 0 38930 1155
7-
"2023-03-15" "3.2-1.006" 269 709 0 38931 1155
7+
"2023-03-16" "3.2-1.007" 269 709 0 38944 1155

0 commit comments

Comments
 (0)