[object Object]

空間自己相関

library(tidyverse)
library(sf)
library(jpndistrict)

df_h17to27_pops <- 
  readr::read_rds(here::here("data-raw", "population_h17-h22.rds"))

sf_pref08 <- 
  jpn_pref(8, district = TRUE)
  
df_pref08_pops <- 
  df_h17to27_pops %>% 
  filter(pref_code == "08", year == 2015, city_type != "a") %>% 
  select(city_code, population)

sf_pref08_pops2015 <- 
  sf_pref08 %>% 
  inner_join(df_pref08_pops, 
             by = c("city_code"))
pops <- 
  c(sf_pref08_pops2015$population)

library(spdep)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Loading required package: Matrix
1
## 
## Attaching package: 'Matrix'
1
2
## The following object is masked from 'package:tidyr':
## 
##     expand
1
2
3
## Loading required package: spData
1
## To access larger datasets in this package, install the spDataLarge
## package with: `install.packages('spDataLarge',
## repos='https://nowosad.github.io/drat/', type='source'))`
1
2
3
## 
## Attaching package: 'spData'
1
2
## The following object is masked _by_ '.GlobalEnv':
## 
##     x
1
2
3
# NS
moran.test(pops,
           st_coordinates(st_centroid(sf_pref08_pops2015)) %>% 
             tri2nb() %>% 
             nb2listw()) %>% 
  broom::tidy()
1
2
3
4
5
6
## Warning in st_centroid.sf(sf_pref08_pops2015): st_centroid assumes
## attributes are constant over geometries of x
1
2
## Warning in st_centroid.sfc(st_geometry(x), of_largest_polygon =
## of_largest_polygon): st_centroid does not give correct centroids for
## longitude/latitude data
1
2
3
## 
##      PLEASE NOTE:  The components "delsgs" and "summary" of the
##  object returned by deldir() are now DATA FRAMES rather than
##  matrices (as they were prior to release 0.0-18).
##  See help("deldir").
##  
##      PLEASE NOTE: The process that deldir() uses for determining
##  duplicated points has changed from that used in version
##  0.0-9 of this package (and previously). See help("deldir").
1
2
3
4
5
6
7
8
9
## # A tibble: 1 x 7
##   estimate1 estimate2 estimate3 statistic p.value method       alternative
##       <dbl>     <dbl>     <dbl>     <dbl>   <dbl> <chr>        <chr>      
## 1   -0.0231   -0.0233   0.00659   0.00207   0.499 Moran I tes… greater
1
2
3
4
# NS
geary.test(pops,
           st_coordinates(st_centroid(sf_pref08_pops2015)) %>% 
             tri2nb() %>% 
             nb2listw())
1
2
3
4
5
## Warning in st_centroid.sf(sf_pref08_pops2015): st_centroid assumes
## attributes are constant over geometries of x

## Warning in st_centroid.sf(sf_pref08_pops2015): st_centroid does not give
## correct centroids for longitude/latitude data
1
2
3
4
5
## 
## 	Geary C test under randomisation
## 
## data:  pops 
## weights: st_coordinates(st_centroid(sf_pref08_pops2015)) %>% tri2nb() %>%  
## pops 
## weights:     nb2listw() 
## 
## Geary C statistic standard deviate = -0.26299, p-value = 0.6037
## alternative hypothesis: Expectation greater than statistic
## sample estimates:
## Geary C statistic       Expectation          Variance 
##       1.023172615       1.000000000       0.007763632
1
2
3
4
5
6
7
8
9
10
11
12
13

ネットワーク分析

クリキング