mapTarget: Make maps for target node

Description Usage Arguments Details Value See Also Examples

View source: R/mapTarget.R

Description

This function creates the required spatial outputs for the target node.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
mapTarget(
  target,
  statesProb,
  what = c("class", "entropy"),
  msk,
  midvals = NULL,
  targetState = NULL,
  spatial = TRUE,
  export = FALSE,
  path = getwd(),
  exportRaster = export
)

Arguments

target

character. The node of interest to be modelled and mapped.

statesProb

matrix. The probability matrix as returned by queryNet and queryNetParallel. Columns must be named accordingly to states of the target node. Columns are the target node states and rows each location considered from the area of interest.

what

character. The required output, one or more of these are valid:

  • "class" returns the relatively most likely state.

  • "entropy" calculates the Shannon index and returns the entropy, given the node probabilities.

  • "probability" returns an object for each state of the target node, with its probability.

  • "expected" gives the expected value for the target node (see Details). Only valid for target nodes of continuous values. midValues argument must be provided.

  • "variation" returns the coefficient of variation, as a measure of uncertainty. Only valid for target nodes of continuous values.

msk

an object of class "RasterLayer" (raster) or a spatial vector of class "sf" (vector spatial polygons). The reference spatial boundaries to be used as mask. All model outputs will have the same extent/outline as this object. All locations with no data (i.e. NA) will be ignored.

midvals

vector of length equal to the number of states of the target node. Applies only if the target node is a continuous variable, in which case midvals must contain the mid values for each of the intervals

targetState

character. One or more states of interest from the target node. Applies only when argument what includes 'probability'. Default is set to all states of the node.

spatial

logical. Should the output be spatially explicit -i.e. a georeferenced raster or spatial vector? Default is TRUE, returning an object of class "RasterLayer" or "sf" for polygons. If FALSE, returns a data frame with one row for each valid cell/feature from msk and in columns the output required by what argument.

export

Logical or character. Should the spatial output be exported to file? Applies only if argument spatial=TRUE. When export=TRUE, output will be exported in .tif (raster) or .shp (vector) format. For rasters, a character specifying another extension can be provided, in which case the raster will be exported in that format. Only formats listed by writeFormats are valid. Argument exportRaster is deprecated.

path

The directory to store the output files, when export is not FALSE. Default is the working directory as from getwd(). File names are set by a default naming convention, see Details.

exportRaster

deprecated, use export instead.

Details

mapTarget

The expected value is calculated by summing the mid values of target node states weighted by their probability: p1 * midVal_1 + p2 * midval_2 + ... + pn * midval_n
When exporting to a file, the file name is set by default, according to the following naming convention:

An additional comma separated file (.csv) is written to the same directory when "class", providing a key to interpret the values and the state they refer to.

Value

A list of objects, one for each item required in what argument. If spatial = TRUE a list of rasters of class "RasterLayer" are returned, or a single spatial vector of class "sf" with one column for each output requested. If FALSE, for raster data it returns a list of vectors with the values associated to each non NA cell in msk raster (i.e. the vectorised raster). For vector data it returns a data frame. If argument export is specified, outputs are exported to files to the directory specified in path.

See Also

bnspatial, aoi, queryNet

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
list2env(ConwyData, environment())

network <- LandUseChange
target <- 'FinalLULC'
statesProb <- queryNet(network, target, evidence)

maps <- mapTarget(target, statesProb, msk=ConwyLU)

library(raster)
plot(maps$Class)
plot(maps$Entropy)

## Returns required outputs by coordinates for each 'msk' cell in a data frame:
noMap <- mapTarget(target, statesProb, msk=ConwyLU, spatial=FALSE)
head(noMap)

## Create a probability surface for the "forest" state of target node "FinalLULC"
mp <- mapTarget('FinalLULC', statesProb, what='probability', targetState='forest', msk=ConwyLU)
plot(mp$Probability$forest)

## With spatial vector (totally made up data here, just for demo):
library(sf)
spVector <- st_read(system.file("extdata", "Conwy.shp", package = "bnspatial"))
ev <- evidence[1:nrow(spVector), ]

probs <- queryNet(network, 'FinalLULC', ev)
mp <- mapTarget('FinalLULC', statesProb=probs,
                what=c('entropy', 'probability'), targetState='forest', msk=spVector)

bnspatial documentation built on Jan. 17, 2020, 9:06 a.m.