R/bw_hpi.R

Defines functions bw_hpi

Documented in bw_hpi

#' Default Plug-in bandwidth selector using ks::Hpi function.
#'
#' A simple wrapper for the ks::Hpi function.
#'
#' @param x 2d matrix of data values.
#' @return A numeric vector of estimated x and y bandwidths. Must subset your data if you wish to obtain group specific bandwidths.
#' @author Shannon E. Albeke, Wyoming Geographic Information Science Center, University of Wyoming
#' @export
#' @examples
#' data("rodents")
#' # Subset the data for a single species
#' spec1<- rodents[rodents$Species == "Species1", ]
#' # Calculate the bandwidth
#' bw_hpi(as.matrix(spec1[, c("Ave_C", "Ave_N")]))


bw_hpi<- function(x){
  if(!inherits(x, "matrix"))
    stop("x must be a 2-d numeric matrix")
  if(!is.numeric(x))
    stop("x must be a 2-d numeric matrix")
  if(dim(x)[2] != 2)
    stop("x must be a 2-d numeric matrix")
  return(ks::Hpi(x)[c(1, 4)])
}

Try the rKIN package in your browser

Any scripts or data that you put into this service are public.

rKIN documentation built on Oct. 3, 2023, 1:06 a.m.