rangeOffset: Generate a spatial map of an expert map (with decay) to be...

Description Usage Arguments Examples

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

1
2
3
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

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
## 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)

bossMaps documentation built on May 2, 2019, 3:57 p.m.