From 954a19c736150a15ce99df3390e46f3d2684ad85 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 26 Mar 2024 12:51:09 -0700 Subject: [PATCH] Add time lookup that may be used in future --- R/fit.R | 2 ++ R/utils.R | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/R/fit.R b/R/fit.R index fb5f9b1a5..a900d2469 100644 --- a/R/fit.R +++ b/R/fit.R @@ -1375,6 +1375,7 @@ sdmTMB <- function( prof <- c("b_j") if (delta) prof <- c(prof, "b_j2") + lu <- make_year_lu(data[[time]]) fd <- data[['__fake_data__']] tmp <- data[!fd,,drop=FALSE] tmp[['__fake_data__']] <- tmp[['__weight_sdmTMB__']] <- @@ -1390,6 +1391,7 @@ sdmTMB <- function( threshold_function = thresh[[1]]$threshold_func, epsilon_predictor = epsilon_predictor, time = time, + time_lu = lu, family = family, smoothers = sm, response = y_i[!fd,,drop=FALSE], diff --git a/R/utils.R b/R/utils.R index 92721311c..8776321ca 100644 --- a/R/utils.R +++ b/R/utils.R @@ -166,6 +166,13 @@ make_year_i <- function(x) { x - min(x) } +make_year_lu <- function(x) { + ret <- unique(data.frame(year_i = make_year_i(x), time_from_data = x, stringsAsFactors = FALSE)) + ret <- ret[order(ret$year_i),,drop=FALSE] + row.names(ret) <- NULL + ret +} + check_offset <- function(formula) { .check <- any(grepl("^offset$", gsub(" ", "", unlist(strsplit(as.character(formula), "\\+")))))