Closed JosiahParry closed 1 year ago
e.g.
data(boston, package = "spData")
x <- boston.c$CRIM
y <- boston.c$NOX
listw <- spdep::nb2listw(boston.soi)
set.seed(1)
res_xy <- spdep::moran_bv(x, y, listw, nsim=499)
p_sim <- function(x) {
alternative <- "two.sided"
nsim <- x[["R"]]
obs <- x[["t0"]]
replicates <- x[["t"]]
gt <- (sum(obs >= replicates) + 1 )/ (nsim + 1)
lt <- (sum(obs <= replicates) + 1 )/ (nsim + 1)
tt <- pmin(gt, lt)
switch(
alternative,
two.sided = tt,
less = lt,
greater = gt
)
}
p_sim(res_xy)
#> [1] 0.002
well, with the alternative as an argument and not hard coded, but you get my point :)
I'll take a look, it may take a little while. Are there any such extractors in the boot package? boot.ci()
or norm.ci()
perhaps?
moran_bv()
now returns a boot object. It isn't immediately clear how to interpret that object. I can be useful to have a helper to extract the simulated p-value.