##--------------------------------------------------------------------------------## ## ras: *RasterLayer object of binary raster with UTM projection and WGS84 datum ## opts: *SpatialPointsDataFrame object of observed locations ## radius: numeric object of length(opts) specifying location-specific ## maximum displacement buffer distance ##--------------------------------------------------------------------------------## misclass <- function(ras, opts, radius){ ## extract cell value at observed point ptval <- extract(ras, opts, method="simple") ptval[which(is.na(ptval))] <- 0 ## assign 0 to NA values ## Calculate proportion of cells of type 1 within displacement buffer x <- extract(ras, opts, buffer=radius, na.rm=TRUE, fun=mean) ## Calculate misclassification probability for each observed location mc <- numeric(length(ptval)) mc[which(ptval==1)] <- 1-x[which(ptval==1)] mc[which(ptval==0)] <- x[which(ptval==0)] list(pr.misclass=mc, misclass.rate=length(which(mc>0))/length(mc)) } ##---------------------------------------------------------------------------------## ## Function returns a list of two objects: ## pr.misclass: numeric vector of length(opts) representing misclassification ## probabilities for each observed location ## misclass.rate: numeric value indicating the proportion of locations with ## non-zero misclassification probabilities ##---------------------------------------------------------------------------------##