-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_Spatial_network.Rmd
133 lines (83 loc) · 5.56 KB
/
01_Spatial_network.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
title: "Spatial network of available cultures"
author: "Ty Tuff, Bruno Vilela, and Carlos Botero"
date: 'project began: 15 May 2016, document updated: `r strftime(Sys.time(), format
= "%d %B %Y")`'
output:
html_notebook: default
html_document: default
pdf_document: default
word_document: default
bibliography: FARM package.bib
---
While we have information on where nodes should be located, we still lack data on how cultural nodes should be connected. To compensate for a lack of data describing these connections between societies, we randomized the number of edges between nodes for different simulations. We created 11 different networks, each with a different minimum number of neighbors ranging from 4 to 14 computed using the function … in the R package … . This function builds a network where the minimum number of connections is achieved for every node, but some nodes may have more connections than that minimum in order to achieve the minimum connections for every node across the network. At the beginning of each simulation, the algorithm draws one of the 11 available networks and uses that network as the arena for carrying out that simulation.
Each node occupies a unique geographic location that is assigned a binary value indicating whether the environment of the region is more favorable to foragers or domesticators based on the results from Vilela et al (unpublished work). This designation was determined by the potential richness of domesticated species in each location estimated using ecological niche models. The threshold richness, above which we considered the region more favorable to domesticators, correspond to the potential number of species where farming societies become the dominant form of subsistence. Only some of these societies were inside of the known origins of agriculture as reported by Larson et al 2014 so, we assigned each node a value of 1 or 0 to distinguish between those inside or outside of those origins.
# Spatial scaffolding for the simulations
Using the ~8000 currently extant cultures cataloged in the glottolog repository
(http://glottolog.org), we calculated a symetrical spatial proximity network
connecting them. This network provides the scaffolding for the simulation to
grow on.
```{r}
library(FARM)
library(spdep)
library(geosphere)
library(maps)
```
We constructed this network using the functions knearneigh() and knn2nb() in
the package spdep. The user identifies the number of neighbors and the
algorythm identifies that many nearest neighbors calculated based on proximity.
Using those neighbor identifiers, we then calculated the great circle distance
between each point using the gcIntermediate() function from the geosphere
package and ploted those lines over a map.
Through a seperate analysis based on ecological niche models of agricultue,
we determined that networks with 7 neighbors produced spatial distributions with
the lowest level of autocorrelation. Accordingly, we ran the simulation on
networks with 5-9 connections between neighbors to represent some variation in
this parameter but centered these estimates around 7. At the begining of each
simualation, one network was chosen from the 5 possible arrangements and used
as simulation scaffolding. The number of neighbors assigned to a particular
simulation replicate is recorded in the metadata so it can be extracted and used
as a covariate in later models.
Here is the code for producing and plotting these networks. The object
language_centroids is in the FARM package, so make sure that package is loaded
so R can find the required data. Below the code are plots of the 5 possible
graph arrangements used in the FARM simulations.
```{r eval=FALSE}
coords <- as.matrix(apply(language_centroids[, 3:4], 2, as.numeric)) #coords
conds <- ifelse(suitability2 == 0, 1, 2)
conds[is.na(conds)] <- sample(c(1, 2), sum(is.na(conds)), replace = TRUE)
origins <- language_centroids[, 5]
nbs_number <- 2
this_row <- 1
number_of_neighbors <- 7
for(i in 5:9){
number_of_neighbors <- i
nbs <- knearneigh(coords, k = number_of_neighbors, longlat = TRUE)
nbs_list <- knn2nb(nbs, sym = TRUE)
png(paste("network_scratch_", number_of_neighbors, ".png"), width=11, height=5.5, res=1000, units = "in")
par(mar=c(0,0,0,0))
plot(0,0, xlim=c(-180,180), ylim=c(-90,90), type="n")
map("world", col=adjustcolor("lightgrey", alpha=0.2), interior = FALSE, fill=TRUE, border=NA)
#map("state", col="lightgrey")
for(this_row in 1:length(nbs_list)){
for(nbs_number in 1:length(nbs_list[[this_row]])){
#pointser <- NULL
pointser <- gcIntermediate(c(coords[nbs_list[[this_row]][nbs_number],1], coords[nbs_list[[this_row]][nbs_number],2]), c(coords[this_row,1], coords[this_row,2]), n=100, breakAtDateLine = T)
length(pointser)
if(length(pointser) == 200){lines(pointser, col=adjustcolor("black", alpha=1), lwd=.3)}
if(length(pointser) == 2){lines(pointser[[1]], col=adjustcolor("black", alpha=1), lwd=.3)
lines(pointser[[2]], col=adjustcolor("black", alpha=1), lwd=.3)}
#lines(pointser, col="red", lwd=.5)
if(length(pointser) == 200){lines(pointser, col="cornflowerblue", lwd=.25)}
if(length(pointser) == 2){lines(pointser[[1]], col="cornflowerblue", lwd=.25)
lines(pointser[[2]], col="cornflowerblue", lwd=.25)}
mtext(paste0("Network with at least ", number_of_neighbors, " connections between each culture"), 3, line=0)
}}
dev.off()
}
```
![5 neighbor network](network_scratch_ 5 .png)
![6 neighbor network](network_scratch_ 6 .png)
![7 neighbor network](network_scratch_ 7 .png)
![8 neighbor network](network_scratch_ 8 .png)
![9 neighbor network](network_scratch_ 9 .png)