-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot classify Bivariate Moran Hotspots #155
Comments
@JosiahParry the object returned by Lines 45 to 56 in 1fb4943
pysal variant is like GeoDa (split on zero for z and lz), median was a speculation. For the present I'm adding a better error message.
|
Now says:
|
Thanks Roger! My apologies for the delay in getting back to you I was stuck in airports for far too long! I was having a think about this and how we could calculate the quadrant of the cluster. Given that the variables are not guaranteed to be on the same scale, I think one has to center and scale them so that they can be effectively compared. Here's how I might go about it library(spdep)
#> Loading required package: spData
#> To access larger datasets in this package, install the spDataLarge
#> package with: `install.packages('spDataLarge',
#> repos='https://nowosad.github.io/drat/', type='source')`
#> Loading required package: sf
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE library(sfdep)
library(ggplot2)
# constants
zero.policy=NULL
NAOK=FALSE
# SWM
listw <- nb2listw(
poly2nb(guerry)
)
# vars
x <- guerry$literacy
y <- guerry$instruction
# note the replacement of z with scale(y)
ly <- lag.listw(listw, scale(y), zero.policy=zero.policy, NAOK=NAOK)
lbs <- c("Low", "High")
quadr_ps <- interaction(
cut(scale(x), c(-Inf, 0, Inf), labels=lbs),
cut(ly, c(-Inf, 0, Inf), labels=lbs),
sep="-"
)
# Moran plot
data.frame(
x = scale(x),
ly,
clust = quadr_ps
) |>
ggplot(aes(x, ly, color = clust)) +
geom_point(size = 3) # calculate bv moran
bv_res <- localmoran_bv(x, y, listw, 499, TRUE) |>
as.data.frame()
# using 0.05 for example purposes
sig <- bv_res[["Pr(z != E(Ibvi)) Sim"]] < 0.05
# removing "insignificant" clusers
quadr_ps[!sig] <- NA
# visualize
ggplot() +
geom_sf(aes(fill = quadr_ps), guerry, lwd = 0.15, color = "black") +
scale_fill_viridis_d() |
@JosiahParry Could you please review 0152f72 and PR #156 |
@JosiahParry Should I modify |
895c520 adds bi-variate Moran plot. |
I am trying to use the
hotspot()
function to classify Bivariate Local Moran output but this results in an errorThe text was updated successfully, but these errors were encountered: