Git Product home page Git Product logo

rgeoda's Introduction

rgeoda

R-CMD-check lint-project pkgdown

rgeoda is a R package for spatial data analysis based on libgeoda and GeoDa. It provides spatial data analysis functionalities including Exploratory Spatial Data Analysis, Spatial Cluster Detection and Clustering Analysis, Regionalization, etc. based on the C++ source code of GeoDa, which is an open-source software tool that serves as an introduction to spatial data analysis. The GeoDa software and its documentation are available at https://geodacenter.github.io.

The rgeoda site is built using pkgdown: https://geodacenter.github.io/rgeoda

Installation

install.packages("rgeoda")

cran status cran release cran downloads

Quick Start

library(sf)
library(rgeoda)

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

w <- queen_weights(guerry)
lisa <- local_moran(w, guerry['Crm_prs'])
clusters <- skater(4, w, guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')])

Tutorials

https://geodacenter.github.io/rgeoda/articles/rgeoda_tutorial.html

APIs

https://geodacenter.github.io/rgeoda/reference/

Current version 0.0.9

  • Map Classification

    • NaturalBreaks
    • QuantileBreaks
    • Hinge15Breaks
    • Hinge30Breaks
    • PercentileBreaks
    • StddevBreaks
  • Spatial Weights

    • Queen
    • Rook
    • Distance based
    • K-Nearest Neighbor
    • Kernel
    • Read GAL/GWT/SWM weights
  • Spatial Autocorrelation

    • Local Moran
    • Bivariate Local Moran
    • Local Moran EB Rates
    • Local Geary
    • Local Getis-Ord
    • Multivariate Local Geary
    • Local Join Count
    • Bivariate Local Join Count
    • (Multivariate) Colocation Local Join Count
    • Quantile LISA
    • Multivariate Quantile LISA
    • Neighbor Match Test
  • Spatial Clustering

    • SCHC Spatial Constrained Hierarchical Clustering
      • Single-linkage
      • Complete-linkage
      • Average-linkage
      • Ward-linkage
    • SKATER
    • REDCAP
      • First-order and Single-linkage
      • Full-order and Complete-linkage
      • Full-order and Average-linkage
      • Full-order and Single-linkage
      • Full-order and Ward-linkage
    • AZP
      • greedy
      • Tabu Search
      • Simulated Annealing
    • Max-p
      • greedy
      • Tabu Search
      • Simulated Annealing
    • Join Count Ratio
    • Spatial Validation
      • Fragmentation
      • Join Count Ratio
      • Compactness
      • Diameter
    • Make Spatial

Build and install from source code

In R console, one can use devtools to install rgeoda from its source package:

devtools::install_github("geodacenter/rgeoda")

Mac

For Mac users, the “Xcode Command Line Tools” need to be installed for installing rgeoda. It is a free software provided by Apple, which can be installed by using the following command in a terminal:

xcode-select --install 

Note that the Xcode tools are not automatically updated when a new version of Xcode is installed. In order to make sure you have the latest version, use:

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

In order to make sure to have the correct C++ compiler for R 4.0 and later, follow the instructions on https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/.

Windows

On Windows, the Rtools needs to be installed first. https://cran.r-project.org/bin/windows/Rtools/

Linux

For Linux users, the “Build Essential Tools” needs to be installed first.

sudo apt-get update
sudo apt-get install build-essential

rgeoda's People

Contributors

giserdaishaoqing avatar lanselin avatar lixun910 avatar sdesabbata avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rgeoda's Issues

read_gal can't work

library(rgeoda)
guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda")
guerry <- sf::read_sf(guerry_path)
queen_w <- queen_weights(guerry)
save_weights(queen_w, guerry['CODE_DE'], './guerry1.gal')
w <- read_gal('./guerry1.gal', guerry['CODE_DE'][[1]])

The last line of code w <- read_gal('./guerry1.gal', guerry['CODE_DE'][[1]]) does not work properly

Example not reproducible

The join_count_ratio() function doc is not reproducible. This probably wasn't captured because the tests are wrapped in a \donttrun{} (and I can't tell why? this example contains fully valid R code)

The correct example code is:

library(sf)
guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda")
guerry <- st_read(guerry_path)
queen_w <- queen_weights(guerry)
data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')]
clusters <- skater(5, queen_w, data)
results <- join_count_ratio(clusters$Clusters, queen_w)

results

rgeoda/R/clustering.R

Lines 696 to 706 in 94c17da

#' \dontrun{
#' library(sf)
#' guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda")
#' guerry <- st_read(guerry_path)
#' queen_w <- queen_weights(guerry)
#' data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')]
#' clusters <- skater(5, queen_w, data)
#' results <- join_count_ratio(clusters, queen_w)
#' results
#' }
#' @export

Unconnected graph crashes `skater()`

This will crash R:

library(sf)
columbus <- st_read(system.file("shapes/columbus.shp", package="spData"))
library(rgeoda)
columbus_43 <- columbus[columbus$NEIG != 43,]
plot(st_geometry(columbus_43), axes=TRUE)
qw <- queen_weights(columbus_43)
geoda_o <- skater(4, qw, columbus_43[,7:9])

#*** caught segfault ***
#address (nil), cause 'memory not mapped'

#Traceback:
# 1: p_skater(k, w$GetPointer(), df, n_vars, scale_method, distance_method,     bound_values, min_bound, random_seed, cpu_threads)
# 2: skater(4, qw, columbus_43[, 7:9])

I think because there is no check that the graph is connected for the minimum spanning tree step.

Differences between results geoda vs rgeoda

Hi all,

We runned geoda in the application and the R software, and there are a lot of differences, in the second case we have only high - high zones, while that running the same dataset with geoda app we have a good results. I wonder, if please, you could help me. What can I do? There is a bug in the library? or in my programm
Moran univariado Tasa de lesividad bruta por accidentes de tránsito 2015
ing?
Moran univariado Tasa de lesividad bruta por accidentes de tránsito 2017

Best regards,
Fabio Castro

sf_to_geoda removes all columns from sf object

When you try to convert an sf object to a geoda object, it removes all the columns of the sf object.

I'm using the guerry sf object from the teaching geodaData package here.

library(geodaData)
library(rgeoda)
guerry_sf <- geodaData::guerry
guerry_geoda <- rgeoda::sf_to_geoda(guerry_sf)
#> Loading required package: sf
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
#> Loading required package: wkb
guerry_geoda
#> Reference class object of class "geoda"
#> Field "gda":
#> An object of class "_p_GeoDa"
#> Slot "ref":
#> <pointer: 0x7fcbfbf7c810>
#> 
#> Field "map_type":
#> [1] "polygon_type"
#> Field "n_cols":
#> [1] 0
#> Field "n_obs":
#> [1] 85
#> Field "field_names":
#> character(0)
#> Field "field_types":
#> character(0)
#> Field "table":
#> data frame with 0 columns and 85 rows

redcap (RStudio crashes)

My code
library(sf)
library(rgeoda)

bf_geoda <- st_read(dsn = "shapefile/bf_geodata",
layer = "bf_zoning_data")

queen_w <- queen_weights(bf_geoda)
cls <- redcap(4, queen_w, bf_geoda["rain"],cpu_threads=1)

Also, skater return only 1 cluster and all metrics are NA. I don't know why but with guerry data everything is okay.

image

My Session Info :

R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Ventura 13.0

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base

loaded via a namespace (and not attached):
[1] compiler_4.2.2 tools_4.2.2 rstudioapi_0.14

add input parameter "seed=" for lisa functions

Add an input parameter "seed=" for all lisa functions:

  • Local Moran: local_moran()
  • Local Geary: local_geary(), local_multigeary()
  • Local Getis-Ord statistics: local_g() and local_gstar()
  • Local Join Count: local_joincount(), local_multijoincount()
  • Quantile LISA: local_quantilelisa()

The "seed" parameter is to allow users to setup random seed numbers in lisa computation. The default random seed number 123456789 is currently used in lisa computation.

maxp_greedy crashing RStudio

Hello !
I have been using the function "maxp_greedy" from rgeoda for many months and it was working perfectly. I tried running the same unmodified script this week and the maxp_greedy function is not working anymore. I have the following error "R encountered a fatal error. The session was terminated".
I tried to download an older version of rgeoda but got errors while dowloading version 0.0.9 and older ones.
Has anyone encountered the same issues (fatal error using maxp_greedy or/and issues downloading older versions of rgeoda) ?
Thank you for your help !

CRAN gcc-ASAN check error

Details:

  • using log directory ‘/data/gannet/ripley/R/packages/tests-gcc-SAN/rgeoda.Rcheck’
  • using R Under development (unstable) (2021-01-28 r79896)
  • using platform: x86_64-pc-linux-gnu (64-bit)
  • using session charset: UTF-8
  • using option ‘--no-stop-on-test-error’
  • checking for file ‘rgeoda/DESCRIPTION’ ... OK
  • checking extension type ... Package
  • this is package ‘rgeoda’ version ‘0.0.6’
  • package encoding: UTF-8
  • checking package dependencies ... OK
  • checking if this is a source package ... OK
  • checking if there is a namespace ... OK
  • checking for hidden files and directories ... OK
  • checking for portable file names ... OK
  • checking whether package ‘rgeoda’ can be installed ... [1175s/345s] OK
  • checking package directory ... OK
  • checking whether the package can be loaded ... OK
  • checking whether the package can be loaded with stated dependencies ... OK
  • checking whether the package can be unloaded cleanly ... OK
  • checking whether the namespace can be loaded with stated dependencies ... OK
  • checking whether the namespace can be unloaded cleanly ... OK
  • checking loading without being on the library search path ... OK
  • checking compiled code ... OK
  • checking examples ... ERROR
    Running examples in ‘rgeoda-Ex.R’ failed
    The error most likely occurred in:

Name: redcap

Title: Regionalization with dynamically constrained agglomerative

clustering and partitioning

Aliases: redcap

** Examples

guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda")
guerry <- geoda_open(guerry_path)
queen_w <- queen_weights(guerry)
guerry_df <- as.data.frame(guerry) # use as data.frame
data <- guerry_df[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')]
guerry_clusters <- redcap(4, queen_w, data, "fullorder-completelinkage")
=================================================================
==3891874==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete []) on 0x602000762090
#0 0x7fde898f3cd7 in operator delete (/lib64/libasan.so.6+0xb2cd7)
#1 0x7fde75f7f5b3 in redcap_wrapper::redcap_wrapper(unsigned int, GeoDaWeight*, std::vector<std::vector<double, std::allocator >, std::allocator<std::vector<double, std::allocator > > > const&, unsigned int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::vector<double, std::allocator > const&, double, int, int) libgeoda_src/clustering/redcap_wrapper.cpp:61
#2 0x7fde756755d6 in gda_redcap(unsigned int, GeoDaWeight*, std::vector<std::vector<double, std::allocator >, std::allocator<std::vector<double, std::allocator > > > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::vector<double, std::allocator > const&, double, int, int) libgeoda_src/gda_clustering.cpp:164
#3 0x7fde762486a8 in p_redcap(int, SEXPREC*, Rcpp::Vector<19, Rcpp::PreserveStorage>&, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, Rcpp::Vector<14, Rcpp::PreserveStorage>&, double, int, int) /data/gannet/ripley/R/packages/tests-gcc-SAN/rgeoda/src/rcpp_clustering.cpp:116
#4 0x7fde76285baa in _rgeoda_p_redcap /data/gannet/ripley/R/packages/tests-gcc-SAN/rgeoda/src/RcppExports.cpp:76
#5 0x57d10d in R_doDotCall /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c:634
#6 0x5866bc in do_dotcall /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c:1281
#7 0x6288eb in bcEval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:7115
#8 0x670607 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:727
#9 0x6758f4 in R_execClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1897
#10 0x677d97 in Rf_applyClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1823
#11 0x64704e in bcEval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:7083
#12 0x670607 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:727
#13 0x6758f4 in R_execClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1897
#14 0x677d97 in Rf_applyClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1823
#15 0x670ecf in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:850
#16 0x67cf99 in do_set /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:2969
#17 0x6712f8 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:802
#18 0x6f0c0d in Rf_ReplIteration /data/gannet/ripley/R/svn/R-devel/src/main/main.c:264
#19 0x6f1258 in R_ReplConsole /data/gannet/ripley/R/svn/R-devel/src/main/main.c:314
#20 0x6f13a4 in run_Rmainloop /data/gannet/ripley/R/svn/R-devel/src/main/main.c:1113
#21 0x6f13f2 in Rf_mainloop /data/gannet/ripley/R/svn/R-devel/src/main/main.c:1120
#22 0x41b3c8 in main /data/gannet/ripley/R/svn/R-devel/src/main/Rmain.c:29
#23 0x7fde881fb081 in __libc_start_main (/lib64/libc.so.6+0x27081)
#24 0x41db3d in _start (/data/gannet/ripley/R/gcc-SAN/bin/exec/R+0x41db3d)

0x602000762090 is located 0 bytes inside of 8-byte region [0x602000762090,0x602000762098)
allocated by thread T0 here:
#0 0x7fde898f1667 in __interceptor_malloc (/lib64/libasan.so.6+0xb0667)
#1 0x7fde7619d2de in distancematrix(int, int, double**, int**, double*, char, int) libgeoda_src/clustering/cluster.cpp:3276
#2 0x7fde75f7f028 in redcap_wrapper::redcap_wrapper(unsigned int, GeoDaWeight*, std::vector<std::vector<double, std::allocator >, std::allocator<std::vector<double, std::allocator > > > const&, unsigned int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::vector<double, std::allocator > const&, double, int, int) libgeoda_src/clustering/redcap_wrapper.cpp:58
#3 0x7fde756755d6 in gda_redcap(unsigned int, GeoDaWeight*, std::vector<std::vector<double, std::allocator >, std::allocator<std::vector<double, std::allocator > > > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::vector<double, std::allocator > const&, double, int, int) libgeoda_src/gda_clustering.cpp:164
#4 0x7fde762486a8 in p_redcap(int, SEXPREC*, Rcpp::Vector<19, Rcpp::PreserveStorage>&, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, Rcpp::Vector<14, Rcpp::PreserveStorage>&, double, int, int) /data/gannet/ripley/R/packages/tests-gcc-SAN/rgeoda/src/rcpp_clustering.cpp:116
#5 0x7fde76285baa in _rgeoda_p_redcap /data/gannet/ripley/R/packages/tests-gcc-SAN/rgeoda/src/RcppExports.cpp:76
#6 0x57d10d in R_doDotCall /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c:634

SUMMARY: AddressSanitizer: alloc-dealloc-mismatch (/lib64/libasan.so.6+0xb2cd7) in operator delete
==3891874==HINT: if you don't care about these errors you may set ASAN_OPTIONS=alloc_dealloc_mismatch=0
==3891874==ABORTING

  • DONE
    Status: 1 ERROR

Skater crashing R

I updated to the latest version (0.10.4) because the "maxp_greedy" function was crashing R (see issue #39), but it seems that the bug wasn´t corrected for the "skater" function.

Weight creation from polygons wrong

It seems that queen_weights() is wrong (unzip attached file) in CRAN version 0.0.8.3:
chk.zip

library(sf)
chk <- st_read("chk.gpgk")
library(rgeoda)
get_neighbors(rook_weights(chk, precision_threshold=sqrt(.Machine$double.eps)), 1)
get_neighbors(queen_weights(chk, precision_threshold=sqrt(.Machine$double.eps)), 1)
library(spdep)
poly2nb(chk, queen=FALSE)[[1]]
poly2nb(chk, queen=TRUE)[[1]]

From examining the geometries, the single coordinate on the borders of 1 and 6 is ignored:

plot(st_geometry(chk))
text(st_coordinates(st_centroid(st_geometry(chk))))

maxp crashing RStudio on Arch

Hello!

I have tried to run several version of maxp, but they fail with the following message (can only catch it when running R from console, RStudio crashes):

 *** caught segfault ***
address 0x2d0, cause 'memory not mapped'

Traceback:
 1: p_maxp_greedy(w$GetPointer(), df, n_vars, bound_values, min_bound, iterations, initial_regions, scale_method, distance_method, random_seed, cpu_threads)
 2: maxp_greedy(queen_w, data, bound_vals, min_bound)

I am by no means an expert, but this particular error is mentioned, for example, here, although it is an old issue. I have tried to reinstall Rccp as well, but that did not help. During compilation of rgeoda, several warnings are thrown in relation to the BH library, such as:

/home/thesixmax/R/x86_64-pc-linux-gnu-library/4.1/BH/include/boost/config/pragma_message.hpp:24:34: note: ‘#pragma message: This header is deprecated. Use <iterator> instead.’
   24 | # define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))

and

/home/thesixmax/R/x86_64-pc-linux-gnu-library/4.1/BH/include/boost/smart_ptr/shared_ptr.hpp: In member function ‘boost::shared_ptr<T>& boost::shared_ptr<T>::operator=(std::auto_ptr<_Up>&&)’:
/home/thesixmax/R/x86_64-pc-linux-gnu-library/4.1/BH/include/boost/smart_ptr/shared_ptr.hpp:572:38: warning: ‘template<class> class std::auto_ptr’ is deprecated: use 'std::unique_ptr' instead [-Wdeprecated-declarations]
  572 |         this_type( static_cast< std::auto_ptr<Y> && >( r ) ).swap( *this );
      |                                      ^~~~~~~~

It does not matter if I install from github or CRAN either. However, the guerry example provided on your webpage does run, which confuses me! So I am a bit lost on whether it is a compiling issue, package issue, linux issue or R issue. When I pull in the shapefile and run maxp in the Geoda desktop software, it runs without issues.

sessionInfo()

R version 4.1.1 (2021-08-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Manjaro Linux

Matrix products: default
BLAS/LAPACK: /opt/intel/mkl/lib/intel64/libmkl_gf_lp64.so

locale:
 [1] LC_CTYPE=en_DK.UTF-8       LC_NUMERIC=C               LC_TIME=en_DK.UTF-8        LC_COLLATE=en_DK.UTF-8     LC_MONETARY=en_DK.UTF-8    LC_MESSAGES=en_DK.UTF-8   
 [7] LC_PAPER=en_DK.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_DK.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgeoda_0.0.8-6 digest_0.6.28  sf_1.0-3      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7           compiler_4.1.1       pillar_1.6.4         later_1.3.0          class_7.3-19         tools_4.1.1          tibble_3.1.6         jsonlite_1.7.2      
 [9] lifecycle_1.0.1      pkgconfig_2.0.3      rlang_0.4.12         shiny_1.7.1          DBI_1.1.1            fastmap_1.1.0        e1071_1.7-9          dplyr_1.0.7         
[17] generics_0.1.1       htmlwidgets_1.5.4    vctrs_0.3.8          tidyselect_1.1.1     classInt_0.4-3       DT_0.19              shinydashboard_0.7.2 grid_4.1.1          
[25] glue_1.5.0           R6_2.5.1             fansi_0.5.0          purrr_0.3.4          magrittr_2.0.1       promises_1.2.0.1     ellipsis_0.3.2       htmltools_0.5.2     
[33] units_0.7-2          assertthat_0.2.1     mime_0.12            xtable_1.8-4         httpuv_1.6.3         utf8_1.2.2           bs4Dash_2.0.3        KernSmooth_2.23-20  
[41] proxy_0.4-26         crayon_1.4.2

Any pointers are much appreciated!

make sf_to_geoda and sp_to_geoda R friendly

The functions sf_to_geoda and sp_to_geoda should become generic as.geoda( ) functions to which either an sf or an sp objects can be passed. So, the type of object passed needs to be detected by the function and then it works seamlessly to create a geoda object. For example, see as.ppp in spatstat.

Ideally, there should also be a geoda method added to as.sf and as.sp.

Max-P with data containing zero or very small values

Hello! I am working with the 'maxp_greedy' function. It works fine when the values of attributes (to be homogeneous) don't have significant variations. When they contain zero values or very small values, however, it takes forever and doesn't end, which doesn't seem right. Is it normal that maxp-greedy doesn't work well with data containing zeros? This is interesting because when I try the same thing in GeoDa Desktop, it works fine.

I would appreciate any comments. Thanks!

rgeoda fails to compile on Windows

We ran this in our workshop and this was an error message we got:

remotes::install_github("lixun910/rgeoda")
Downloading GitHub repo lixun910/rgeoda@master
√ checking for file 'C:\Users\Public\Documents\Wondershare\CreatorTemp\Rtmp61QG7m\remotes4628bf64594\lixun910-rgeoda-abd3684/DESCRIPTION' ...

  • preparing 'rgeoda':
    √ checking DESCRIPTION meta-information ...
  • cleaning src
  • checking for LF line-endings in source and make files and shell scripts
  • checking for empty or unneeded directories
  • building 'rgeoda_0.0.3.tar.gz'

Installing package into ‘C:/Users/aryaa/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)

  • installing source package 'rgeoda' ...
    ** using staged installation
    ** libs

*** arch - i386
rm -f rgeoda.dll rgeoda.o
mkdir -p ../inst
"C:/PROGRA1/R/R-361.1/bin/i386/Rscript.exe" --vanilla "../tools/winlibs.R" 2.2.3
Warning message:
In unzip("wxlib.zip", exdir = "../windows") : internal error in 'unz' code
cp -r ../windows/gdal2-2.2.3/share/gdal ../inst/
cp -r ../windows/gdal2-2.2.3/share/proj ../inst/
C:/RBuildTools/3.5/mingw_32/bin/g++ -std=gnu++11 -I"C:/PROGRA1/R/R-361.1/include" -DNDEBUG -I../windows/gdal2-2.2.3/include/gdal -I../windows/gdal2-2.2.3/include/geos -I../windows/gdal2-2.2.3/include/proj -I../windows/libgeoda_static-0.0.3.3/include -I../windows/wx_static-3.0.4/include -I../windows/wx_static-3.0.4/lib/i386/baseu -I../windows/ANN_static-1.1.2/include -O2 -Wall -mtune=generic -c rgeoda.cpp -o rgeoda.o
In file included from rgeoda.cpp:3544:0:
../windows/libgeoda_static-0.0.3.3/include/GeodaWeight.h:24:23: fatal error: wx/string.h: No such file or directory
#include <wx/string.h>
^
compilation terminated.
make: *** [C:/PROGRA1/R/R-361.1/etc/i386/Makeconf:215: rgeoda.o] Error 1
ERROR: compilation failed for package 'rgeoda'

  • removing 'C:/Users/aryaa/Documents/R/win-library/3.6/rgeoda'
    Error: Failed to install 'rgeoda' from GitHub:
    (converted from warning) installation of package ‘C:/Users/Public/Documents/Wondershare/CreatorTemp/Rtmp61QG7m/file462819e97d1d/rgeoda_0.0.3.tar.gz’ had non-zero exit status

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

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

Calculating Univariate Moran's I

Thanks very much for putting this together. I am looking forward to getting my hands dirty and having a go with this. I will probably be using it for teaching this summer (alongside GeoDa).

One question - is it possible to calculate the Univariate Moran's I (Global Moran's I) here? I can't find this in the tutorial - https://geodacenter.github.io/rgeoda/articles/rgeoda_tutorial.html.

I'd like to do this in R, but currently all I have is code in SP for this, whereas I'd like to use this library (or at least be able to use SF).

Many thanks,
Nick.

Create weights for sf with tibble classes

Hi,

When loading geographic data using read_sf instead of st_read, the resulting sf object has four classes. As such, the condition length(class(obj)) == 2 in line 86 of sf_geoda.R seems to block the casting of the sf object to geoda object. I would suggest changing the condition to allow objects with both 2 and 4 classes.

Line 86 of sf_geoda.R:

  } else if (length(class(obj)) == 2 && class(obj)[[1]] == "sf") {

Using st_read:

> st_read_loac <- st_read("Shapefile_London/LOAC.shp")
> class(st_read_loac)
[1] "sf"         "data.frame"
> length(class(st_read_loac))
[1] 2

Using read_sf:

> read_sf_loac <- read_sf("Shapefile_London/LOAC.shp")
> class(read_sf_loac)
[1] "sf"         "tbl_df"     "tbl"        "data.frame"
> length(class(read_sf_loac))
[1] 4

Local moran with NA

How Geoda calculates the local moran with NA values, because Rgeoda does not allow it because it cannot calculate with NA. What extra process does Geoda have than Rgeoda?

Random REDCAP and SKATER crashes

Hi!

I found that both Redcap and Skater algorithms randomly crash R when given too many polygons. The crash was recreated on different machines, including RStudio Cloud.

library(sf)
library(rgeoda)

# creating test geometry with random values
sfc = st_sfc(st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,0)))))
grid = st_make_grid(sfc, cellsize = 0.02, square = F)
grid = st_sf(geom = grid)
grid$value = runif(nrow(grid))

# assigning weights
w = queen_weights(grid)

# looping the redcap algorithm
# using print to see after how many iterations R crashes
for(i in 100:1){
  print(i)
  redcap(10, w, grid[,"value"])
}

Error when using "sf" "grouped_df" "tbl_df" "tbl" "data.frame" in queen_weights()

Hi !
I get this error "Error in as.geoda(sf_obj, with_table = FALSE) : as.geoda() takes either an 'sf' or 'sp' object. " when using queen_weights ().
I'm using a class object "sf" "grouped_df" "tbl_df" "tbl" "data.frame" and I thought that because is an sf one i could run properly. What am I missing ?

Thank you in advance

change input parameters of multi-variate lisa in v0.0.4

in version 0.0.4, there are two multivariate lisa functions:

  • local_multigeary(w, data)
  • local_multijoincount(w, data)

the second input parameter data is defined as a 2-d array, which one can get using the following code:

data <-as.list(guerry_df[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')])
multigeary <- local_multigeary(queen_w, data)

This is NOT straightforward to R users, and the proposed change is to use a data.frame object instead:

data <- guerry_df[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')]
multigeary <- local_multigeary(queen_w, data)

So, that requires to update the following functions in source code: R/lisa.R
https://github.com/lixun910/rgeoda/blob/6f9a62bb003885127027fed0b5d0adfa0690a060/R/lisa.R#L213-L230

and here:
https://github.com/lixun910/rgeoda/blob/6f9a62bb003885127027fed0b5d0adfa0690a060/R/lisa.R#L289-L306

The conversion from a data.frame to a 2-d array should be applied within these two functions.

Note: the related Rmd file under vignettes/ directory: rgeoda_tutorial_0_0_4.Rmd and rgeoda_tutorial_0_0_4cn.Rmd should be updated as well.

the color may be wrong for LISA mapping

Dear Prof. Li
When I run the rgeoda for my data, I found the legend color may be inconsistent with the results of geoda software (low-high and high-low). see the graph below:
image

How to load saved weight

Hi,

Please how can one load the saved load weight or .gwt file generated from the desktop Geoda?

Thanks a lot for porting this to R.

Odd p-values from `local_geary()`

In an example just added to spdep on github, issue r-spatial/spdep#68, I find that the lisa_pvalues() are not bounded by [0, 0.5] as in for example local_moran() for the same data. When I "fold back" the values > 0.5, the vector correlates well with the equivalent conditional permutation output for the local Geary measure just added to spdep. Installing spdep from github (main), the following reproduces the objects and oddness:

library(spdep)
orig <- spData::africa.rook.nb
listw <- nb2listw(orig)
x <- spData::afcon$totcon

(A <- localC(x, listw))
listw1 <- nb2listw(droplinks(sym.attr.nb(orig), 3, sym=TRUE), zero.policy=TRUE)
(A1 <- localC(x, listw1, zero.policy=FALSE))
(A2 <- localC(x, listw1, zero.policy=TRUE))
if (require(rgeoda, quietly=TRUE)) {
  W <- create_weights(as.numeric(length(x)))
  for (i in 1:length(listw$neighbours)) {
    set_neighbors_with_weights(W, i, listw$neighbours[[i]], listw$weights[[i]])
    update_weights(W)
  }
  set.seed(1)
  B <- local_geary(W, data.frame(x))
  all.equal(A, lisa_values(B))
}
set.seed(1)
C <- localC_perm(x, listw, nsim = 499, conditional=TRUE, alternative="two.sided")
plot(lisa_pvalues(B), attr(C, "pseudo-p")[,6])
cor(lisa_pvalues(B), attr(C, "pseudo-p")[,6])
cor(ifelse(lisa_pvalues(B) < 0.5, lisa_pvalues(B), 1-lisa_pvalues(B)), attr(C, "pseudo-p")[,6])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.