Learn R Programming

spatialEco (version 2.0-2)

raster.modified.ttest: Dutilleul moving window bivariate raster correlation

Description

A bivarate raster correlation using Dutilleul's modified t-test

This function provides a bivariate moving window correlation using the modified t-test to account for spatial autocorrelation. Point based subsampling is provided for computation tractability. The hexagon sampling is recommended as it it good at capturing spatial process that includes nonstationarity and anistropy.

Usage

raster.modified.ttest(
  x,
  y,
  d = "auto",
  sample = c("none", "random", "hexagonal", "regular"),
  p = 0.1,
  size = NULL
)

Value

A terra SpatRaster or sf POINT class object with the following attributes:

  • corr - Correlation

  • Fstat - The F-statistic calculated as degrees of freedom unscaled F-statistic

  • p.value - p-value for the test

  • moran.x - Moran's-I for x

  • moran.y - Moran's-I for y

Arguments

x

A terra SpatRaster class object

y

A terra SpatRaster class object, same dimensions as x

d

Distance for finding neighbors

sample

Apply sub-sampling options; c("none", "random", "hexagonal", "regular")

p

If sample != "none", what proportion of population should be sampled

size

Fixed sample size (default NULL)

Author

Jeffrey S. Evans jeffrey_evans@tnc.org

References

Clifford, P., S. Richardson, D. Hemon (1989), Assessing the significance of the correlationbetween two spatial processes. Biometrics 45:123-134.

Dutilleul, P. (1993), Modifying the t test for assessing the correlation between two spatial processes. Biometrics 49:305-314.

See Also

modified.ttest for test details

Examples

Run this code
# \donttest{
 p = c("sf", "sp", "terra", "gstat")
 if(any(!unlist(lapply(p, requireNamespace, quietly=TRUE)))) { 
   m = which(!unlist(lapply(p, requireNamespace, quietly=TRUE)))
   message("Can't run examples, please install ", paste(p[m], collapse = " "))
 } else {
   invisible(lapply(p, require, character.only=TRUE))

data(meuse, package = "sp")
meuse <- st_as_sf(meuse, coords = c("x", "y"), crs = 28992, 
                  agr = "constant") 
data(meuse.grid, package = "sp")                                      
meuse.grid <- st_as_sf(meuse.grid, coords = c("x", "y"), crs = 28992, 
                  agr = "constant") 

ref <- rast(ext(meuse.grid), resolution = 40)
  crs(ref) <- crs(meuse)
e <- ext(179407.8, 181087.9, 331134.4, 332332.1)
                                       
# GRID-1 log(copper): 
v1 <- variogram(log(copper) ~ 1, meuse) 
  x1 <- fit.variogram(v1, vgm(1, "Sph", 800, 1))           
  G1 <- krige(zinc ~ 1, meuse, meuse.grid, x1, nmax = 30)
G1 <- crop(rasterize(G1, ref, "var1.pred"),e)
names(G1) <- "copper"
 
 # GRID-2 log(elev):
v2 <- variogram(log(elev) ~ 1, meuse) 
  x2 <- fit.variogram(v2, vgm(1, "Sph", 800, 1))           
  G2 <- krige(zinc ~ 1, meuse, meuse.grid, x2, nmax = 30)
G2 <- crop(rasterize(G2, ref, "var1.pred"),e)
names(G2) <- "elev"

# Raster corrected correlation 
acor <- raster.modified.ttest(G1, G2)
  plot(acor)
 
# Sample-based corrected correlation
( cor.hex <- raster.modified.ttest(G1, G2, sample = "hexagonal") )	 
  plot(cor.hex["corr"], pch=20)
}
# }

Run the code above in your browser using DataLab