Skip to content

Commit ddd1e23

Browse files
committed
tidy
1 parent 1fa07f2 commit ddd1e23

File tree

4 files changed

+46
-38
lines changed

4 files changed

+46
-38
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: spatialreg
22
Version: 1.3-7
3-
Date: 2025-04-25
3+
Date: 2025-07-25
44
Title: Spatial Regression Analysis
55
Encoding: UTF-8
66
Authors@R: c(person("Roger", "Bivand", role = c("cre", "aut"), email = "Roger.Bivand@nhh.no", comment=c(ORCID="0000-0003-2392-6140")),

R/SLX_WX.R

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ impacts.SlX <- function(obj, ...) {
272272
stopifnot(!is.null(attr(obj, "mixedImps")))
273273
n <- nrow(obj$model)
274274
k <- obj$qr$rank
275-
impactsWX(attr(obj, "mixedImps"), n, k, type="SlX", method="glht")
275+
impactsWX(attr(obj, "mixedImps"), n, k, type="SlX", method="glht",
276+
have_factor_preds=attr(obj, "have_factor_preds"))
276277
}
277278

278279
impactsWX <- function(obj, n, k, type="SlX", method="glht", have_factor_preds=FALSE) {
@@ -300,19 +301,26 @@ update_bnames <- function(bnames, have_factor_preds=FALSE) {
300301
if (have_factor_preds && !interactions) {
301302
factnames <- attr(have_factor_preds, "factnames")
302303
xlevels <- attr(have_factor_preds, "xlevels")
303-
contrasts <- attr(have_factor_preds, "contrasts")
304+
contrasts <- attr(have_factor_preds, "pred_contrasts")
304305
for (pred in seq(along=factnames)) {
305306
npred <- grep(factnames[pred], bnames)
306307
xlpred <- xlevels[[pred]]
307308
cpred <- contrasts[[pred]]
308-
if (length(npred) == length(xlpred)) {
309-
b_suffix[npred] <- xlpred
309+
if (length(npred) >= length(xlpred)) {
310+
b_suffix[npred] <- ""
310311
} else {
311-
switch(cpred,
312-
contr.treatment = ,
313-
code_control = ,
314-
code_diff =
315-
)
312+
if (cpred == "contr.treatment") {
313+
b_suffix[npred] <- xlpred[-1]
314+
} else if (cpred == "code_control") {
315+
b_suffix[npred] <- paste(xlpred[-1], "vs.", xlpred[1])
316+
} else if (cpred == "code_diff") {
317+
b_suffix[npred] <- paste(xlpred[-1], "vs.",
318+
xlpred[-length(xlpred)])
319+
} else if (cpred == "contr.poly") {
320+
b_suffix[npred] <- "poly"
321+
} else {
322+
b_suffix[npred] <- ""
323+
}
316324
}
317325
}
318326
}

inst/tinytest/test_Durbin_factor.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ data(oldcol, package="spdep")
33
lw <- spdep::nb2listw(COL.nb)
44
COL.OLD$fEW <- factor(COL.OLD$EW)
55
COL.OLD$fDISCBD <- ordered(cut(COL.OLD$DISCBD, c(0, 1.5, 3, 4.5, 6)))
6-
f <- formula(CRIME ~ INC + HOVAL + fDISCBD*fEW)
6+
f <- formula(CRIME ~ INC + HOVAL + fDISCBD + fEW)
77
expect_warning(COL.SLX0 <- lmSLX(f, data=COL.OLD, lw, Durbin=TRUE))
8-
expect_warning(COL.SLX1 <- lmSLX(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW))
8+
expect_warning(COL.SLX1 <- lmSLX(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD + fEW))
99
expect_warning(COL.SLX2 <- lmSLX(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fEW))
1010
expect_silent(COL.SLX3 <- lmSLX(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL))
1111
expect_warning(COL.err0 <- errorsarlm(f, data=COL.OLD, lw, Durbin=TRUE))
12-
expect_warning(COL.err1 <- errorsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW))
12+
expect_warning(COL.err1 <- errorsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD + fEW))
1313
expect_warning(COL.err2 <- errorsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD))
1414
expect_silent(COL.err3 <- errorsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL))
1515
expect_warning(COL.lag0 <- lagsarlm(f, data=COL.OLD, lw, Durbin=TRUE))
16-
expect_warning(COL.lag1 <- lagsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW))
16+
expect_warning(COL.lag1 <- lagsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD + fEW))
1717
expect_warning(COL.lag2 <- lagsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD))
1818
expect_silent(COL.lag3 <- lagsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL))
1919
expect_warning(COL.sac0 <- sacsarlm(f, data=COL.OLD, lw, Durbin=TRUE))
20-
expect_warning(COL.sac1 <- sacsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW))
20+
expect_warning(COL.sac1 <- sacsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD + fEW))
2121
expect_warning(COL.sac2 <- sacsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD))
2222
expect_silent(COL.sac3 <- sacsarlm(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL))
2323
expect_warning(COL.lag0 <- spBreg_lag(f, data=COL.OLD, lw, Durbin=TRUE))
24-
expect_warning(COL.lag1 <- spBreg_lag(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW))
24+
expect_warning(COL.lag1 <- spBreg_lag(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD + fEW))
2525
expect_warning(COL.lag2 <- spBreg_lag(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD))
2626
expect_silent(COL.lag3 <- spBreg_lag(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL))
2727
expect_warning(COL.err0 <- spBreg_err(f, data=COL.OLD, lw, Durbin=TRUE))
28-
expect_warning(COL.err1 <- spBreg_err(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW))
28+
expect_warning(COL.err1 <- spBreg_err(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD + fEW))
2929
expect_warning(COL.err2 <- spBreg_err(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD))
3030
expect_silent(COL.err3 <- spBreg_err(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL))
3131
expect_warning(COL.sac0 <- spBreg_sac(f, data=COL.OLD, lw, Durbin=TRUE))
32-
expect_warning(COL.sac1 <- spBreg_sac(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD*fEW))
32+
expect_warning(COL.sac1 <- spBreg_sac(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD + fEW))
3333
expect_warning(COL.sac2 <- spBreg_sac(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL + fDISCBD))
3434
expect_silent(COL.sac3 <- spBreg_sac(f, data=COL.OLD, lw, Durbin=~ INC + HOVAL))
3535

inst/tinytest/test_TR_20_07_20.R

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ expect_true(isTRUE(all.equal(c(m2c.imps[[1]]$indirect["ft.NWBIR74"],
4747
# Total impact is linear combination
4848
lc <- summary(multcomp::glht(m2c, linfct = c("east + lag.east = 0")))
4949
expect_true(isTRUE(all.equal(c(m2c.imps[[1]]$total["east"],
50-
summary(m2c.imps)$semat["east", "Total"]),
50+
summary(m2c.imps)$semat["east dy/dx", "Total"]),
5151
c(lc$test$coefficients,
5252
lc$test$sigma),
5353
tolerance = 1e-5, check.attributes = FALSE)))
@@ -74,9 +74,9 @@ expect_true(isTRUE(all.equal(c(m2d.imps[[1]]$indirect["ft.NWBIR74"],
7474
lc1 <- summary(multcomp::glht(m2d, linfct = c("ft.NWBIR74 + lag.ft.NWBIR74 = 0")))
7575
lc2 <- summary(multcomp::glht(m2d, linfct = c("east + lag.east = 0")))
7676
expect_true(isTRUE(all.equal(c(m2d.imps[[1]]$total["ft.NWBIR74"],
77-
summary(m2d.imps)$semat["ft.NWBIR74", "Total"],
77+
summary(m2d.imps)$semat["ft.NWBIR74 dy/dx", "Total"],
7878
m2d.imps[[1]]$total["east"],
79-
summary(m2d.imps)$semat["east", "Total"]),
79+
summary(m2d.imps)$semat["east dy/dx", "Total"]),
8080
c(lc1$test$coefficients,
8181
lc1$test$sigma,
8282
lc2$test$coefficients,
@@ -104,9 +104,9 @@ expect_true(isTRUE(all.equal(c(m2e.imps[[1]]$indirect["ft.NWBIR74"],
104104
lc1 <- summary(multcomp::glht(m2e, linfct = c("ft.NWBIR74 + lag.ft.NWBIR74 = 0")))
105105
lc2 <- summary(multcomp::glht(m2e, linfct = c("east + lag.east = 0")))
106106
expect_true(isTRUE(all.equal(c(m2e.imps[[1]]$total["ft.NWBIR74"],
107-
summary(m2e.imps)$semat["ft.NWBIR74", "Total"],
107+
summary(m2e.imps)$semat["ft.NWBIR74 dy/dx", "Total"],
108108
m2e.imps[[1]]$total["east"],
109-
summary(m2e.imps)$semat["east", "Total"]),
109+
summary(m2e.imps)$semat["east dy/dx", "Total"]),
110110
c(lc1$test$coefficients,
111111
lc1$test$sigma,
112112
lc2$test$coefficients,
@@ -135,9 +135,9 @@ lc1 <- summary(multcomp::glht(m2f,
135135
linfct = c("ft.NWBIR74 + lag.ft.NWBIR74 = 0")))
136136
lc2 <- summary(multcomp::glht(m2f, linfct = c("east + lag.east = 0")))
137137
expect_true(isTRUE(all.equal(c(m2f.imps[[1]]$total["ft.NWBIR74"],
138-
summary(m2f.imps)$semat["ft.NWBIR74", "Total"],
138+
summary(m2f.imps)$semat["ft.NWBIR74 dy/dx", "Total"],
139139
m2f.imps[[1]]$total["east"],
140-
summary(m2f.imps)$semat["east", "Total"]),
140+
summary(m2f.imps)$semat["east dy/dx", "Total"]),
141141
c(lc1$test$coefficients,
142142
lc1$test$sigma,
143143
lc2$test$coefficients,
@@ -163,7 +163,7 @@ expect_true(isTRUE(all.equal(m3b.imps[[1]]$indirect,
163163
# Total impact is linear combination
164164
lc <- summary(multcomp::glht(m3b, linfct = c("ft.NWBIR74 + lag.ft.NWBIR74 = 0")))
165165
expect_true(isTRUE(all.equal(c(m3b.imps[[1]]$total,
166-
summary(m3b.imps)$semat["ft.NWBIR74", "Total"]),
166+
summary(m3b.imps)$semat["ft.NWBIR74 dy/dx", "Total"]),
167167
c(lc$test$coefficients,
168168
lc$test$sigma),
169169
tolerance = 1e-5, check.attributes = FALSE)))
@@ -191,9 +191,9 @@ lc1 <- summary(multcomp::glht(m3c,
191191
linfct = c("ft.NWBIR74 + lag.ft.NWBIR74 = 0")))
192192
lc2 <- summary(multcomp::glht(m3c, linfct = c("east + lag.east = 0")))
193193
expect_true(isTRUE(all.equal(c(m3c.imps[[1]]$total["ft.NWBIR74"],
194-
summary(m3c.imps)$semat["ft.NWBIR74", "Total"],
194+
summary(m3c.imps)$semat["ft.NWBIR74 dy/dx", "Total"],
195195
m3c.imps[[1]]$total["east"],
196-
summary(m3c.imps)$semat["east", "Total"]),
196+
summary(m3c.imps)$semat["east dy/dx", "Total"]),
197197
c(lc1$test$coefficients,
198198
lc1$test$sigma,
199199
lc2$test$coefficients,
@@ -222,9 +222,9 @@ lc1 <- summary(multcomp::glht(m3e,
222222
linfct = c("ft.NWBIR74 + lag.ft.NWBIR74 = 0")))
223223
lc2 <- summary(multcomp::glht(m3e, linfct = c("east + lag.east = 0")))
224224
expect_true(isTRUE(all.equal(c(m3e.imps[[1]]$total["ft.NWBIR74"],
225-
summary(m3e.imps)$semat["ft.NWBIR74", "Total"],
225+
summary(m3e.imps)$semat["ft.NWBIR74 dy/dx", "Total"],
226226
m3e.imps[[1]]$total["east"],
227-
summary(m3e.imps)$semat["east", "Total"]),
227+
summary(m3e.imps)$semat["east dy/dx", "Total"]),
228228
c(lc1$test$coefficients,
229229
lc1$test$sigma,
230230
lc2$test$coefficients,
@@ -258,9 +258,9 @@ lc1 <- summary(multcomp::glht(m3f,
258258
linfct = c("ft.NWBIR74 + lag.ft.NWBIR74 = 0")))
259259
lc2 <- summary(multcomp::glht(m3f, linfct = c("east + lag.east = 0")))
260260
expect_true(isTRUE(all.equal(c(m3f.imps[[1]]$total["ft.NWBIR74"],
261-
summary(m3f.imps)$semat["ft.NWBIR74", "Total"],
261+
summary(m3f.imps)$semat["ft.NWBIR74 dy/dx", "Total"],
262262
m3f.imps[[1]]$total["east"],
263-
summary(m3f.imps)$semat["east", "Total"]),
263+
summary(m3f.imps)$semat["east dy/dx", "Total"]),
264264
c(lc1$test$coefficients,
265265
lc1$test$sigma,
266266
lc2$test$coefficients,
@@ -289,9 +289,9 @@ lc1 <- summary(multcomp::glht(m3fb,
289289
linfct = c("ft.NWBIR74 + lag.ft.NWBIR74 = 0")))
290290
lc2 <- summary(multcomp::glht(m3fb, linfct = c("east + lag.east = 0")))
291291
expect_true(isTRUE(all.equal(c(m3fb.imps[[1]]$total["ft.NWBIR74"],
292-
summary(m3fb.imps)$semat["ft.NWBIR74", "Total"],
292+
summary(m3fb.imps)$semat["ft.NWBIR74 dy/dx", "Total"],
293293
m3fb.imps[[1]]$total["east"],
294-
summary(m3fb.imps)$semat["east", "Total"]),
294+
summary(m3fb.imps)$semat["east dy/dx", "Total"]),
295295
c(lc1$test$coefficients,
296296
lc1$test$sigma,
297297
lc2$test$coefficients,
@@ -333,7 +333,7 @@ expect_true(isTRUE(all.equal(c(m1c.imps[[1]]$indirect["ft.NWBIR74"],
333333
# Total impact is linear combination
334334
lc <- summary(multcomp::glht(m1c, linfct = c("east + lag.east = 0")))
335335
expect_true(isTRUE(all.equal(c(m1c.imps[[1]]$total["east"],
336-
summary(m1c.imps)$semat["east", "Total"]),
336+
summary(m1c.imps)$semat["east dy/dx", "Total"]),
337337
c(lc$test$coefficients,
338338
lc$test$sigma),
339339
tolerance = 1e-5, check.attributes = FALSE)))
@@ -359,7 +359,7 @@ expect_true(isTRUE(all.equal(c(m1d.imps[[1]]$indirect["ft.NWBIR74"],
359359
# Total impact is linear combination
360360
lc <- summary(multcomp::glht(m1d, linfct = c("east + lag.east = 0")))
361361
expect_true(isTRUE(all.equal(c(m1d.imps[[1]]$total["east"],
362-
summary(m1d.imps)$semat["east", "Total"]),
362+
summary(m1d.imps)$semat["east dy/dx", "Total"]),
363363
c(lc$test$coefficients,
364364
lc$test$sigma),
365365
tolerance = 1e-5, check.attributes = FALSE)))
@@ -384,7 +384,7 @@ expect_true(isTRUE(all.equal(c(m1e.imps[[1]]$indirect["ft.NWBIR74"],
384384
# Total impact is linear combination
385385
lc <- summary(multcomp::glht(m1e, linfct = c("east + lag.east = 0")))
386386
expect_true(isTRUE(all.equal(c(m1e.imps[[1]]$total["east"],
387-
summary(m1e.imps)$semat["east", "Total"]),
387+
summary(m1e.imps)$semat["east dy/dx", "Total"]),
388388
c(lc$test$coefficients,
389389
lc$test$sigma),
390390
tolerance = 1e-5, check.attributes = FALSE)))
@@ -409,7 +409,7 @@ expect_true(isTRUE(all.equal(c(m1f.imps[[1]]$indirect["ft.NWBIR74"],
409409
# Total impact is linear combination
410410
lc <- summary(multcomp::glht(m1f, linfct = c("east + lag.east = 0")))
411411
expect_true(isTRUE(all.equal(c(m1f.imps[[1]]$total["east"],
412-
summary(m1f.imps)$semat["east", "Total"]),
412+
summary(m1f.imps)$semat["east dy/dx", "Total"]),
413413
c(lc$test$coefficients,
414414
lc$test$sigma),
415415
tolerance = 1e-5, check.attributes = FALSE)))

0 commit comments

Comments
 (0)