################################################################################ # # Program: Indices.txt # Author: John Fieberg # # Description: Indices for calculating overlap # # ####################################################################################### # All of these functions assume that two vectors will be passed (x and y) # => x and y represent estimates of the UD at a set of grid points (assumed to be the same # for UD1 and UD2) # => dxdy = the area of each grid cell # => tol = tolerance level (sets any values of the UD < this level to 0). This is only # needed for those indices that use areas (i.e., HR, PHR, and UDOI). vi.index<-function(x,y,dxdy){ z<-sum(pmin(x,y))*dxdy z } # Note, for HR, dxdy will cancel from numerator and denominator and therefore, we do not need to # consider it. HR<-function(x,y,dxdy, tol=1*10^(-15)){ x[x0)*(y>0)>0) # Area of overlap a1<-sum((x>0)>0) # HR area for UD1 a2<-sum((y>0)>0) # HR area for UD2 cbind(a12/a1, a12/a2) } PHR<-function(x,y,dxdy,tol=1*10^(-15)){ x[x0])*dxdy # prob. animal 2 is in animal 1's HR phr21<-sum(x[y>0])*dxdy # prob. animal 1 is in animal 2's HR cbind(phr12, phr21) } BA<-function(x,y,dxdy){ z<-sum(sqrt(x)*sqrt(y))*dxdy z } UDOI<-function(x,y,dxdy, tol=1*10^(-15)){ # sum(((x>tol)*(y>tol)>0)*dxdy) = A12 z<-sum(x*y)*sum(((x>tol)*(y>tol)>0)*dxdy)*dxdy z } # Claculate all indices allcalc<-function(x,y,dxdy){ inds<-c(vi.index(x,y,dxdy), HR(x,y,dxdy), PHR(x,y,dxdy), BA(x,y,dxdy), UDOI(x,y,dxdy)) names(inds)<-c("VI", "HR1,2", "HR2,1", "PHR1,2", "PHR2,1", "BA", "UDOI") inds }