Skip to content
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

Error Bivariate Local Moran function (and Local MOran function too?) #37

Open
denis-or opened this issue Feb 19, 2023 · 1 comment
Open

Comments

@denis-or
Copy link

Hi folks!

I've been thinking about an error in the bivariate moran function and I'd like some help. Below, I replicate it with the guerry shp:

Ok:

  library(rgeoda)
  library(ggplot2)
  library(dplyr)
  library(sf)

guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda")
guerry <- sf::st_read(guerry_path)

lisa_rgeoda <- rgeoda::queen_weights(guerry) |> 
  rgeoda::local_bimoran(guerry[c("Crm_prp","Wealth")])

mutate(
  guerry,
  bv_moran = factor(
    x = rgeoda::lisa_clusters(lisa_rgeoda),
    levels = 0:6,
    labels = rgeoda::lisa_labels(lisa_rgeoda)
  )
) |>
  ggplot() +
  geom_sf(aes(fill = bv_moran)) +
  scale_fill_manual(name = "With rgeoda",
                    values = rgeoda::lisa_colors(lisa_rgeoda),
                    drop = F)

image

Not ok:

set.seed(123)
guerry$Crm_prp[sample(1:nrow(guerry), size = 3, replace = T)] <- NA

lisa_rgeoda_NA <- rgeoda::queen_weights(guerry) |> 
  rgeoda::local_bimoran(guerry[c("Crm_prp","Wealth")])

mutate(
  guerry,
  bv_moran = factor(
    x = rgeoda::lisa_clusters(lisa_rgeoda_NA),
    levels = 0:6,
    labels = rgeoda::lisa_labels(lisa_rgeoda_NA)
  )
) |>
  ggplot() +
  geom_sf(aes(fill = bv_moran)) +
  scale_fill_manual(name = "With rgeoda",
                    values = rgeoda::lisa_colors(lisa_rgeoda_NA),
                    drop = F)

image

Created on 2023-02-19 with reprex v2.0.2

It seems that part of the code is wrong or incomplete, as it does not cover the NAs or the values equal zero (I guess)
https://github.com/GeoDaCenter/libgeoda/blob/a9a3d0a3212dfc7cdc63d41f5e8033ba54063693/sa/BiLocalMoran.cpp#L81

Is it wrong if I use na.omit()? Like as: rgeoda::local_bimoran(na.omit(guerry[c("Crm_prp","Wealth")])) like so the map is different.

What I do? thanks

@denis-or
Copy link
Author

#31 I think it's the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant