philchodrow / compx Goto Github PK
View Code? Open in Web Editor NEWAnalyze spatial and temporal separation using information geometry
Home Page: https://philchodrow.github.io/compx/
Analyze spatial and temporal separation using information geometry
Home Page: https://philchodrow.github.io/compx/
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)
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()
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
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
Line 180 in 4f5c6fe
h$name <- lookup$n
Everything works. I use the last version of R and Mac OS :(
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.