Nations datasets Week 6 HW

World Fertility Rate Map

<https://en.wikipedia.org/wiki/Total_fertility_ratehttps://en.wikipedia.org/wiki/Total_fertility_rate>

[Source:: Wikipedia]

Set datasets

library(tidyverse)
library(ggfortify)
library(plotly)
library(ggplot2)
setwd("D:/Data 110/Week 6")
nation<- read_csv("nations.csv")
head(nation)
## # A tibble: 6 × 10
##   iso2c iso3c country  year gdp_percap population birth_rate neonat_mortal_rate
##   <chr> <chr> <chr>   <dbl>      <dbl>      <dbl>      <dbl>              <dbl>
## 1 AD    AND   Andorra  1996         NA      64291       10.9                2.8
## 2 AD    AND   Andorra  1994         NA      62707       10.9                3.2
## 3 AD    AND   Andorra  2003         NA      74783       10.3                2  
## 4 AD    AND   Andorra  1990         NA      54511       11.9                4.3
## 5 AD    AND   Andorra  2009         NA      85474        9.9                1.7
## 6 AD    AND   Andorra  2011         NA      82326       NA                  1.6
## # ℹ 2 more variables: region <chr>, income <chr>

Names of datasets

names(nation)
##  [1] "iso2c"              "iso3c"              "country"           
##  [4] "year"               "gdp_percap"         "population"        
##  [7] "birth_rate"         "neonat_mortal_rate" "region"            
## [10] "income"

Plot 1 - Point bar graph

Picked 4 countries: Singapore - The entire country is urbanized, Bhutan = Only one the carbon negative country in the world, Iceland - Limited world’s economic impact because unique geological location and isolated economy system., Afghanistan - USA established new government in late 2001 through Aug. 2021 (reason why no data before 2000)

library(RColorBrewer) 

filtered_country <- nation |>
  filter(country %in% c("Singapore", "Bhutan", "Iceland", "Afghanistan"))


plot1 <- ggplot(filtered_country, aes(x = year, y = birth_rate, color = country)) +
  geom_point(aes(size = gdp_percap, alpha = 0.3)) +  
  geom_line() +
  scale_color_brewer(palette = "Set1") +
  scale_size_continuous(name = "GDP per Capita") +
  theme_minimal() +
  labs(title = "Birth Rate, GDP per Capita, and Neonatal Mortality Rate \n by Country and Year",
       x = "Year",
       y = "Birth Rate") +
  labs(caption= "source nation") +
  guides(color = guide_legend(order = 1)) +
  guides(size = guide_legend(order = 2)) +
  guides(alpha = guide_legend(order = 3))

plot1
## Warning: Removed 12 rows containing missing values or values outside the scale range
## (`geom_point()`).

ggplotly(plot1)

Overall, the birth rate is on a downward trend. Afghanistan’s efforts to reorganize infrastructure and improve security under the new U.S.-led government can reflect the country’s growing affluence. Singapore’s GDP rapidly increased from 1996 to 1997 because the Singaporean government intervened in foreign exchange during the Asian currency crisis, stabilizing the Singapore dollar and leading to rapid economic growth. In Bhutan, energy development, particularly hydropower, the development of tourism, improved agricultural production, and economic reforms by the government have made the country prosperous. In Iceland, as mentioned above, the impact of the 2008 Lehman Shock has been minimized, and the economy has stabilized.

Plot 2 - Area map

If I compared birth rate regions based on the population, the graph makes no sense because of differences in the number of populations. Although this linear regression model would be more accurate if we used bootstrapping, I set the hypothesis 100 million population in each region. Therefore, my linear regression model is different from the actual birthrate.

grouped_nation <- nation |>
mutate(income_num = as.numeric(income)) |>
  group_by(region, year) |>
  summarise(population = sum(population, na.rm = TRUE),
            avg_birth_rate = mean(birth_rate, na.rm = TRUE) / population * 100000000,
            avg_income = mean(income_num, na.rm = TRUE)) 
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `income_num = as.numeric(income)`.
## Caused by warning:
## !  強制変換により NA が生成されました
## `summarise()` has grouped output by 'region'. You can override using the
## `.groups` argument.
plot2 <- ggplot(grouped_nation, aes(x = year, y = avg_birth_rate, fill = region)) +
  geom_area(alpha = 0.8) +  
  scale_fill_brewer(palette = "Set2") +  
  theme_minimal() +  
  labs(title = "Birth Rate per One 100 million population \n by Region",
       x = "Year",
       y = "Birth Rate") +  
  labs(caption = "Source nations") +
  guides(fill = guide_legend(order = 1))
plot2

ggplotly(plot2)

My comment is on the end of multiple regression liner model

Does income matter much role in fertility rate?

nation_2000 <- nation |>
  filter(year >= 2000)

multi_lm_model <- lm(birth_rate ~ income + neonat_mortal_rate + population + region + gdp_percap, data = nation_2000)
summary(multi_lm_model)
## 
## Call:
## lm(formula = birth_rate ~ income + neonat_mortal_rate + population + 
##     region + gdp_percap, data = nation_2000)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -13.6356  -2.4729  -0.1828   2.7599  13.9513 
## 
## Coefficients:
##                                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                       1.291e+01  5.225e-01  24.711  < 2e-16 ***
## incomeHigh income: OECD           1.674e+00  3.966e-01   4.220 2.52e-05 ***
## incomeLow income                  1.019e+01  5.306e-01  19.204  < 2e-16 ***
## incomeLower middle income         7.022e+00  4.667e-01  15.046  < 2e-16 ***
## incomeNot classified              4.702e+00  1.658e+00   2.835 0.004616 ** 
## incomeUpper middle income         1.419e+00  4.127e-01   3.438 0.000596 ***
## neonat_mortal_rate                3.100e-01  1.148e-02  27.014  < 2e-16 ***
## population                       -4.742e-09  6.326e-10  -7.496 8.93e-14 ***
## regionEurope & Central Asia      -5.249e+00  2.916e-01 -17.999  < 2e-16 ***
## regionLatin America & Caribbean   9.613e-02  3.100e-01   0.310 0.756488    
## regionMiddle East & North Africa  2.720e+00  3.437e-01   7.914 3.63e-15 ***
## regionNorth America              -3.143e+00  8.254e-01  -3.808 0.000143 ***
## regionSouth Asia                 -3.337e+00  4.720e-01  -7.071 1.96e-12 ***
## regionSub-Saharan Africa          7.054e+00  3.392e-01  20.798  < 2e-16 ***
## gdp_percap                        8.586e-06  8.217e-06   1.045 0.296150    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.155 on 2659 degrees of freedom
##   ( 491 個の観測値が欠損のため削除されました )
## Multiple R-squared:  0.867,  Adjusted R-squared:  0.8663 
## F-statistic:  1238 on 14 and 2659 DF,  p-value: < 2.2e-16

Although the overall birth rate is declining, the visualization graph illustrates the differences in birth rates by region. Regions with more so-called poverty regions have higher birth rates.

The multiple-linear regression model examines which income, population, neonate mortality rate, region, and GDP cap values correlate with the birth rate. The Liner model suggests that 86.63% of birth rate and income, particularly in the lower-income regions, are affected. On the other hand, as income increases, the birth rate decreases. Furthermore, GDP and population are also highly uncorrelated with fertility. The visualization graph clearly shows that areas of high poverty have a greater range of areas for this reason.

*The model provides a birth rate based on a population of 100 million population rather than absolute births. Values in the assessment may not directly correspond to the actual variety of births in each region.