setClasses: Set classes or intervals

Description Usage Arguments Details Value See Also Examples

View source: R/setClasses.R

Description

Functions setClasses and importClasses return a formatted list from given arguments, to be used for the integration and error checking of Bayesian network and input spatial variables. For setClasses a vector with node names and a list of vectors for both states of nodes and (optional) their boundaries in the spatial data must be provided, in the right order. For importClasses a formatted text file must be provided (see Details).

Usage

1
2
3
setClasses(nodes, states, classBoundaries, wr = NULL, layer = NULL)

importClasses(classFile)

Arguments

nodes

character. The nodes known and available as spatial data.

states

A list of characters. The states associated to each of the nodes (order must match nodes names).

classBoundaries

A list of the boundary values splitting the nodes into their corresponding states. They must be sorted in ascending order. For nominal categorical variables of raster data, classBoundaries must be the unique raster values associated to node states.

wr

character. Optional, the full path to the file to be written. Default is set to NULL, otherwise it writes the formatted list returned by setClasses to the specified path. Suggested file format is .txt, albeit not mandatory.

layer

character. Optional argument to indicate the path to files with input spatial data. If not NULL, then all nodes must have a corresponding file path, stored in the 'layer' element of output list.

classFile

character. A text file where for each input variable associated to a node (see Details) three lines are specified as follows: the first one indicates the node name, as in the Bayesian network; the second indicates the states associated with such node, as they are in the Bayesian network (note that underscores are not allowed); the third one contains the values associated to each state in the spatial data (for discrete variables) or the class boundaries dividing the states (for continuous variables), including minimum and maximum.

Details

As a reference for the text file format required by importClasses, for each node of the network:
First line: the node name.
Second line: the node states, comma separated (spaces allowed). NOTE: commas are NOT allowed inside the state names.
Third line: interval values from the spatial data associated to the states (integer values for discrete data; interval boundaries, including endpoints, for continuous data). The same exact order as node states is required.

For example:

CurrentLULC
forest,other,arable
2, 1, 3
Slope
flat, moderate, steep
-Inf, 1, 7, Inf
LegalStatus
public, private, protected
4, 3, 1

It is possible to write the formatted file automatically using setClasses, by setting argument wr as path to the text file to be created.

Value

A formatted list, specifying states break values for continuous nodes and integer values for categorical nodes.

See Also

dataDiscretize

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Load classes from external formatted text file
# Not run: importClasses('LUclasses.txt')
raw = system.file("extdata/LUclasses.txt", package = "bnspatial")
importClasses(raw)

## Same as:

setClasses(c('Slope', 'CurrentLULC', 'LegalStatus'), list(c('flat', 'moderate', 'steep'),
c('forest', 'arable', 'other'), c('public', 'private', 'protected')),
list(c(-Inf, 0, 5, Inf), c(2, 3, 1), (c(4, 3, 1))))

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