Skip to content

Commit

Permalink
fixes #1592
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Dec 19, 2024
1 parent 545fb19 commit d077a38
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/autocor.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ setMethod("autocor", signature(x="SpatRaster"),
wZiZj <- wZiZj * z
wZiZj <- unlist(global(wZiZj, "sum", na.rm=TRUE))
z2 <- unlist(global(z*z, "sum", na.rm=TRUE))
n <- ncell(z) - unlist(global(is.na(z), "sum"))
n <- ncell(z) - unlist(global(z, "isNA"))
zz <- ifel(is.na(x), NA, 1)
W <- focal( zz, w=w, fun="sum")
W <- focal( zz, w=w, fun="sum", na.rm = TRUE, na.policy="omit")
NS0 <- n / unlist(global(W, "sum", na.rm=TRUE))
m <- NS0 * wZiZj / z2
names(m) <- names(x)
m
} else { # geary
w <- .getFilter(w, warn=FALSE)
i <- trunc(length(w)/2)+1
n <- ncell(x) - unlist(global(is.na(x), "sum"))
n <- ncell(x) - unlist(global(x, "isNA"))
fun <- function(x,...) sum((x-x[i])^2, ...)
f <- focal(x, w=dim(w), fun=fun, na.rm=TRUE)
Eij <- unlist(global(f, "sum", na.rm=TRUE))
Expand Down

0 comments on commit d077a38

Please sign in to comment.