Skip to content

Commit

Permalink
Add time lookup that may be used in future
Browse files Browse the repository at this point in the history
  • Loading branch information
seananderson committed Mar 26, 2024
1 parent bbadbb7 commit 954a19c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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__']] <-
Expand All @@ -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],
Expand Down
7 changes: 7 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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), "\\+")))))
Expand Down

0 comments on commit 954a19c

Please sign in to comment.