ecalcrsf

Function that creates the calibration plots following Boyce et al. (2002) and Johnson et al. (2006)

importFrom = ggplot2

return = Dataframe with observed and expected number of points per bin

ecalrsf <- function(preds, y_test, nbins, do_plot=FALSE){

  # Create bins of equal size
  bins <- cut_number(preds, n=nbins)

  # Determine mean(w(x_bin)) in each bin
  wbins <- tapply(preds, bins, mean)

  # Determine areas of each bin (should be ~equal sized bins, 
  #       but may differ by an observation if 
  #       n is not a multiple of the number of bins)
  abins <- tapply(preds,bins,length)

  # Determine U(x_bin) = wbins*Abins/sum(wbins*abins)
  ux <- wbins*abins/sum(wbins*abins)

  # Determine expected number of observations in each bin, N_bin = N*ux
  Nx <- sum(y_test)*ux

  # Count the number of 1's in each bin
  nx <- tapply(y_test, bins, sum)

  #plot results
  if(do_plot==TRUE){
  plot(Nx, nx, xlab="Expected Number", ylab="Observed Number")
  abline(lm(Nx~nx),lty="dashed")
  abline(0,1)
  } 
  return(data.frame(Nx=Nx, nx=nx))
}

References

Boyce, M.S., Vernier, P.R., Nielsen, S.E. & Schmiegelow, F.K. (2002). Evaluating resource selection functions. Ecological Modelling, 157, 281–300.

Johnson, C.J., Nielsen, S.E., Merrill, E.H., McDonald, T.L. & Boyce, M.S. (2006). Resource selection functions based on use-availability data: Theoretical motivation and evaluation methods. Journal of Wildlife Management, 70, 347-357.

spun with ezspin(“examples/functions_not_in_uhcplots/ecalcrsf.R”, out_dir = “examples/output”, fig_dir=“figures”, keep_md=F)