library(WDI)
SP.DYN.LE00.FE.IN Doğumda beklenen yaşam süresi, kızlar (yıl) SP.DYN.LE00.MA.IN Doğumda beklenen yaşam süresi, erkek (yıl)
data <- WDI(indicator= c("SP.DYN.LE00.FE.IN","SP.DYN.LE00.MA.IN"))
2002
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data2002 <- data %>% filter(year==2002)
dataMA <- data %>% filter(country=="Morocco")
library(ggplot2)
ggplot(dataMA,aes(year,SP.DYN.LE00.FE.IN)) +geom_line()
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).
ggplot(dataMA,aes(year,SP.DYN.LE00.MA.IN)) +geom_line()
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).
model <- lm(SP.DYN.LE00.FE.IN ~ SP.DYN.LE00.MA.IN, data = dataMA)
summary(model)
##
## Call:
## lm(formula = SP.DYN.LE00.FE.IN ~ SP.DYN.LE00.MA.IN, data = dataMA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.39234 -0.11992 0.01109 0.08516 0.72457
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.686919 0.157944 -10.68 1.35e-15 ***
## SP.DYN.LE00.MA.IN 1.076834 0.002622 410.70 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1977 on 61 degrees of freedom
## (1 observation effacée parce que manquante)
## Multiple R-squared: 0.9996, Adjusted R-squared: 0.9996
## F-statistic: 1.687e+05 on 1 and 61 DF, p-value: < 2.2e-16