R/moranI.R

Defines functions moranI

Documented in moranI

#[export]
moranI <- function(x, w, scaled = FALSE, R = 999) {
  if ( !scaled )  w <- w / Rfast::rowsums(w)
  y <- w %*% x
  if (R > 1) {
    b <- Rfast::permcor(y, x, R = R) 
    res <- c( b[1] * Rfast::Var(y, std = TRUE) / Rfast::Var(x, std = TRUE), b[2] )
  } else  res <- c( cor(y, x,) * Rfast::Var(y, std = TRUE) / Rfast::Var(x, std = TRUE), NA )	
  names(res) <- c("Moran's I", "permutation p-value")
  res
}

Try the Rfast2 package in your browser

Any scripts or data that you put into this service are public.

Rfast2 documentation built on May 29, 2024, 8:45 a.m.