This function creates the required spatial outputs for the target node.
mapTarget(
target,
statesProb,
what = c("class", "entropy"),
msk,
midvals = NULL,
targetState = NULL,
spatial = TRUE,
export = FALSE,
path = getwd(),
exportRaster = export
)
character. The node of interest to be modelled and mapped.
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.
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.
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.
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
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.
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.
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.
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.
deprecated, use export
instead.
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
.
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:
"class"
<target node name>_Class.<file format -default .tif>
"entropy"
<target node name>_ShanEntropy.<file format -default .tif>
"probability"
<target node name>_Probability_.<targetState>.<file format -default .tif>
"expected"
<target node name>_ExpectedValue.<file format -default .tif>
"variation"
<target node name>_CoefVariation.<file format -default .tif>
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.
# NOT RUN {
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)
# }
Run the code above in your browser using DataLab