presentation

1 Coding, table, and graph

1.1 Preparation

setwd("C:/Users/KOUKI/Documents/University/THESIS/data")
getwd()

library(tidyverse)
library(gt)
library(conflicted)
library(janitor)
library(plm)
library(ggplot2)
library(psych)
library(MASS)
library(corrplot)
library(car)
library(modelsummary)
library(skimr)
library(rstatix)
conflict_prefer("filter", "dplyr")
conflict_prefer("select", "dplyr")
conflict_prefer("lag", "dplyr")

library(httr)
library(estatapi)

appId <- "fa36d285e27be24a03967d0d29affdef3b1a63ea"

1.2 Collecting Data

1.2.1 School

stats_school <- GET(
  url = "https://api.e-stat.go.jp/rest/3.0/app/getStatsData?cdArea=01100%2C01101%2C01102%2C01103%2C01104%2C01105%2C01106%2C01107%2C01108%2C01109%2C01110%2C01202%2C01203%2C01204%2C01205%2C01206%2C01207%2C01208%2C01209%2C01210%2C01211%2C01212%2C01213%2C01214%2C01215%2C01216%2C01217%2C01218%2C01219%2C01220%2C01221%2C01222%2C01223%2C01224%2C01225%2C01226%2C01227%2C01228%2C01229%2C01230%2C01231%2C01233%2C01234%2C01235%2C01236%2C01303%2C01304%2C01331%2C01332%2C01333%2C01334%2C01337%2C01343%2C01345%2C01346%2C01347%2C01361%2C01362%2C01363%2C01364%2C01367%2C01370%2C01371%2C01391%2C01392%2C01393%2C01394%2C01395%2C01396%2C01397%2C01398%2C01399%2C01400%2C01401%2C01402%2C01403%2C01404%2C01405%2C01406%2C01407%2C01408%2C01409%2C01423%2C01424%2C01425%2C01427%2C01428%2C01429%2C01430%2C01431%2C01432%2C01433%2C01434%2C01436%2C01437%2C01438%2C01452%2C01453%2C01454%2C01455&cdCat01=E1101%2CE2101%2CE3101%2CE4101&appId=&lang=J&statsDataId=0000020205&metaGetFlg=Y&cntGetFlg=N&explanationGetFlg=Y&annotationGetFlg=Y&sectionHeaderFlg=1&replaceSpChars=0",
  query = list(
    appId = appId, 
    statsDataId = "0000020205")
) 
result <- content(stats_school) 
str(result, max.level = 4, list.len = 4) 
school <- estat_getStatsData(
  appId = appId,
  statsDataId = "0000020205", 
  cdCat01 = list("E1101",
                 "E2101",
                 "E3101",
                 "E4101")
) %>%
  select(-1,
         -2,
         -3,
         -8,
         -9,
         -11) %>%
  mutate(time_code = str_sub(time_code, 1, 4),
         time_code = as.integer(time_code),
         value = as.integer(value))
colnames(school) = c("subject","area_code","region","time","value")
school = school %>%
  dplyr::select(region, area_code, time, everything())
school = school %>%
  pivot_wider(names_from = "subject",
              values_from = value)
colnames(school)[4:7] = c("E1101_kindergartens",
                          "E2101_elementaryschools",
                          "E3101_juniorhighschools",
                          "E4101_highschools")
head(school)
# A tibble: 6 x 7
  region        area_code  time E1101_kindergartens E2101_elementaryschools
  <chr>         <chr>     <int>               <int>                   <int>
1 北海道 札幌市 01100      1980                 120                     160
2 北海道 札幌市 01100      1981                 126                     164
3 北海道 札幌市 01100      1982                 130                     171
4 北海道 札幌市 01100      1983                 134                     174
5 北海道 札幌市 01100      1984                 137                     178
6 北海道 札幌市 01100      1985                 139                     182
# i 2 more variables: E3101_juniorhighschools <int>, E4101_highschools <int>

1.2.2 Library

stats_library <- GET(
  url = "https://api.e-stat.go.jp/rest/3.0/app/getStatsData?cdArea=01100%2C01101%2C01102%2C01103%2C01104%2C01105%2C01106%2C01107%2C01108%2C01109%2C01110%2C01202%2C01203%2C01204%2C01205%2C01206%2C01207%2C01208%2C01209%2C01210%2C01211%2C01212%2C01213%2C01214%2C01215%2C01216%2C01217%2C01218%2C01219%2C01220%2C01221%2C01222%2C01223%2C01224%2C01225%2C01226%2C01227%2C01228%2C01229%2C01230%2C01231%2C01233%2C01234%2C01235%2C01236%2C01303%2C01304%2C01331%2C01332%2C01333%2C01334%2C01337%2C01343%2C01345%2C01346%2C01347%2C01361%2C01362%2C01363%2C01364%2C01367%2C01370%2C01371%2C01391%2C01392%2C01393%2C01394%2C01395%2C01396%2C01397%2C01398%2C01399%2C01400%2C01401%2C01402%2C01403%2C01404%2C01405%2C01406%2C01407%2C01408%2C01409%2C01423%2C01424%2C01425%2C01427%2C01428%2C01429%2C01430%2C01431%2C01432%2C01433%2C01434%2C01436%2C01437%2C01438%2C01452%2C01453%2C01454%2C01455&cdCat01=G1401&appId=&lang=J&statsDataId=0000020207&metaGetFlg=Y&cntGetFlg=N&explanationGetFlg=Y&annotationGetFlg=Y&sectionHeaderFlg=1&replaceSpChars=0",
  query = list(
    appId = appId, 
    statsDataId = "0000020207")
)
result <- content(stats_library)
str(result, max.level = 4, list.len = 4)
library <- estat_getStatsData(
  appId = appId,
  statsDataId = "0000020207", 
  cdCat01 = list("G1401")
) %>%
  select(-1,
         -2,
         -3,
         -8,
         -9,
         -11) %>%
  mutate(time_code = str_sub(time_code, 1, 4),
         time_code = as.integer(time_code),
         value = as.integer(value))
  colnames(library) = c("subject","area_code","region","time","value")
library = library %>%
  dplyr::select(region, area_code, time, everything())
library = library %>%
  pivot_wider(names_from = "subject",
              values_from = value)
colnames(library)[4] = "G1401_libraries"
head(library)
# A tibble: 6 x 4
  region        area_code  time G1401_libraries
  <chr>         <chr>     <int>           <int>
1 北海道 札幌市 01100      1995              10
2 北海道 札幌市 01100      1996              10
3 北海道 札幌市 01100      1997              10
4 北海道 札幌市 01100      1999              10
5 北海道 札幌市 01100      2002              17
6 北海道 札幌市 01100      2005              11

1.2.3 Hospital

stats_hospital <- GET(
  url = "https://api.e-stat.go.jp/rest/3.0/app/getStatsData?cdArea=01100%2C01101%2C01102%2C01103%2C01104%2C01105%2C01106%2C01107%2C01108%2C01109%2C01110%2C01202%2C01203%2C01204%2C01205%2C01206%2C01207%2C01208%2C01209%2C01210%2C01211%2C01212%2C01213%2C01214%2C01215%2C01216%2C01217%2C01218%2C01219%2C01220%2C01221%2C01222%2C01223%2C01224%2C01225%2C01226%2C01227%2C01228%2C01229%2C01230%2C01231%2C01233%2C01234%2C01235%2C01236%2C01303%2C01304%2C01331%2C01332%2C01333%2C01334%2C01337%2C01343%2C01345%2C01346%2C01347%2C01361%2C01362%2C01363%2C01364%2C01367%2C01370%2C01371%2C01391%2C01392%2C01393%2C01394%2C01395%2C01396%2C01397%2C01398%2C01399%2C01400%2C01401%2C01402%2C01403%2C01404%2C01405%2C01406%2C01407%2C01408%2C01409%2C01423%2C01424%2C01425%2C01427%2C01428%2C01429%2C01430%2C01431%2C01432%2C01433%2C01434%2C01436%2C01437%2C01438%2C01452%2C01453%2C01454%2C01455&cdCat01=I5101%2CI5102&appId=&lang=J&statsDataId=0000020209&metaGetFlg=Y&cntGetFlg=N&explanationGetFlg=Y&annotationGetFlg=Y&sectionHeaderFlg=1&replaceSpChars=0",
  query = list(
    appId = appId, 
    statsDataId = "0000020209")
)
result <- content(stats_hospital)
str(result, max.level = 4, list.len = 4)
hospital <- estat_getStatsData(
  appId = appId,
  statsDataId = "0000020209", 
  cdCat01 = list("I5101",
                 "I5102")
) %>%
  select(-1,
         -2,
         -3,
         -8,
         -9,
         -11) %>%
  mutate(time_code = str_sub(time_code, 1, 4),
         time_code = as.integer(time_code),
         value = as.integer(value))
  colnames(hospital) = c("subject","area_code","region","time","value")
hospital = hospital %>%
  dplyr::select(region, area_code, time, everything())
hospital = hospital %>%
  pivot_wider(names_from = "subject",
              values_from = value)
colnames(hospital)[4:5] = c("I5101_hospitals","I5102_generalclinics")
head(hospital)

1.2.4 Eonomic Entity

stats_economic <- GET(
  url = "https://api.e-stat.go.jp/rest/3.0/app/getStatsData?cdArea=01100%2C01101%2C01102%2C01103%2C01104%2C01105%2C01106%2C01107%2C01108%2C01109%2C01110%2C01202%2C01203%2C01204%2C01205%2C01206%2C01207%2C01208%2C01209%2C01210%2C01211%2C01212%2C01213%2C01214%2C01215%2C01216%2C01217%2C01218%2C01219%2C01220%2C01221%2C01222%2C01223%2C01224%2C01225%2C01226%2C01227%2C01228%2C01229%2C01230%2C01231%2C01233%2C01234%2C01235%2C01236%2C01303%2C01304%2C01331%2C01332%2C01333%2C01334%2C01337%2C01343%2C01345%2C01346%2C01347%2C01361%2C01362%2C01363%2C01364%2C01367%2C01370%2C01371%2C01391%2C01392%2C01393%2C01394%2C01395%2C01396%2C01397%2C01398%2C01399%2C01400%2C01401%2C01402%2C01403%2C01404%2C01405%2C01406%2C01407%2C01408%2C01409%2C01423%2C01424%2C01425%2C01427%2C01428%2C01429%2C01430%2C01431%2C01432%2C01433%2C01434%2C01436%2C01437%2C01438%2C01452%2C01453%2C01454%2C01455&cdCat01=C210831%2CC210835%2CC210836%2CC210837%2CC210838%2CC210839%2CC210840%2CC210842%2CC210843%2CC210844%2CC210845%2CC210846%2CC210847%2CC210848%2CC210849%2CC210850%2CC210851%2CC210852&appId=&lang=J&statsDataId=0000020203&metaGetFlg=Y&cntGetFlg=N&explanationGetFlg=Y&annotationGetFlg=Y&sectionHeaderFlg=1&replaceSpChars=0",
  query = list(
    appId = appId, 
    statsDataId = "0000020203")
)
result <- content(stats_economic)
str(result, max.level = 4, list.len = 4)
economic <- estat_getStatsData(
  appId = appId,
  statsDataId = "0000020203", 
  cdCat01 = list("C210832",
                 "C210833",
                 "C210835",
                 "C210836",
                 "C210837",
                 "C210838",
                 "C210839",
                 "C210840",
                 "C210842",
                 "C210843",
                 "C210844",
                 "C210845",
                 "C210846",
                 "C210847",
                 "C210848",
                 "C210849",
                 "C210850",
                 "C210851",
                 "C210852")
) %>%
  select(-1,
        -2,
        -3,
        -8,
        -9,
        -11) %>%
  mutate(time_code = str_sub(time_code, 1, 4),
         time_code = as.integer(time_code),
         value = as.integer(value)) 
 colnames(economic) = c("subject","area_code","region","time","value")
 economic = economic %>%
   dplyr::select(region, area_code, time, everything())
 economic = economic %>%
 pivot_wider(names_from = "subject",
             values_from = value)
 colnames(economic)[4:22] = c("C210832_agriculture_forestry",
                              "C210833_fishing",
                              "C210835_mining_quarrying_gravel_extraction",
                              "C210836_construction",
                              "C210837_manufacturing",
                              "C210838_electricity_gas_heat_supply_water",
                              "C210839_information_and_communication",
                              "C210840_transportation_postal",
                              "C210842_wholesale_trade",
                              "C210843_retail_trade",
                              "C210844_financial",
                              "C210845_real_estate_goods_rental",
                              "C210846_academic_professional_services",
                              "C210847_lodging_food_beverage",
                              "C210848_life_related_service_entertainment",
                              "C210849_education",
                              "C210850_medical_care_welfare",
                              "C210851_complex_service",
                              "C210852_others_service")
 head(economic)
# A tibble: 6 x 22
  region               area_code  time C210832_agriculture_for~1 C210833_fishing
  <chr>                <chr>     <int>                     <int>           <int>
1 北海道 札幌市        01100      2011                        82               3
2 北海道 札幌市        01100      2014                        96               2
3 北海道 札幌市        01100      2016                        93               2
4 北海道 札幌市 中央区 01101      2011                        23               3
5 北海道 札幌市 中央区 01101      2014                        29               2
6 北海道 札幌市 中央区 01101      2016                        28               2
# i abbreviated name: 1: C210832_agriculture_forestry
# i 17 more variables: C210835_mining_quarrying_gravel_extraction <int>,
#   C210836_construction <int>, C210837_manufacturing <int>,
#   C210838_electricity_gas_heat_supply_water <int>,
#   C210839_information_and_communication <int>,
#   C210840_transportation_postal <int>, C210842_wholesale_trade <int>,
#   C210843_retail_trade <int>, C210844_financial <int>, ...

1.3 Combining each data

diversity = full_join(school, hospital, by = c("region","area_code","time")) %>%
  full_join(library, by = c("region","area_code","time")) %>%
  full_join(economic, by = c("region","area_code","time")) %>%
  mutate(sum = select(., c(4:29)) %>% rowSums(na.rm = TRUE), .before = 4)
head(diversity)
# A tibble: 6 x 30
  region        area_code  time   sum E1101_kindergartens E2101_elementaryscho~1
  <chr>         <chr>     <int> <dbl>               <int>                  <int>
1 北海道 札幌市 01100      1980  1340                 120                    160
2 北海道 札幌市 01100      1981  1377                 126                    164
3 北海道 札幌市 01100      1982  1397                 130                    171
4 北海道 札幌市 01100      1983   434                 134                    174
5 北海道 札幌市 01100      1984  1434                 137                    178
6 北海道 札幌市 01100      1985  1459                 139                    182
# i abbreviated name: 1: E2101_elementaryschools
# i 24 more variables: E3101_juniorhighschools <int>, E4101_highschools <int>,
#   I5101_hospitals <int>, I5102_generalclinics <int>, G1401_libraries <int>,
#   C210832_agriculture_forestry <int>, C210833_fishing <int>,
#   C210835_mining_quarrying_gravel_extraction <int>,
#   C210836_construction <int>, C210837_manufacturing <int>,
#   C210838_electricity_gas_heat_supply_water <int>, ...

1.4 Processing data

all_city = diversity %>%
  mutate(across(starts_with("E"), ~./sum, .names = "probability_{.col}")) %>%
  mutate(across(starts_with("I"), ~./sum, .names = "probability_{.col}")) %>%
  mutate(across(starts_with("G"), ~./sum, .names = "probability_{.col}")) %>%
  mutate(across(starts_with("C"), ~./sum, .names = "probability_{.col}")) %>%
  mutate(across(starts_with("probability"), log, .names = "log_{.col}")) %>%
  mutate(multiply_E1101_kindergartens = probability_E1101_kindergartens * log_probability_E1101_kindergartens) %>%
  mutate(multiply_E2101_elementaryschools = probability_E2101_elementaryschools * log_probability_E2101_elementaryschools) %>%
  mutate(multiply_E3101_juniorhighschools = probability_E3101_juniorhighschools * log_probability_E3101_juniorhighschools) %>%
  mutate(multiply_E4101_highschools = probability_E4101_highschools * log_probability_E4101_highschools) %>%
  mutate(multiply_G1401_libraries = probability_G1401_libraries * log_probability_G1401_libraries) %>%
  mutate(multiply_I5101_hospitals = probability_I5101_hospitals * log_probability_I5101_hospitals) %>%
  mutate(multiply_I5102_generalclinics = probability_I5102_generalclinics * log_probability_I5102_generalclinics) %>%
  mutate(multiply_C210832_agriculture_forestry = probability_C210832_agriculture_forestry * log_probability_C210832_agriculture_forestry) %>%
  mutate(multiply_C210833_fishing = probability_C210833_fishing * log_probability_C210833_fishing) %>%
  mutate(multiply_C210835_mining_quarrying_gravel_extraction = probability_C210835_mining_quarrying_gravel_extraction * log_probability_C210835_mining_quarrying_gravel_extraction) %>%
  mutate(multiply_C210836_construction = probability_C210836_construction * log_probability_C210836_construction) %>%
  mutate(multiply_C210837_manufacturing = probability_C210837_manufacturing * log_probability_C210837_manufacturing) %>%
  mutate(multiply_C210838_electricity_gas_heat_supply_water = probability_C210838_electricity_gas_heat_supply_water * log_probability_C210838_electricity_gas_heat_supply_water) %>%
  mutate(multiply_C210839_information_and_communication = probability_C210839_information_and_communication * log_probability_C210839_information_and_communication) %>%
  mutate(multiply_C210840_transportation_postal = probability_C210840_transportation_postal * log_probability_C210840_transportation_postal) %>%
  mutate(multiply_C210842_wholesale_trade = probability_C210842_wholesale_trade * log_probability_C210842_wholesale_trade) %>%
  mutate(multiply_C210843_retail_trade = probability_C210843_retail_trade * log_probability_C210843_retail_trade) %>%
  mutate(multiply_C210844_financial = probability_C210844_financial * log_probability_C210844_financial) %>%
  mutate(multiply_C210845_real_estate_goods_rental = probability_C210845_real_estate_goods_rental * log_probability_C210845_real_estate_goods_rental) %>%
  mutate(multiply_C210846_academic_professional_services = probability_C210846_academic_professional_services * log_probability_C210846_academic_professional_services) %>%
  mutate(multiply_C210847_lodging_food_beverage = probability_C210847_lodging_food_beverage * log_probability_C210847_lodging_food_beverage) %>%
  mutate(multiply_C210848_life_related_service_entertainment = probability_C210848_life_related_service_entertainment * log_probability_C210848_life_related_service_entertainment) %>%
  mutate(multiply_C210849_education = probability_C210849_education * log_probability_C210849_education) %>%
  mutate(multiply_C210850_medical_care_welfare = probability_C210850_medical_care_welfare * log_probability_C210850_medical_care_welfare) %>%
  mutate(multiply_C210851_complex_service = probability_C210851_complex_service * log_probability_C210851_complex_service) %>%
  mutate(multiply_C210852_others_service = probability_C210852_others_service * log_probability_C210852_others_service) %>%
  mutate(sum_log = -rowSums(across(starts_with("multiply")), na.rm = TRUE), .before = 5)
head(all_city)
# A tibble: 6 x 109
  region        area_code  time   sum sum_log E1101_kindergartens
  <chr>         <chr>     <int> <dbl>   <dbl>               <int>
1 北海道 札幌市 01100      1980  1340   0.978                 120
2 北海道 札幌市 01100      1981  1377   0.979                 126
3 北海道 札幌市 01100      1982  1397   0.990                 130
4 北海道 札幌市 01100      1983   434   1.28                  134
5 北海道 札幌市 01100      1984  1434   1.02                  137
6 北海道 札幌市 01100      1985  1459   1.02                  139
# i 103 more variables: E2101_elementaryschools <int>,
#   E3101_juniorhighschools <int>, E4101_highschools <int>,
#   I5101_hospitals <int>, I5102_generalclinics <int>, G1401_libraries <int>,
#   C210832_agriculture_forestry <int>, C210833_fishing <int>,
#   C210835_mining_quarrying_gravel_extraction <int>,
#   C210836_construction <int>, C210837_manufacturing <int>,
#   C210838_electricity_gas_heat_supply_water <int>, ...

1.5 Descriptive statistics

skim(all_city)
Warning: There was 1 warning in `dplyr::summarize()`.
i In argument: `dplyr::across(tidyselect::any_of(variable_names),
  mangled_skimmers$funs)`.
i In group 0: .
Caused by warning:
! There were 26 warnings in `dplyr::summarize()`.
The first warning was:
i In argument: `dplyr::across(tidyselect::any_of(variable_names),
  mangled_skimmers$funs)`.
Caused by warning in `inline_hist()`:
! Variable contains Inf or -Inf value(s) that were converted to NA.
i Run `dplyr::last_dplyr_warnings()` to see the 25 remaining warnings.
Data summary
Name all_city
Number of rows 80427
Number of columns 109
_______________________
Column type frequency:
character 2
numeric 107
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
region 0 1 6 14 0 1917 0
area_code 0 1 5 5 0 1917 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
time 0 1.00 2000.52 12.12 1980.00 1990.00 2001.00 2011.00 2021.00 ▇▇▇▇▇
sum 0 1.00 359.53 4005.99 0.00 14.00 38.00 110.00 533906.00 ▇▁▁▁▁
sum_log 0 1.00 1.30 0.41 0.00 1.11 1.27 1.42 2.74 ▁▂▇▁▁
E1101_kindergartens 2270 0.97 8.83 25.32 0.00 1.00 3.00 10.00 1012.00 ▇▁▁▁▁
E2101_elementaryschools 1599 0.98 14.12 28.97 0.00 4.00 8.00 16.00 978.00 ▇▁▁▁▁
E3101_juniorhighschools 1728 0.98 6.79 16.38 0.00 2.00 4.00 8.00 590.00 ▇▁▁▁▁
E4101_highschools 2519 0.97 3.36 9.44 0.00 1.00 1.00 4.00 343.00 ▇▁▁▁▁
I5101_hospitals 34881 0.57 5.69 15.74 0.00 1.00 2.00 6.00 468.00 ▇▁▁▁▁
I5102_generalclinics 6703 0.92 62.86 257.44 0.00 5.00 17.00 53.00 10720.00 ▇▁▁▁▁
G1401_libraries 62064 0.23 1.78 5.71 0.00 0.00 1.00 2.00 239.00 ▇▁▁▁▁
C210832_agriculture_forestry 74689 0.07 15.68 20.71 0.00 4.00 9.00 19.00 258.00 ▇▁▁▁▁
C210833_fishing 74689 0.07 1.87 5.41 0.00 0.00 0.00 1.00 83.00 ▇▁▁▁▁
C210835_mining_quarrying_gravel_extraction 74689 0.07 1.15 2.74 0.00 0.00 0.00 1.00 84.00 ▇▁▁▁▁
C210836_construction 74689 0.07 331.43 904.71 0.00 55.00 149.00 356.00 29856.00 ▇▁▁▁▁
C210837_manufacturing 74689 0.07 315.06 1153.92 0.00 38.00 117.00 307.00 42370.00 ▇▁▁▁▁
C210838_electricity_gas_heat_supply_water 74689 0.07 2.81 8.95 0.00 0.00 1.00 3.00 328.00 ▇▁▁▁▁
C210839_information_and_communication 74689 0.07 55.30 504.55 0.00 1.00 4.50 20.00 20413.00 ▇▁▁▁▁
C210840_transportation_postal 74689 0.07 91.90 375.25 0.00 11.00 31.00 80.00 14382.00 ▇▁▁▁▁
C210842_wholesale_trade 74689 0.07 277.18 1416.60 0.00 15.00 56.00 184.75 50195.00 ▇▁▁▁▁
C210843_retail_trade 74689 0.07 675.71 2177.05 0.00 92.00 271.50 670.00 76609.00 ▇▁▁▁▁
C210844_financial 74689 0.07 60.53 258.05 0.00 4.00 15.00 47.00 9540.00 ▇▁▁▁▁
C210845_real_estate_goods_rental 74689 0.07 270.02 1289.30 0.00 10.00 54.00 211.00 49995.00 ▇▁▁▁▁
C210846_academic_professional_services 74689 0.07 168.05 964.25 0.00 8.00 33.00 109.00 36882.00 ▇▁▁▁▁
C210847_lodging_food_beverage 74689 0.07 494.59 2029.20 0.00 47.00 152.00 437.00 74387.00 ▇▁▁▁▁
C210848_life_related_service_entertainment 74689 0.07 318.58 1020.94 0.00 39.00 121.50 320.00 36030.00 ▇▁▁▁▁
C210849_education 74689 0.07 112.52 371.05 0.00 8.00 33.00 113.00 12767.00 ▇▁▁▁▁
C210850_medical_care_welfare 74689 0.07 275.49 974.26 0.00 26.00 86.00 264.00 35165.00 ▇▁▁▁▁
C210851_complex_service 74689 0.07 20.71 41.02 0.00 5.00 12.00 23.00 1261.00 ▇▁▁▁▁
C210852_others_service 74689 0.07 239.49 883.88 0.00 32.00 89.00 213.00 32547.00 ▇▁▁▁▁
probability_E1101_kindergartens 2286 0.97 0.09 0.09 0.00 0.02 0.08 0.13 1.00 ▇▁▁▁▁
probability_E2101_elementaryschools 1615 0.98 0.24 0.15 0.00 0.13 0.21 0.33 1.00 ▇▆▂▁▁
probability_E3101_juniorhighschools 1744 0.98 0.11 0.08 0.00 0.06 0.09 0.14 1.00 ▇▁▁▁▁
probability_E4101_highschools 2535 0.97 0.04 0.04 0.00 0.00 0.04 0.06 1.00 ▇▁▁▁▁
probability_I5101_hospitals 34881 0.57 0.05 0.04 0.00 0.00 0.04 0.07 0.44 ▇▁▁▁▁
probability_I5102_generalclinics 6703 0.92 0.45 0.20 0.00 0.33 0.49 0.60 1.00 ▂▅▇▅▁
probability_G1401_libraries 62064 0.23 0.02 0.04 0.00 0.00 0.01 0.03 1.00 ▇▁▁▁▁
probability_C210832_agriculture_forestry 74689 0.07 0.01 0.02 0.00 0.00 0.01 0.02 0.29 ▇▁▁▁▁
probability_C210833_fishing 74689 0.07 0.00 0.01 0.00 0.00 0.00 0.00 0.21 ▇▁▁▁▁
probability_C210835_mining_quarrying_gravel_extraction 74689 0.07 0.00 0.00 0.00 0.00 0.00 0.00 0.03 ▇▁▁▁▁
probability_C210836_construction 74689 0.07 0.11 0.04 0.00 0.09 0.11 0.13 0.34 ▁▇▂▁▁
probability_C210837_manufacturing 74689 0.07 0.10 0.05 0.00 0.06 0.08 0.12 0.44 ▇▆▁▁▁
probability_C210838_electricity_gas_heat_supply_water 74689 0.07 0.00 0.00 0.00 0.00 0.00 0.00 0.06 ▇▁▁▁▁
probability_C210839_information_and_communication 74689 0.07 0.01 0.01 0.00 0.00 0.00 0.01 0.09 ▇▁▁▁▁
probability_C210840_transportation_postal 74689 0.07 0.03 0.02 0.00 0.02 0.02 0.03 0.30 ▇▁▁▁▁
probability_C210842_wholesale_trade 74689 0.07 0.05 0.03 0.00 0.03 0.04 0.06 0.24 ▇▅▁▁▁
probability_C210843_retail_trade 74689 0.07 0.20 0.04 0.00 0.17 0.20 0.22 0.40 ▁▂▇▁▁
probability_C210844_financial 74689 0.07 0.01 0.01 0.00 0.01 0.01 0.02 0.05 ▅▇▂▁▁
probability_C210845_real_estate_goods_rental 74689 0.07 0.05 0.03 0.00 0.02 0.04 0.07 0.22 ▇▅▁▁▁
probability_C210846_academic_professional_services 74689 0.07 0.03 0.01 0.00 0.02 0.03 0.03 0.16 ▇▃▁▁▁
probability_C210847_lodging_food_beverage 74689 0.07 0.12 0.06 0.00 0.09 0.11 0.14 0.70 ▇▂▁▁▁
probability_C210848_life_related_service_entertainment 74689 0.07 0.09 0.02 0.00 0.08 0.09 0.10 0.25 ▁▇▂▁▁
probability_C210849_education 74689 0.07 0.03 0.01 0.00 0.02 0.02 0.03 0.08 ▃▇▃▁▁
probability_C210850_medical_care_welfare 74689 0.07 0.07 0.02 0.00 0.05 0.07 0.08 0.17 ▁▇▇▁▁
probability_C210851_complex_service 74689 0.07 0.01 0.01 0.00 0.00 0.01 0.02 0.12 ▇▁▁▁▁
probability_C210852_others_service 74689 0.07 0.07 0.02 0.00 0.05 0.07 0.08 0.19 ▁▇▂▁▁
log_probability_E1101_kindergartens 2286 0.97 -Inf NaN -Inf -3.78 -2.52 -2.01 0.00 ▁▁▁▇▂
log_probability_E2101_elementaryschools 1615 0.98 -Inf NaN -Inf -2.03 -1.55 -1.12 0.00 ▁▁▁▅▇
log_probability_E3101_juniorhighschools 1744 0.98 -Inf NaN -Inf -2.80 -2.40 -1.95 0.00 ▁▁▁▇▂
log_probability_E4101_highschools 2535 0.97 -Inf NaN -Inf -6.55 -3.35 -2.89 0.00 ▁▁▁▇▁
log_probability_I5101_hospitals 34881 0.57 -Inf NaN -Inf -6.66 -3.14 -2.67 -0.81 ▁▁▁▇▂
log_probability_I5102_generalclinics 6703 0.92 -Inf NaN -Inf -1.10 -0.72 -0.51 0.00 ▁▁▁▁▇
log_probability_G1401_libraries 62064 0.23 -Inf NaN -Inf -Inf -4.32 -3.37 0.00 ▁▁▃▇▁
log_probability_C210832_agriculture_forestry 74689 0.07 -Inf NaN -Inf -6.12 -4.94 -4.09 -1.23 ▁▃▇▇▁
log_probability_C210833_fishing 74689 0.07 -Inf NaN -Inf -Inf -Inf -7.11 -1.56 ▁▃▇▅▁
log_probability_C210835_mining_quarrying_gravel_extraction 74689 0.07 -Inf NaN -Inf -Inf -Inf -7.12 -3.38 ▁▂▇▇▁
log_probability_C210836_construction 74689 0.07 -Inf NaN -Inf -2.44 -2.24 -2.01 -1.08 ▁▁▇▇▁
log_probability_C210837_manufacturing 74689 0.07 -Inf NaN -Inf -2.84 -2.48 -2.11 -0.81 ▁▂▇▇▁
log_probability_C210838_electricity_gas_heat_supply_water 74689 0.07 -Inf NaN -Inf -Inf -7.52 -6.60 -2.89 ▁▇▆▂▁
log_probability_C210839_information_and_communication 74689 0.07 -Inf NaN -Inf -6.45 -5.55 -5.02 -2.41 ▁▅▇▂▁
log_probability_C210840_transportation_postal 74689 0.07 -Inf NaN -Inf -4.10 -3.80 -3.50 -1.21 ▁▃▇▁▁
log_probability_C210842_wholesale_trade 74689 0.07 -Inf NaN -Inf -3.47 -3.15 -2.87 -1.42 ▁▁▅▇▁
log_probability_C210843_retail_trade 74689 0.07 -Inf NaN -Inf -1.76 -1.63 -1.52 -0.91 ▁▁▁▇▁
log_probability_C210844_financial 74689 0.07 -Inf NaN -Inf -4.75 -4.45 -4.19 -3.06 ▁▁▇▇▁
log_probability_C210845_real_estate_goods_rental 74689 0.07 -Inf NaN -Inf -3.88 -3.24 -2.71 -1.49 ▁▁▃▇▂
log_probability_C210846_academic_professional_services 74689 0.07 -Inf NaN -Inf -4.02 -3.66 -3.40 -1.84 ▁▁▇▇▁
log_probability_C210847_lodging_food_beverage 74689 0.07 -Inf NaN -Inf -2.38 -2.17 -1.99 -0.36 ▁▁▇▂▁
log_probability_C210848_life_related_service_entertainment 74689 0.07 -Inf NaN -Inf -2.58 -2.43 -2.32 -1.39 ▁▁▂▇▁
log_probability_C210849_education 74689 0.07 -Inf NaN -Inf -4.10 -3.71 -3.42 -2.50 ▁▁▃▇▂
log_probability_C210850_medical_care_welfare 74689 0.07 -Inf NaN -Inf -2.97 -2.73 -2.53 -1.79 ▁▁▁▇▃
log_probability_C210851_complex_service 74689 0.07 -Inf NaN -Inf -5.32 -4.74 -4.20 -2.08 ▁▇▇▃▁
log_probability_C210852_others_service 74689 0.07 -Inf NaN -Inf -2.90 -2.72 -2.56 -1.65 ▁▁▁▇▁
multiply_E1101_kindergartens 16353 0.80 -0.22 0.09 -0.37 -0.28 -0.23 -0.17 0.00 ▆▇▇▂▂
multiply_E2101_elementaryschools 1659 0.98 -0.29 0.09 -0.37 -0.36 -0.32 -0.26 0.00 ▇▃▁▁▁
multiply_E3101_juniorhighschools 2098 0.97 -0.22 0.09 -0.37 -0.28 -0.22 -0.17 0.00 ▅▆▇▂▂
multiply_E4101_highschools 18968 0.76 -0.14 0.06 -0.37 -0.17 -0.13 -0.10 0.00 ▁▂▅▇▂
multiply_G1401_libraries 67061 0.17 -0.10 0.07 -0.37 -0.14 -0.09 -0.05 0.00 ▁▁▃▇▇
multiply_I5101_hospitals 44929 0.44 -0.15 0.07 -0.37 -0.20 -0.16 -0.12 0.00 ▁▂▇▆▃
multiply_I5102_generalclinics 7011 0.91 -0.30 0.08 -0.37 -0.36 -0.33 -0.28 0.00 ▇▂▁▁▁
multiply_C210832_agriculture_forestry 74956 0.07 -0.05 0.05 -0.36 -0.07 -0.04 -0.02 0.00 ▁▁▁▂▇
multiply_C210833_fishing 78180 0.03 -0.02 0.03 -0.33 -0.03 -0.01 0.00 0.00 ▁▁▁▁▇
multiply_C210835_mining_quarrying_gravel_extraction 77958 0.03 -0.01 0.01 -0.12 -0.01 -0.01 0.00 0.00 ▁▁▁▁▇
multiply_C210836_construction 74702 0.07 -0.24 0.04 -0.37 -0.27 -0.24 -0.21 -0.08 ▁▆▇▂▁
multiply_C210837_manufacturing 74702 0.07 -0.21 0.06 -0.37 -0.26 -0.21 -0.17 -0.04 ▂▅▇▅▁
multiply_C210838_electricity_gas_heat_supply_water 76847 0.04 -0.01 0.01 -0.16 -0.01 -0.01 0.00 0.00 ▁▁▁▁▇
multiply_C210839_information_and_communication 75834 0.06 -0.03 0.02 -0.22 -0.04 -0.03 -0.02 0.00 ▁▁▁▁▇
multiply_C210840_transportation_postal 74747 0.07 -0.09 0.04 -0.36 -0.11 -0.09 -0.07 -0.02 ▁▁▁▇▇
multiply_C210842_wholesale_trade 74794 0.07 -0.14 0.05 -0.34 -0.16 -0.14 -0.11 -0.01 ▁▁▆▇▁
multiply_C210843_retail_trade 74695 0.07 -0.32 0.02 -0.37 -0.33 -0.32 -0.30 -0.12 ▇▇▁▁▁
multiply_C210844_financial 74921 0.07 -0.05 0.02 -0.14 -0.06 -0.05 -0.04 -0.01 ▁▁▃▇▂
multiply_C210845_real_estate_goods_rental 74940 0.07 -0.14 0.06 -0.34 -0.18 -0.13 -0.09 -0.01 ▁▃▇▇▃
multiply_C210846_academic_professional_services 74893 0.07 -0.10 0.03 -0.29 -0.11 -0.10 -0.08 -0.01 ▁▁▂▇▂
multiply_C210847_lodging_food_beverage 74698 0.07 -0.25 0.04 -0.37 -0.27 -0.25 -0.22 -0.07 ▂▇▇▂▁
multiply_C210848_life_related_service_entertainment 74713 0.07 -0.21 0.03 -0.35 -0.23 -0.21 -0.20 -0.05 ▁▂▇▁▁
multiply_C210849_education 74962 0.07 -0.09 0.03 -0.20 -0.11 -0.09 -0.07 -0.02 ▁▂▇▇▂
multiply_C210850_medical_care_welfare 74722 0.07 -0.18 0.04 -0.30 -0.20 -0.18 -0.15 -0.02 ▁▆▇▂▁
multiply_C210851_complex_service 74698 0.07 -0.05 0.03 -0.26 -0.06 -0.04 -0.03 -0.01 ▁▁▁▃▇
multiply_C210852_others_service 74713 0.07 -0.18 0.03 -0.32 -0.20 -0.18 -0.16 -0.03 ▁▂▇▂▁
get_summary_stats(all_city)
# A tibble: 107 x 13
   variable     n   min    max median     q1     q3    iqr    mad   mean      sd
   <fct>    <dbl> <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>  <dbl>   <dbl>
 1 time     80427  1980 2.02e3 2.00e3 1.99e3 2.01e3 21     14.8   2.00e3 1.21e+1
 2 sum      80427     0 5.34e5 3.8 e1 1.4 e1 1.1 e2 96     43.0   3.60e2 4.01e+3
 3 sum_log  80427     0 2.74e0 1.27e0 1.11e0 1.42e0  0.304  0.225 1.30e0 4.15e-1
 4 E1101_k~ 78157     0 1.01e3 3   e0 1   e0 1   e1  9      4.45  8.83e0 2.53e+1
 5 E2101_e~ 78828     0 9.78e2 8   e0 4   e0 1.6 e1 12      7.41  1.41e1 2.90e+1
 6 E3101_j~ 78699     0 5.9 e2 4   e0 2   e0 8   e0  6      4.45  6.79e0 1.64e+1
 7 E4101_h~ 77908     0 3.43e2 1   e0 1   e0 4   e0  3      1.48  3.36e0 9.44e+0
 8 I5101_h~ 45546     0 4.68e2 2   e0 1   e0 6   e0  5      2.96  5.68e0 1.57e+1
 9 I5102_g~ 73724     0 1.07e4 1.7 e1 5   e0 5.3 e1 48     20.8   6.29e1 2.57e+2
10 G1401_l~ 18363     0 2.39e2 1   e0 0      2   e0  2      1.48  1.78e0 5.71e+0
# i 97 more rows
# i 2 more variables: se <dbl>, ci <dbl>

1.6 Selecting areas

big_city = filter(all_city, area_code %in% c("13100","23100","27100","01100","04100","11100","12100","14100","14130","14150","15100","22100","22130","26100","27140","28100","33100","34100","40100","43100","40130"))
tokyo <- big_city %>% 
  filter(area_code %in% "13100")
sendai <- big_city %>% 
  filter(area_code %in% "04100")

1.7 Visualizing

1.7.1 All cities

hist(all_city$sum_log, main = "Histogram of diversity index", xlab = "diversity index")

ggplot(data = all_city,
       mapping = aes(x=time,
                     y=sum_log)) +
  geom_point() + 
  geom_smooth(method = "lm") +    
  scale_x_continuous(name = "time") +
  scale_y_continuous(name = "divercity index") +
  
  theme(axis.title.x = element_text(size = 12, hjust = 0.5), #font size and adjust
        axis.text.x = element_text(size = 12),
        axis.text.y = element_text(size = 12),
        axis.title.y=element_text(size=12, vjust = 0.8)
  ) 
`geom_smooth()` using formula = 'y ~ x'

1.7.2 Ordinance designed cities

hist(big_city$sum_log, main = "Histogram of diversity index", xlab = "diversity index")

ggplot(data = big_city,
       mapping = aes(x=region,
                     y=sum_log,
                     fill=region)) +
  geom_boxplot()

ggplot(data = big_city,
       mapping = aes(x=time,
                     y=sum_log)) +
  geom_point() + 
  geom_smooth(method = "lm") +    
  scale_x_continuous(name = "time") +
  scale_y_continuous(name = "divercity index")+
  ggtitle("Ordinance Designed Cities")+
  labs(caption = "bachelor thesis")+
  theme(axis.title.x = element_text(size = 12, hjust = 0.5), #font size and adjust
        axis.text.x = element_text(size = 12),
        axis.text.y = element_text(size = 12),
        axis.title.y=element_text(size=12, vjust = 0.8)
  ) 
`geom_smooth()` using formula = 'y ~ x'

1.7.3 Sendai

hist(sendai$sum_log, main = "Histogram of diversity index", xlab = "diversity index")

ggplot(data = sendai,
       mapping = aes(x=time,
                     y=sum_log)) +
  geom_point() + 
  geom_smooth(method = "lm") +    
  scale_x_continuous(name = "time") +
  scale_y_continuous(name = "divercity index") +
  ggtitle("Sendai")+
  labs(caption = "bachelor thesis")+
  theme(axis.title.x = element_text(size = 12, hjust = 0.5), #font size and adjust
        axis.text.x = element_text(size = 12),
        axis.text.y = element_text(size = 12),
        axis.title.y=element_text(size=12, vjust = 0.8)
  ) 
`geom_smooth()` using formula = 'y ~ x'

1.7.4 Tokyo

hist(tokyo$sum_log, main = "Histogram of diversity index", xlab = "diversity index")

ggplot(data = tokyo,
       mapping = aes(x=time,
                     y=sum_log)) +
  geom_point() + 
  geom_smooth(method = "lm") +    
  scale_x_continuous(name = "time") +
  scale_y_continuous(name = "divercity index") +
  ggtitle("Tokyo")+
  labs(caption = "bachelor thesis")+
  theme(axis.title.x = element_text(size = 12, hjust = 0.5), #font size and adjust
        axis.text.x = element_text(size = 12),
        axis.text.y = element_text(size = 12),
        axis.title.y=element_text(size=12, vjust = 0.8)
  ) 
`geom_smooth()` using formula = 'y ~ x'