Learn R Programming

spatialEco (version 2.0-1)

raster.change: Raster change between two nominal rasters

Description

Compares two categorical rasters with a variety of statistical options

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)

Usage

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

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")

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

Author

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

Run this code
# \donttest{
 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) 
# }

Run the code above in your browser using DataLab