tests/testthat/test-moransI.R

test_that("moransI and moransI.w agree for binary adaptive weights", {
  set.seed(123)
  d <- random.test.data(nrows = 5, ncols = 5)
  Coords <- cbind(d$X + runif(25)/10, d$Y + runif(25)/10)
  bw <- 4
  mI <- moransI(Coords, bw, d$dep)
  w <- w.matrix(Coords, bw, WType = "Binary", family = "adaptive")
  mI.w <- moransI.w(d$dep, w)
  expect_equal(mI$Morans.I, as.numeric(mI.w$Morans.I), tolerance = 1e-10)
  expect_equal(mI$Expected.I, -1 / (25 - 1), tolerance = 1e-10)
  expect_true(mI$p.value.resampling >= 0 && mI$p.value.resampling <= 1)
  expect_true(mI$p.value.randomization >= 0 && mI$p.value.randomization <= 1)
})

Try the lctools package in your browser

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

lctools documentation built on July 9, 2026, 9:07 a.m.