Skip to content

Instantly share code, notes, and snippets.

View dsjohnson's full-sized avatar

Devin Johnson dsjohnson

  • NOAA Pacific Islands Fisheries Science Center
  • Loveland, CO
  • 07:30 (UTC -06:00)
View GitHub Profile
#' @title Find the sections of a path that pass thorugh a restricted area
#' @description This function is used to identify sections of a path that pass through
#' restricted areas. the CTCRW model in crawl cannot actively steer paths away
#' from restricted areas as it knows nothing of spatial information. So, this function
#' will identify areas that for which the unrestrained path passes through these areas.
#' If the path/points end within the restricted area, those records will be removed.
#' The user can then use this information to adjust the path as desired.
#' @param xy A \code{SpatialPoints} object from the \code{sp} package or a
#' 2-column matrix of x and y locations
#' @param res_raster A \code{raster} object from the raster package that indicates
library(glmmTMB)
library(mgcv)
#########################################################################
## Function to create prediction matrices from mgcv for glmmTMB
## from ?mgcv::smooth2random
########################################################################
s2rPred <- function(sm,re,data) {
## Function to aid prediction from smooths represented as type==2
## random effects. re must be the result of smooth2random(sm,...,type=2).