Skip to content

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

@denis-or

Description

@denis-or

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions