R/add_threshold.R

Defines functions add_threshold

Documented in add_threshold

#' Determine the threshold cutoff to use for determining false hits.
#'
#' @param x
#'
#' @return
#' @export
#'
#' @examples
add_threshold <- function(x, offset = .5) {
  library(dplyr)
  # add spacing at target location
  params    <- searchR::create_retinal_constants()
  spacing   <- searchR::watson_spacing(
      params$ring_centers,
      0,
      binoc = 1,
      sp_scal = 0.943,
      f0 = 0
    )
  patch_rad <-
    offset + params$patch_radii # taken from the table of values computed in the notes.
  x$threshold <- NULL

  x <- x %>% mutate(spacing = purrr::pmap(., function(stimX, stimY, tPresent, ...)
    {
      spacing = ifelse(
        tPresent == "present",
        searchR::watson_spacing(
          stimX,
          stimY,
          binoc = 1,
          sp_scal = 0.943,
          f0 = 0
        ),
        -1
      )
    })) %>% tidyr::unnest(spacing)

  x$threshold <-
    Hmisc::approxExtrap(spacing, patch_rad, x$spacing)$y

  x[x$tPresent == "absent", "threshold"] <- NA

  return(x)
}
calenwalshe/humansearch documentation built on March 19, 2021, 5:23 p.m.