Calculates composition imbalance index (also known as the m index) – a sum of cell’s values over the entire site divided by the number of cell in the site. m has a range from -1 (site completely dominated by the -1 values) to 1 (site completely dominated by the 1 values). Missing cells are ignored.

composition_index(x)

Arguments

x

SpatRaster or matrix containing two values: -1 and 1

Value

A numeric vector

See also

Examples

data(r_start, package = "spatialising")
composition_index(r_start)
#> [1] 0.9
ts1 = kinetic_ising(r_start, B = -0.3, J = 0.7)
composition_index(ts1)
#> [1] 0.896
ts2 = kinetic_ising(r_start, B = -0.3, J = 0.7, updates = 2)
composition_index(ts2)
#> [1] 0.8784 0.8744

# \donttest{
  library(terra)
#> terra 1.9.50
  r1 = rast(system.file("raster/r_start.tif", package = "spatialising"))
  composition_index(r1)
#> [1] 0.9
  r2 = kinetic_ising(r1, B = -0.3, J = 0.7)
  composition_index(r2)
#> [1] 0.8784
# }