% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/raster.modified.ttest.R
\name{raster.modified.ttest}
\alias{raster.modified.ttest}
\title{Dutilleul moving window bivariate raster correlation}
\usage{
raster.modified.ttest(
  x,
  y,
  d = "auto",
  sample = c("none", "random", "hexagonal", "regular"),
  p = 0.1,
  size = NULL
)
}
\arguments{
\item{x}{A terra SpatRaster class object}

\item{y}{A terra SpatRaster class object, same dimensions as x}

\item{d}{Distance for finding neighbors}

\item{sample}{Apply sub-sampling options; c("none", "random", "hexagonal", "regular")}

\item{p}{If sample != "none", what proportion of population
should be sampled}

\item{size}{Fixed sample size (default NULL)}
}
\value{
A terra SpatRaster or sf POINT class object with the following attributes:
\itemize{
\item corr - Correlation
\item Fstat - The F-statistic calculated as degrees of freedom unscaled F-statistic
\item p.value - p-value for the test
\item moran.x - Moran's-I for x
\item moran.y - Moran's-I for y
}
}
\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.
}
\examples{
\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)
}
}
}
\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.
}
\seealso{
\code{\link[SpatialPack]{modified.ttest}} for test details
}
\author{
Jeffrey S. Evans  \href{mailto:jeffrey_evans@tnc.org}{jeffrey_evans@tnc.org}
}
