-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoran_and_plot.R
52 lines (47 loc) · 2.2 KB
/
moran_and_plot.R
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
#Test Spatial Autocorrelation
require(spdep)
DC_w <- poly2nb(DC)
wlist <- nb2listw(DC_w, style="W", zero.policy = TRUE)
nsim <- 999
set.seed(1234)
DC_mi_black <- moran.mc(DC$black_diff, listw=wlist, nsim=nsim, zero.policy = TRUE)
ggsave(
filename = "./figures/DC_black_pop_difference_moransI.png",
plot = qplot(DC_mi_black$res[1:nsim],
main = "DC Spatial Pattern in Differences in the Black pop\nObserved Moran's I Compared 999 Random Maps",
xlab = ""
) + geom_vline(xintercept = DC_mi_black$statistic, col="red")
)
DC_mi_white <- moran.mc(DC$white_diff, listw=wlist, nsim=nsim, zero.policy = TRUE)
ggsave(
filename = "./figures/DC_white_pop_difference_moransI.png",
plot = qplot(DC_mi_white$res[1:nsim],
main = "DC Spatial Pattern in Differences in the White pop\nObserved Moran's I Compared 999 Random Maps",
xlab = ""
) + geom_vline(xintercept = DC_mi_white$statistic, col="red")
)
tct_w <- poly2nb(tct)
tct_wlist <- nb2listw(tct_w, style="W", zero.policy = TRUE)
nsim <- 999
set.seed(1234)
US_mi_white <- moran.mc(tct$white_diff, listw=tct_wlist, nsim=nsim, zero.policy = TRUE)
ggsave(
filename = "./figures/US_white_pop_difference_moransI.png",
qplot(US_mi_white$res[1:nsim],
main = "National Spatial Pattern in Differences in the White pop\nObserved Moran's I Compared 999 Random Maps",
xlab = "") + geom_vline(xintercept = US_mi_white$statistic, col="red")
)
US_mi_totpop <- moran.mc(tct$pop_diff, listw=tct_wlist, nsim=nsim, zero.policy = TRUE)
ggsave(
filename = "./figures/US_tot_pop_difference_moransI.png",
qplot(US_mi_totpop$res[1:nsim],
main = "National Spatial Pattern in Differences in total pop\nObserved Moran's I Compared 999 Random Maps",
xlab = "") + geom_vline(xintercept = US_mi_totpop$statistic, col="red")
)
US_mi_black <- moran.mc(tct$black_diff, listw=tct_wlist, nsim=nsim, zero.policy = TRUE)
ggsave(
filename = "./figures/US_black_difference_moransI.png",
qplot(US_mi_black$res[1:nsim],
main = "National Spatial Pattern in Differences in black pop\nObserved Moran's I Compared 999 Random Maps",
xlab = "") + geom_vline(xintercept = US_mi_black$statistic, col="red")
)