Learn R Programming

bossMaps (version 0.1.0)

rangeOffset: Generate a spatial map of an expert map (with decay) to be used as an offset

Description

Uses the logistic function to transform the rdist object to a normalized expert range with a desired proportion of the total probability inside the range. You can set fitdist to include a buffer around the range as 'inside' for the purposes of the prior expectation of what Typically the user supplies prob, rate, and skew as fixparms while upper and lower are estimated.

Usage

rangeOffset(rdist, parms, dists = NULL, returnRaster = TRUE, doNormalize = TRUE, verbose = TRUE, doWriteRaster = FALSE, doWriteMetadata = TRUE, ...)

Arguments

rdist
raster* object of distances to the range edge (output from rangeDist
parms
A named vector of parameter values from logistic that describe the desired curve. These include all parameters for logistic (rate,skew,shift) and two additional parameters named prob (indicating the desired probability inside the range, e.g. 0.95) and buffer (a desired buffer, in meters) outside the expert range that should be considered 'inside' the range. See description for details.
dists
frequency table of unique distance values (output from running freq on the rdist object). If NULL, it will be created within the function but can also be supplied here to speed up processing multiple logistic parameters
returnRaster
logiical indicating whether to calculate the full spatial prior and return the raster. If FALSE, the result will simply be the fitted parameters.
doNormalize
logical indicating whether to normalize the raster before returning it. If FALSE, the result will range from lower to upper.
verbose
logical indicating whether to print verbose messages
doWriteRaster
logical indicating whether to write the output to disk
doWriteMetadata
logical indicating whether to write summary metadata to disk as a .csv file
...
additional functions to be passed to writeRaster

Examples

Run this code
## Not run: 
#   library(raster)
#   library(ggplot2)
#   
#   data("Tinamus_solitarius_points")
#   data("Tinamus_solitarius_range")
#   
#   ## Define global modeling grid
#   domain = raster(
#     xmn = -180,
#     xmx = 180,
#     ymn = -90,
#     ymx = 90,
#     crs = "+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs",
#     resolution = 10 / 360,
#     vals = NULL
#   )
#   
#   ## turn on raster progress bar
#   rasterOptions(progress = "")
#   
#   ## calculate distance-to-range: this is slow but only has to
#   ## be done once per species.  Can speed it up by increasing
#   ## 'fact' (at the expense of reduced accuracy).
#   range = Tinamus_solitarius_range
#   points=Tinamus_solitarius_points
#   
#   rdist = rangeDist(range=range,
#                     domain=domain,
#                     domainkm = 100,
#                     mask = FALSE,
#                     fact = 10)
#   
#   ## Mask out undesired areas (ocean, etc.)  Typically you would
#   ## do this using your environmental data, but here we'll just
#   ## use a coastline polygon from the maps package
# #    land = map(
# #    interior = F,
# #    fill = T,
# #    xlim = bbox(rdist)[1, ],
# #    ylim = bbox(rdist)[2, ]
# #  )
# #  land = map2SpatialPolygons(land, IDs = land$names)
# #  rdist = mask(rdist, land)
#   
#   ## calculate frequency table of distances
#   dists = freq(rdist)
#   
#   ### plot to visualize potential decay parameters
#   vars = expand.grid(
#     rate = c(0, 0.03, 0.05, 0.1, 10),
#     skew = c(0.2,
#              0.4),
#     shift = 0,
#     stringsAsFactors = FALSE
#   )
#   x = seq(-150, 300, len = 1000)
#   
#   ## Calculate all the curves
#   erd = do.call(rbind, lapply(1:nrow(vars), function(i) {
#     y = logistic(x, parms = unlist(c(
#       lower = 0, upper = 1, vars[i, ]
#     )))
#     return(cbind.data.frame(
#       group = i,
#       c(vars[i, ]),
#       x = x,
#       y = y
#     ))
#   }))
#   
#   ## plot it
#   ggplot(erd,
#          aes(
#            x = x,
#            y = y,
#            linetype = as.factor(skew),
#            colour = as.factor(rate),
#            group = group
#          )) + 
#     geom_vline(aes(xintercept=0),
#                colour = "red") + geom_line() +
#     xlab("Prior value (not normalized)") +
#     xlab("Distance to range edge (km)")
#   
#   
#   ## calculate the expert range prior
#   expert = rangeOffset(
#     rdist,
#     dists = dists,
#     parms = c(
#       prob = 0.9,
#       rate = 0.05,
#       skew = 0.4,
#       shift = 0
#     ),
#     normalize = TRUE,
#     verbose = TRUE
#   )
#   
#   ## View the metadata
#   metadata(expert)$parms
#   
#   ## plot it
#   plot(expert)
# ## End(Not run)

Run the code above in your browser using DataLab