GithubHelp home page GithubHelp logo

philchodrow / compx Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 1.0 22.95 MB

Analyze spatial and temporal separation using information geometry

Home Page: https://philchodrow.github.io/compx/

R 0.32% HTML 99.68%

compx's People

Contributors

philchodrow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

denadai2

compx's Issues

NA from compute metric

Hello Phil,
I'm trying to follow your vignette to compute a measure of spatial segregation from your code.

Thus, I have my own map (shapefile in meter projection) and my own data. Unfortunately, I can't see where the problem lies but compute metric returns me NA without warnings:

library(compx)
library(tidyverse)    # data import, manipulation, and viz. Need dev version of ggplot2 for viz
library(maptools)     # plot the tracts
library(RColorBrewer) # for plots
library(ggthemes)     # for theme_map
library(viridis)      # for color scales
library(units)        # needed by sf
library(sf)           # for io and viz
library(scales)       # for ggplot2 viz

detroit_tracts <- st_read("data/shps/milano_int.shp")
detroit_tracts %>% 
    ggplot() + 
    geom_sf() + 
    theme_map()

detroit_race <- read_csv('data/prova.csv')
detroit_race$n <- detroit_race$n
head(detroit_race)

screen shot 2018-05-29 at 19 10 05

tracts_to_use <- detroit_race 

tracts <- detroit_tracts %>% 
    filter(GEOID %in% tracts_to_use$tract)

data  <- tracts_to_use %>%
    filter(tract %in% tracts$GEOID) %>%
    group_by(tract) %>%
    ungroup() 

metric_df <- compute_metric(tracts, 
                            data, 
                            km = T,
                            r_sigma = 10,
                            s_sigma = 1, 
                            smooth = F,
                            hessian = euc_)
metric_df %>% head()

screen shot 2018-05-29 at 19 09 42

Is it normal?

I used the same variables of the vignette to make a toy example :)
Files are here (in case you need):
data.zip

I just installed R + packages (for the versions)

Thanks in advance

vector memory exhausted

Hello Phil,
sorry for this. I found a possible error in the library.

With the same data sources as #2, I run:

library(compx)        # main analysis functions
library(tidyverse)    # for data manipulation and viz
library(igraph)       # for network analysis
library(RColorBrewer) # for plots
library(ggthemes)     # for theme_map
library(units)        # needed for sf
library(sf)           # needed for io and visualization in this vignette
library(scales)       # for ggplot2 viz
library(RSpectra)     # fast eigenvalues, also used within compx

detroit_tracts <- st_read("data/shps/milano_int.shp")
detroit_tracts <- st_transform(detroit_tracts, 4326)

race_2010 <- read_csv('data/prova.csv')
race_2010$n <- race_2010$n

tracts_to_use <- race_2010 

tracts <- detroit_tracts %>% 
    filter(GEOID %in% tracts_to_use$tract)

js_dist <- function(n,m){
    
    N <- sum(n)
    M <- sum(m)
    
    p <- n/N
    q <- m/M
    
    sqrt((N/(M+N))*DKL(p, p+q) + (M/(M+N))*DKL(q, p+q))
}

g <- construct_information_graph(tracts = tracts, 
                                 data = race_2010, 
                                 divergence = js_dist)
g

And the error is:

Error: vector memory exhausted (limit reached?)
Traceback:

1. construct_information_graph(tracts = tracts, data = race_2010, 
 .     divergence = js_dist)
2. adj %>% undirect() %>% add_data(data_df) %>% information_distances(divergence) %>% 
 .     make_graph() %>% add_n(data_df) %>% add_coordinates(tracts)
3. withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
4. eval(quote(`_fseq`(`_lhs`)), env, env)
5. eval(quote(`_fseq`(`_lhs`)), env, env)
6. `_fseq`(`_lhs`)
7. freduce(value, `_function_list`)
8. function_list[[i]](value)
9. add_n(., data_df)
10. h %>% igraph::set.vertex.attribute("n", index = lookup$key, value = lookup$n)
11. withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
12. eval(quote(`_fseq`(`_lhs`)), env, env)
13. eval(quote(`_fseq`(`_lhs`)), env, env)
14. `_fseq`(`_lhs`)
15. freduce(value, `_function_list`)
16. withVisible(function_list[[k]](value))
17. function_list[[k]](value)
18. igraph::set.vertex.attribute(., "n", index = lookup$key, value = lookup$n)
19. i_set_vertex_attr(graph = graph, name = name, index = index, 
  .     value = value)

The error lies in

h %>% igraph::set.vertex.attribute('n', index = lookup$key, value = lookup$n)
, because if I substitute this line with:

h$name <- lookup$n

Everything works. I use the last version of R and Mac OS :(

construct_information_graph error: `nest_()` is now defunct

Dear Phil,
construct_information_graph() function is now throwing errors " nest_() was deprecated in tidyr 1.0.0 and is now defunct." I can try to install older tidyr versions. Or will there be a new version of compx?

I see that nest_() appears in constructors.R. So I will try to fix it locally in the meantime for my own use.

Best,
Madina

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.