raster.change: Raster change between two nominal rasters

View source: R/raster.change.R

raster.changeR Documentation

Raster change between two nominal rasters

Description

Compares two categorical rasters with a variety of statistical options

Usage

raster.change(
  x,
  y,
  s = 3,
  stat = c("kappa", "t.test", "cor", "entropy", "cross-entropy", "divergence"),
  ...
)

Arguments

x

A terra SpatRaster

y

A terra SpatRaster for comparison to x

s

Integer or matrix for defining Kernel, must be odd but not necessarily square

stat

Statistic to use in comparison, please see details for options.

...

Additional arguments passed to terra::focalPairs

Details

This function provides a various statistics for comparing two classified maps. Valid options are:

  • kappa - Cohen's Kappa

  • t.test - Two-tailed paired t-test

  • cor - Persons Correlation

  • entropy - Delta entropy

  • cross-entropy - Cross-entropy loss function

  • divergence - Kullback-Leibler divergence (relative entropy)

Kappa and t-test values < 0 are reported as 0. For a weighted kappa, a matrix must be provided that correspond to the pairwise weights for all values in both rasters. Delta entropy is derived by calculating Shannon's on each focal window then differencing them (e(x) - e(y)). The s argument can be a single scalar, defining a symmetrical kernel, two scalers defining the dimensions of the kernel eg., c(3,5) or a matrix defining the kernel say, resulting from terra::focalMat

Value

A terra SpatRaster layer containing one of the following layers:

  • kappa - Kappa or Weighted Kappa statistic (if stat = "kappa")

  • correlation - Paired t.test statistic (if stat = "cor")

  • entropy - Local entropy (if stat = "entropy")

  • divergence - Kullback-Leibler divergence (if stat = "divergence")

  • cross.entropy - Local Cross-entropy (if stat = "cross.entropy")

  • t.test - Paired t.test statistic (if stat = "t.test")

  • p.value - p-value of the paired t.test statistic (if stat = "t.test")

Author(s)

Jeffrey S. Evans jeffrey_evans@tnc.org

References

Cohen, J. (1960). A coefficient of agreement for nominal scales. Educational and Psychological Measurement, 20:37-46

McHugh M.L. (2012) Interrater reliability: the kappa statistic. Biochemia medica, 22(3):276–282.

Kullback, S., R.A. Leibler (1951). On information and sufficiency. Annals of Mathematical Statistics. 22(1):79–86

Examples


 library(sf) 
 library(terra) 
  
 e <- ext(179407.8, 181087.9, 331134.4, 332332.1)
 r1 <- rast(e, resolution=20)
   r1[] <- sample(1:5, ncell(r1), replace=TRUE)
 r2 <- rast(e, resolution=20)
   r2[] <- sample(1:5, ncell(r2), replace=TRUE)
 	  
 d = 5 # kernel    
 ( r.kappa <- raster.change(r1, r2, s = d) )   
 ( r.ttest <- raster.change(r1, r2, s = d, stat="t.test") )
 ( r.ent <- raster.change(r1, r2, s = d, stat="entropy") )   
 ( r.cor <- raster.change(r1, r2, s = d, stat="cor") )
 ( r.ce <- raster.change(r1, r2, s = d, stat = "cross-entropy") )
 ( r.kl <- raster.change(r1, r2, s = d, stat = "divergence") )	
       
   opar <- par(no.readonly=TRUE)
   par(mfrow=c(3,2))
     plot(r.kappa, main="Kappa")
     plot(r.ttest[[1]], main="Paired t-test")
     plot(r.ent, main="Delta Entropy")
     plot(r.cor, main="Rank Correlation")
     plot(r.kl, main="Kullback-Leibler")
     plot(r.ce, main="cross-entropy")
   par(opar) 



spatialEco documentation built on Nov. 18, 2023, 1:13 a.m.