Skip to content

Commit 252b94a

Browse files
committed
Set get_index(..., bias_correct = TRUE) as default #456
1 parent 3810f77 commit 252b94a

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: sdmTMB
33
Title: Spatial and Spatiotemporal SPDE-Based GLMMs with 'TMB'
4-
Version: 0.7.2.9004
4+
Version: 0.7.2.9005
55
Authors@R: c(
66
person(c("Sean", "C."), "Anderson", , "sean@seananderson.ca",
77
role = c("aut", "cre"),

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Minor improvements and fixes
44

5+
* Change default in `get_index()` etc. to `bias_correct = TRUE`. This is the
6+
recommended setting for final inference and speed improvements within TMB
7+
have made it more viable to include the bias correction by default. #456
8+
59
* Only retain Newton update parameters if they improve the objective function.
610
#455
711

R/index.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#' Alternatively, if [sdmTMB()] was called with `do_index = TRUE` or if using
66
#' the helper function [get_index_split()], an object from [sdmTMB()].
77
#' @param bias_correct Should bias correction be implemented [TMB::sdreport()]?
8+
#' This is recommended to be `TRUE` for any final analyses, but one may wish
9+
#' to set this to `FALSE` for slightly faster calculations while experimenting
10+
#' with models.
811
#' @param level The confidence level.
912
#' @param area Grid cell area. A vector of length `newdata` from
1013
#' [predict.sdmTMB()] *or* a value of length 1 which will be repeated
@@ -115,7 +118,7 @@
115118
#' ylim(0, NA)
116119
#' }
117120
#' @export
118-
get_index <- function(obj, bias_correct = FALSE, level = 0.95, area = 1, silent = TRUE, ...) {
121+
get_index <- function(obj, bias_correct = TRUE, level = 0.95, area = 1, silent = TRUE, ...) {
119122
# if offset is a character vector, use the value in the dataframe
120123
if (is.character(area)) {
121124
area <- obj$data[[area]]

man/get_index.Rd

Lines changed: 5 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-index.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ test_that("get_index works", {
1111
)
1212
nd <- replicate_df(qcs_grid, "year", unique(pcod$year))
1313
predictions <- predict(m, newdata = nd, return_tmb_object = TRUE)
14-
ind <- get_index(predictions)
14+
ind <- get_index(predictions, bias_correct = FALSE)
1515
ind
1616
expect_s3_class(ind, "data.frame")
1717

18-
indsp <- get_index_split(m, nd, nsplit = 2)
18+
indsp <- get_index_split(m, nd, nsplit = 2, bias_correct = FALSE)
1919
expect_equal(ind, indsp)
2020
expect_identical(chunk_time(c(1, 2, 3), 2), list(`1` = c(1, 2), `2` = 3))
2121
expect_error(chunk_time(c(1, 2), 0))
@@ -40,8 +40,8 @@ test_that("get_index works", {
4040
# splits work with areas:
4141
set.seed(1)
4242
areas <- rlnorm(nrow(nd), meanlog = 0, sdlog = 0.1)
43-
ind <- get_index(predictions, area = areas)
44-
indsp <- get_index_split(m, nd, nsplit = 2, area = areas)
43+
ind <- get_index(predictions, area = areas, bias_correct = FALSE)
44+
indsp <- get_index_split(m, nd, nsplit = 2, area = areas, bias_correct = FALSE)
4545
expect_equal(ind, indsp)
4646

4747
# splits work with offsets:
@@ -57,8 +57,8 @@ test_that("get_index works", {
5757
set.seed(1)
5858
fake_offset <- rnorm(nrow(nd2), 0, 0.1)
5959
predictions2 <- predict(m2, newdata = nd2, return_tmb_object = TRUE, offset = fake_offset)
60-
ind <- get_index(predictions2)
61-
indsp <- get_index_split(m2, nd2, nsplit = 2, predict_args = list(offset = fake_offset))
60+
ind <- get_index(predictions2, bias_correct = FALSE)
61+
indsp <- get_index_split(m2, nd2, nsplit = 2, predict_args = list(offset = fake_offset), bias_correct = FALSE)
6262
expect_equal(ind, indsp)
6363
})
6464

@@ -130,13 +130,13 @@ test_that("Index integration with area vector works with extra time and possibly
130130
nd <- replicate_df(qcs_grid, "year", seq(2011, 2017))
131131
nd$area <- 4
132132
p <- predict(fit, newdata = nd, return_tmb_object = TRUE)
133-
ind0 <- get_index(p, area = nd$area)
133+
ind0 <- get_index(p, area = nd$area, bias_correct = FALSE)
134134

135135
# newdata doesn't have all fitted years:
136136
nd <- replicate_df(qcs_grid, "year", unique(pcod_2011$year))
137137
nd$area <- 4
138138
p <- predict(fit, newdata = nd, return_tmb_object = TRUE)
139-
ind <- get_index(p, area = nd$area)
139+
ind <- get_index(p, area = nd$area, bias_correct = FALSE)
140140
if (FALSE) {
141141
library(ggplot2)
142142
ggplot(ind, aes(year, est, ymin = lwr, ymax = upr)) + geom_pointrange() +
@@ -165,9 +165,9 @@ test_that("get_index works", {
165165
predictions <- predict(m, newdata = nd, return_tmb_object = TRUE)
166166

167167
# get predictions with area passed as vector
168-
ind <- get_index(predictions, area = nd$area)
168+
ind <- get_index(predictions, area = nd$area, bias_correct = FALSE)
169169
# get predictions with area as a named column
170-
ind2 <- get_index(predictions, area = "area")
170+
ind2 <- get_index(predictions, area = "area", bias_correct = FALSE)
171171
expect_equal(ind, ind2)
172172

173173
# get predictions with area passed as vector

0 commit comments

Comments
 (0)