library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.4.3
## ── 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 4.0.0 ✔ 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
library(knitr)
library(lme4)
## Cargando paquete requerido: Matrix
##
## Adjuntando el paquete: 'Matrix'
##
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
library(sjPlot)
##
## Adjuntando el paquete: 'sjPlot'
##
## The following object is masked from 'package:ggplot2':
##
## set_theme
library(performance)
## Warning: package 'performance' was built under R version 4.4.3
library(lmerTest)
## Warning: package 'lmerTest' was built under R version 4.4.3
##
## Adjuntando el paquete: 'lmerTest'
##
## The following object is masked from 'package:lme4':
##
## lmer
##
## The following object is masked from 'package:stats':
##
## step
#library(rworldmap) # no es necesario
#library(countrycode) # no es necesario
library(knitr)
library(data.table)
## Warning: package 'data.table' was built under R version 4.4.3
##
## Adjuntando el paquete: 'data.table'
##
## The following objects are masked from 'package:lubridate':
##
## hour, isoweek, mday, minute, month, quarter, second, wday, week,
## yday, year
##
## The following objects are masked from 'package:dplyr':
##
## between, first, last
##
## The following object is masked from 'package:purrr':
##
## transpose
library(haven)
library(lme4)
library(geepack)
## Warning: package 'geepack' was built under R version 4.4.3
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.4.3
## corrplot 0.95 loaded
library(psych)
##
## Adjuntando el paquete: 'psych'
##
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(sjPlot)
library(broom.mixed)
## Warning: package 'broom.mixed' was built under R version 4.4.3
library(marginaleffects)
## Warning: package 'marginaleffects' was built under R version 4.4.3
library(stevemisc) # instalar si quieren pero es solo para gráficos no muy útiles
## Warning: package 'stevemisc' was built under R version 4.4.3
##
## Adjuntando el paquete: 'stevemisc'
##
## The following object is masked from 'package:lubridate':
##
## dst
##
## The following object is masked from 'package:dplyr':
##
## tbl_df
library(kableExtra)
## Warning: package 'kableExtra' was built under R version 4.4.3
##
## Adjuntando el paquete: 'kableExtra'
##
## The following object is masked from 'package:dplyr':
##
## group_rows
options(scipen=999, digits=2)
library(readr)
datos <- read_csv("C:/Users/Administrador/Downloads/THdatabasal.csv")
## Rows: 2679 Columns: 16
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): iso3, country, status, human.development.groups, continent
## dbl (11): year, alcohol, measles, polio, health.expenditure, diphtheria, hiv...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(datos)
str(datos)
## spc_tbl_ [2,679 × 16] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ iso3 : chr [1:2679] "AFG" "AFG" "AFG" "AFG" ...
## $ country : chr [1:2679] "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
## $ year : num [1:2679] 2000 2001 2002 2003 2004 ...
## $ status : chr [1:2679] "Developing" "Developing" "Developing" "Developing" ...
## $ human.development.groups: chr [1:2679] "Low" "Low" "Low" "Low" ...
## $ continent : chr [1:2679] "Asia" "Asia" "Asia" "Asia" ...
## $ alcohol : num [1:2679] 0.0147 0.0147 0.0147 0.0147 0.0147 ...
## $ measles : num [1:2679] 2443 2443 2443 2443 2443 ...
## $ polio : num [1:2679] 51.2 51.2 51.2 51.2 51.2 51.2 51.2 51.2 51.2 51.2 ...
## $ health.expenditure : num [1:2679] 8.26 8.26 8.26 8.26 8.26 ...
## $ diphtheria : num [1:2679] 51.5 51.5 51.5 51.5 51.5 ...
## $ hiv.aids : num [1:2679] 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 ...
## $ malnutrition : num [1:2679] 15.5 15.5 15.5 15.5 15.5 ...
## $ life_expectancy_avg : num [1:2679] 55.3 55.8 56.5 57.3 57.9 ...
## $ hepatitis.b_avg : num [1:2679] 40.6 40.6 40.6 40.6 40.6 ...
## $ year_c : num [1:2679] 0 1 2 3 4 5 6 7 8 9 ...
## - attr(*, "spec")=
## .. cols(
## .. iso3 = col_character(),
## .. country = col_character(),
## .. year = col_double(),
## .. status = col_character(),
## .. human.development.groups = col_character(),
## .. continent = col_character(),
## .. alcohol = col_double(),
## .. measles = col_double(),
## .. polio = col_double(),
## .. health.expenditure = col_double(),
## .. diphtheria = col_double(),
## .. hiv.aids = col_double(),
## .. malnutrition = col_double(),
## .. life_expectancy_avg = col_double(),
## .. hepatitis.b_avg = col_double(),
## .. year_c = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
datos1=datos
Hay que modelar la expectativa de vida en el tiempo con un modelo mixto que tenga en cuenta los clusters
# Gráfico A: Año como continuo
p1 <- ggplot(datos, aes(x = year, y = life_expectancy_avg)) +
geom_smooth(method = "lm", color = "blue") +
labs(title = "A: Expectativa de vida mundial", x = "Año", y = "Expectativa de Vida") +
theme_minimal()
p1
## `geom_smooth()` using formula = 'y ~ x'
# Gráfico B: Agrupado por continentes
p2 <- ggplot(datos, aes(x = year, y = life_expectancy_avg)) +
geom_smooth(method = "lm", color = "blue") +
labs(title = "B: Expectativa de vida por continente", x = "Año", y = "Expectativa de Vida") + facet_wrap(~continent) +
theme_minimal()
p2
## `geom_smooth()` using formula = 'y ~ x'
colSums(is.na(datos))
## iso3 country year
## 0 0 0
## status human.development.groups continent
## 0 1 0
## alcohol measles polio
## 0 0 0
## health.expenditure diphtheria hiv.aids
## 0 0 0
## malnutrition life_expectancy_avg hepatitis.b_avg
## 0 0 0
## year_c
## 0
#base long
# Base en formnato long
datos_long <- datos %>%
pivot_longer(
cols = starts_with("life_expectancy_avg"), # las columans que empiecen con
names_to = "PERIOD", # nueva columna a las que le voy a pasar el periodo de tiempo
names_prefix = "life_expectancy_avg", # El valor que le voy a asignar a PERIOD es el que sigue a este prefijo
values_to = "life_expectancy_avg" # valores de TAS
)
datos_long$PERIOD = datos_long$year_c
#paso a factor las chr
datos_long <- datos_long %>% mutate_if(is.character, as.factor)
###Pregunta 3: Modelo Nulo y Justificación del Anidamiento
#Ajusta un modelo nulo (solo con intercepto) para la variable life_expectancy_avg. Este modelo debe tener efectos aleatorios para continent y para country anidado en continent. La estructura en lmer para esto es (1 | continent/country).
#Calcula e interpreta el ICC para ambos niveles (continent y country). ¿Qué te dicen estos valores sobre la estructura de dependencia en tus datos?
#MODELO ALEATORIO NULO
mod_aleatorio_NULO <- lmer(life_expectancy_avg ~ (1 | continent/country), REML = T, data = datos_long)
tidy(mod_aleatorio_NULO)
## # A tibble: 4 × 8
## effect group term estimate std.error statistic df p.value
## <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 fixed <NA> (Inter… 69.6 3.13 22.3 4.07 2.12e-5
## 2 ran_pars country:continent sd__(I… 5.64 NA NA NA NA
## 3 ran_pars continent sd__(I… 6.91 NA NA NA NA
## 4 ran_pars Residual sd__Ob… 1.97 NA NA NA NA
tab_model(mod_aleatorio_NULO)
| life_expectancy_avg | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 69.57 | 63.44 – 75.71 | <0.001 |
| Random Effects | |||
| σ2 | 3.89 | ||
| τ00 country:continent | 31.76 | ||
| τ00 continent | 47.77 | ||
| ICC | 0.95 | ||
| N country | 184 | ||
| N continent | 5 | ||
| Observations | 2679 | ||
| Marginal R2 / Conditional R2 | 0.000 / 0.953 | ||
performance::icc(mod_aleatorio_NULO)
## # Intraclass Correlation Coefficient
##
## Adjusted ICC: 0.953
## Unadjusted ICC: 0.953
#modelo continente
#modelo country
Pregunta 4: Construcción y Comparación de Modelos Ahora construimos y comparamos modelos para predecir life_expectancy_avg. Los alumnos deben crear el mejor modelo posible.
Usa la función compare_performance() del paquete performance para comparar, por ejemplo, Modelo A y Modelo B. Presenta la tabla de resultados.
mod_mixto1 <- lmer(life_expectancy_avg ~ PERIOD + (1 | continent/country), REML = T, data = datos_long)
tab_model(mod_mixto1)
| life_expectancy_avg | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 67.01 | 60.88 – 73.13 | <0.001 |
| PERIOD | 0.35 | 0.34 – 0.36 | <0.001 |
| Random Effects | |||
| σ2 | 1.49 | ||
| τ00 country:continent | 32.62 | ||
| τ00 continent | 47.66 | ||
| ICC | 0.98 | ||
| N country | 184 | ||
| N continent | 5 | ||
| Observations | 2679 | ||
| Marginal R2 / Conditional R2 | 0.027 / 0.982 | ||
#la esperanza de vida aumenta 0.35 años por año. En este caso, el ICC es de 0.98
#lo cual indica que el 98% de la varianza de la esperanza de vida se relaciona con la pertenencia al país y al continente
#Modelo con status e interacción
mod_mixto2 <- lmer(life_expectancy_avg ~ PERIOD + status + PERIOD*status + (1 | continent/country), REML = T, data = datos_long)
tab_model(mod_mixto2)
| life_expectancy_avg | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 73.03 | 67.29 – 78.77 | <0.001 |
| PERIOD | 0.25 | 0.23 – 0.28 | <0.001 |
| status [Developing] | -7.38 | -10.20 – -4.55 | <0.001 |
|
PERIOD × status [Developing] |
0.12 | 0.09 – 0.14 | <0.001 |
| Random Effects | |||
| σ2 | 1.45 | ||
| τ00 country:continent | 29.60 | ||
| τ00 continent | 34.93 | ||
| ICC | 0.98 | ||
| N country | 184 | ||
| N continent | 5 | ||
| Observations | 2679 | ||
| Marginal R2 / Conditional R2 | 0.115 / 0.981 | ||
Output Las personas tienen una expectativa de vida al nacer de 73 años en países desarrollados en el año 2000 y 65.7 años para países en desarrollo La expectativa de vida al nacer aumenta 0.25 en países desarrollados por año y 0.12 en países en desarrollo, en forma estadísticamente significativa
#Voy a estandarizar measles y alcohol
datos_long <- datos_long %>%
mutate(measles_z = scale(measles))
datos_long <- datos_long %>%
mutate(alcohol_z = scale(alcohol))
datos_long <- datos_long %>%
mutate(polio_z = scale(polio))
datos_long <- datos_long %>%
mutate(diphtheria_z = scale(diphtheria))
datos_long <- datos_long %>%
mutate(malnutrition_z = scale(malnutrition))
#Modelo con alcohol
#alcohol es no significativa
mod_mixto3 <- lmer(life_expectancy_avg ~ PERIOD + status + alcohol_z +PERIOD*status + (1 | continent/country), REML = T, data = datos_long)
tab_model(mod_mixto3)
| life_expectancy_avg | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 72.62 | 66.93 – 78.32 | <0.001 |
| PERIOD | 0.25 | 0.23 – 0.28 | <0.001 |
| status [Developing] | -6.86 | -9.93 – -3.79 | <0.001 |
| alcohol z | 0.57 | -0.72 – 1.85 | 0.387 |
|
PERIOD × status [Developing] |
0.12 | 0.09 – 0.14 | <0.001 |
| Random Effects | |||
| σ2 | 1.45 | ||
| τ00 country:continent | 29.68 | ||
| τ00 continent | 33.06 | ||
| ICC | 0.98 | ||
| N country | 184 | ||
| N continent | 5 | ||
| Observations | 2679 | ||
| Marginal R2 / Conditional R2 | 0.130 / 0.980 | ||
#Modelo con measles
#measles no es significativo
mod_mixto4 <- lmer(life_expectancy_avg ~ PERIOD + status + measles_z + alcohol_z +PERIOD*status + (1 | continent/country), REML = T, data = datos_long)
tab_model(mod_mixto4)
| life_expectancy_avg | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 72.43 | 66.84 – 78.02 | <0.001 |
| PERIOD | 0.25 | 0.23 – 0.28 | <0.001 |
| status [Developing] | -6.68 | -9.74 – -3.61 | <0.001 |
| measles z | -0.72 | -1.55 – 0.11 | 0.088 |
| alcohol z | 0.69 | -0.59 – 1.98 | 0.289 |
|
PERIOD × status [Developing] |
0.12 | 0.09 – 0.14 | <0.001 |
| Random Effects | |||
| σ2 | 1.45 | ||
| τ00 country:continent | 29.40 | ||
| τ00 continent | 31.55 | ||
| ICC | 0.98 | ||
| N country | 184 | ||
| N continent | 5 | ||
| Observations | 2679 | ||
| Marginal R2 / Conditional R2 | 0.147 / 0.980 | ||
#modelo con polio. El aumento de la cobertura de la polio aumenta la esperanza de vida al nacer
#polio es significativa. Por cada 1% de aumento de la cobertura, la esperanza de vida al nacer aumenta en el periodo 0
mod_mixto5 <- lmer(life_expectancy_avg ~ PERIOD + status + measles_z + alcohol_z+ polio_z +PERIOD*status + (1 | continent/country), REML = T, data = datos_long)
tab_model(mod_mixto5)
| life_expectancy_avg | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 72.13 | 67.47 – 76.79 | <0.001 |
| PERIOD | 0.25 | 0.23 – 0.28 | <0.001 |
| status [Developing] | -6.11 | -8.82 – -3.41 | <0.001 |
| measles z | -0.13 | -0.88 – 0.61 | 0.729 |
| alcohol z | 0.22 | -0.92 – 1.35 | 0.707 |
| polio z | 2.94 | 2.15 – 3.73 | <0.001 |
|
PERIOD × status [Developing] |
0.12 | 0.09 – 0.14 | <0.001 |
| Random Effects | |||
| σ2 | 1.45 | ||
| τ00 country:continent | 22.79 | ||
| τ00 continent | 21.20 | ||
| ICC | 0.97 | ||
| N country | 184 | ||
| N continent | 5 | ||
| Observations | 2679 | ||
| Marginal R2 / Conditional R2 | 0.308 / 0.978 | ||
#modelo con health.expenditure
#no es significatia en tiempo basal ni modifica los coeficientes
mod_mixto6 <- lmer(life_expectancy_avg ~ PERIOD + status + measles_z + alcohol_z+ polio_z +PERIOD*status + health.expenditure+ (1 | continent/country), REML = T, data = datos_long)
tab_model(mod_mixto6)
| life_expectancy_avg | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 72.54 | 67.14 – 77.93 | <0.001 |
| PERIOD | 0.25 | 0.23 – 0.28 | <0.001 |
| status [Developing] | -6.18 | -8.92 – -3.43 | <0.001 |
| measles z | -0.14 | -0.89 – 0.61 | 0.714 |
| alcohol z | 0.22 | -0.92 – 1.36 | 0.702 |
| polio z | 2.93 | 2.14 – 3.72 | <0.001 |
| health expenditure | -0.06 | -0.42 – 0.31 | 0.764 |
|
PERIOD × status [Developing] |
0.12 | 0.09 – 0.14 | <0.001 |
| Random Effects | |||
| σ2 | 1.45 | ||
| τ00 country:continent | 22.90 | ||
| τ00 continent | 21.43 | ||
| ICC | 0.97 | ||
| N country | 184 | ||
| N continent | 5 | ||
| Observations | 2679 | ||
| Marginal R2 / Conditional R2 | 0.305 / 0.978 | ||
#modelo con diphtheria . Cobertura de inminización para difteria
#no es significativo pero modifica un poco 2.93 a 3.02 el coeficiente de polio
mod_mixto7 <- lmer(life_expectancy_avg ~ PERIOD + status + diphtheria_z+measles_z + alcohol_z+ polio_z +PERIOD*status + health.expenditure+ (1 | continent/country), REML = T, data = datos_long)
tab_model(mod_mixto7)
| life_expectancy_avg | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 72.52 | 67.11 – 77.94 | <0.001 |
| PERIOD | 0.25 | 0.23 – 0.28 | <0.001 |
| status [Developing] | -6.18 | -8.94 – -3.43 | <0.001 |
| diphtheria z | -0.10 | -2.26 – 2.06 | 0.929 |
| measles z | -0.14 | -0.90 – 0.61 | 0.709 |
| alcohol z | 0.22 | -0.92 – 1.36 | 0.704 |
| polio z | 3.02 | 0.92 – 5.12 | 0.005 |
| health expenditure | -0.05 | -0.42 – 0.32 | 0.776 |
|
PERIOD × status [Developing] |
0.12 | 0.09 – 0.14 | <0.001 |
| Random Effects | |||
| σ2 | 1.45 | ||
| τ00 country:continent | 23.03 | ||
| τ00 continent | 21.50 | ||
| ICC | 0.97 | ||
| N country | 184 | ||
| N continent | 5 | ||
| Observations | 2679 | ||
| Marginal R2 / Conditional R2 | 0.304 / 0.978 | ||
#modelo con malnutrition
#malnutrition es significativo en tiempo 0. A mayor porcentaje de malnutrición, baja la esperanza de vida basal 1.53 años
mod_mixto8 <- lmer(life_expectancy_avg ~ PERIOD + status + diphtheria_z+measles_z + alcohol_z+ polio_z +PERIOD*status + malnutrition_z +health.expenditure+ (1 | continent/country), REML = T, data = datos_long)
tab_model(mod_mixto8)
| life_expectancy_avg | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 72.15 | 66.98 – 77.32 | <0.001 |
| PERIOD | 0.25 | 0.23 – 0.28 | <0.001 |
| status [Developing] | -5.76 | -8.46 – -3.05 | <0.001 |
| diphtheria z | -0.13 | -2.24 – 1.98 | 0.905 |
| measles z | 0.06 | -0.69 – 0.81 | 0.874 |
| alcohol z | 0.08 | -1.04 – 1.20 | 0.891 |
| polio z | 2.85 | 0.79 – 4.90 | 0.007 |
| malnutrition z | -1.53 | -2.49 – -0.57 | 0.002 |
| health expenditure | -0.10 | -0.46 – 0.26 | 0.588 |
|
PERIOD × status [Developing] |
0.12 | 0.09 – 0.14 | <0.001 |
| Random Effects | |||
| σ2 | 1.45 | ||
| τ00 country:continent | 21.97 | ||
| τ00 continent | 18.84 | ||
| ICC | 0.97 | ||
| N country | 184 | ||
| N continent | 5 | ||
| Observations | 2679 | ||
| Marginal R2 / Conditional R2 | 0.361 / 0.978 | ||
summary(mod_mixto8)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: life_expectancy_avg ~ PERIOD + status + diphtheria_z + measles_z +
## alcohol_z + polio_z + PERIOD * status + malnutrition_z +
## health.expenditure + (1 | continent/country)
## Data: datos_long
##
## REML criterion at convergence: 9602
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -12.240 -0.317 0.026 0.363 6.519
##
## Random effects:
## Groups Name Variance Std.Dev.
## country:continent (Intercept) 21.97 4.69
## continent (Intercept) 18.84 4.34
## Residual 1.45 1.21
## Number of obs: 2679, groups: country:continent, 184; continent, 5
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 72.1482 2.6357 12.1801 27.37
## PERIOD 0.2523 0.0127 2492.1174 19.81
## statusDeveloping -5.7561 1.3790 175.7542 -4.17
## diphtheria_z -0.1288 1.0755 173.0169 -0.12
## measles_z 0.0608 0.3821 171.1659 0.16
## alcohol_z 0.0781 0.5708 175.5922 0.14
## polio_z 2.8489 1.0483 172.2149 2.72
## malnutrition_z -1.5316 0.4898 174.6450 -3.13
## health.expenditure -0.1005 0.1855 177.9259 -0.54
## PERIOD:statusDeveloping 0.1154 0.0141 2492.3136 8.20
## Pr(>|t|)
## (Intercept) 0.00000000000260243 ***
## PERIOD < 0.0000000000000002 ***
## statusDeveloping 0.00004701700210018 ***
## diphtheria_z 0.9048
## measles_z 0.8737
## alcohol_z 0.8913
## polio_z 0.0072 **
## malnutrition_z 0.0021 **
## health.expenditure 0.5888
## PERIOD:statusDeveloping 0.00000000000000037 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) PERIOD sttsDv dphth_ msls_z alchl_ poli_z mlntr_ hlth.x
## PERIOD -0.034
## statsDvlpng -0.490 0.065
## diphtheri_z 0.049 0.000 0.048
## measles_z -0.008 0.000 -0.020 0.102
## alcohol_z -0.138 0.000 0.368 0.018 -0.144
## polio_z -0.062 0.000 -0.025 -0.924 -0.024 -0.056
## malnutrtn_z 0.045 0.000 -0.100 0.010 -0.172 0.083 0.052
## hlth.xpndtr -0.504 0.000 0.139 -0.129 0.047 -0.023 0.150 0.082
## PERIOD:sttD 0.031 -0.905 -0.072 0.000 0.000 0.001 0.000 0.000 -0.002
#modelo con human.development.groups. Se modifican varios coeficientes y algunos pasan a ser significativos, como alcohol. el icc baja un poco a 0.94 y R2 es de 0.978
#reordeno la variablepara que low quede de referencia
datos_long$human.development.groups <- factor(
datos_long$human.development.groups,
levels = c("Low", "Medium", "High", "Very High")
)
summary(datos$human.development.groups)
## Length Class Mode
## 2679 character character
table(datos$human.development.groups)
##
## High Low Medium Very High
## 677 450 627 924
mod_mixto9 <- lmer(life_expectancy_avg ~ PERIOD + status+ human.development.groups + diphtheria_z+measles_z + alcohol_z+ polio_z +PERIOD*status + malnutrition_z +health.expenditure+ (1 | continent/country), REML = T, data = datos_long)
tab_model(mod_mixto9)
| life_expectancy_avg | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 63.60 | 59.08 – 68.13 | <0.001 |
| PERIOD | 0.25 | 0.23 – 0.28 | <0.001 |
| status [Developing] | -4.96 | -7.27 – -2.64 | <0.001 |
|
human development groups [Medium] |
3.82 | 1.76 – 5.88 | <0.001 |
|
human development groups [High] |
8.93 | 6.45 – 11.42 | <0.001 |
|
human development groups [Very High] |
12.69 | 9.78 – 15.60 | <0.001 |
| diphtheria z | -0.53 | -2.29 – 1.23 | 0.553 |
| measles z | 0.22 | -0.41 – 0.84 | 0.497 |
| alcohol z | -1.37 | -2.35 – -0.40 | 0.006 |
| polio z | 1.94 | 0.23 – 3.65 | 0.026 |
| malnutrition z | -0.43 | -1.26 – 0.40 | 0.309 |
| health expenditure | -0.02 | -0.33 – 0.28 | 0.883 |
|
PERIOD × status [Developing] |
0.12 | 0.09 – 0.14 | <0.001 |
| Random Effects | |||
| σ2 | 1.45 | ||
| τ00 country:continent | 14.86 | ||
| τ00 continent | 9.15 | ||
| ICC | 0.94 | ||
| N country | 183 | ||
| N continent | 5 | ||
| Observations | 2678 | ||
| Marginal R2 / Conditional R2 | 0.608 / 0.978 | ||
summary(mod_mixto9)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: life_expectancy_avg ~ PERIOD + status + human.development.groups +
## diphtheria_z + measles_z + alcohol_z + polio_z + PERIOD *
## status + malnutrition_z + health.expenditure + (1 | continent/country)
## Data: datos_long
##
## REML criterion at convergence: 9519
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -12.223 -0.317 0.026 0.367 6.500
##
## Random effects:
## Groups Name Variance Std.Dev.
## country:continent (Intercept) 14.86 3.85
## continent (Intercept) 9.15 3.03
## Residual 1.45 1.21
## Number of obs: 2678, groups: country:continent, 183; continent, 5
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 63.6045 2.3056 25.8671 27.59
## PERIOD 0.2523 0.0127 2492.3501 19.81
## statusDeveloping -4.9554 1.1795 172.7450 -4.20
## human.development.groupsMedium 3.8177 1.0503 170.7710 3.63
## human.development.groupsHigh 8.9324 1.2674 170.9107 7.05
## human.development.groupsVery High 12.6916 1.4849 171.0895 8.55
## diphtheria_z -0.5309 0.8957 170.0485 -0.59
## measles_z 0.2160 0.3178 167.5115 0.68
## alcohol_z -1.3747 0.4954 171.6358 -2.77
## polio_z 1.9418 0.8724 169.0939 2.23
## malnutrition_z -0.4314 0.4237 170.7608 -1.02
## health.expenditure -0.0229 0.1553 176.8761 -0.15
## PERIOD:statusDeveloping 0.1154 0.0141 2492.5745 8.20
## Pr(>|t|)
## (Intercept) < 0.0000000000000002 ***
## PERIOD < 0.0000000000000002 ***
## statusDeveloping 0.00004247862435321 ***
## human.development.groupsMedium 0.00037 ***
## human.development.groupsHigh 0.00000000004282614 ***
## human.development.groupsVery High 0.00000000000000677 ***
## diphtheria_z 0.55418
## measles_z 0.49762
## alcohol_z 0.00614 **
## polio_z 0.02734 *
## malnutrition_z 0.30999
## health.expenditure 0.88295
## PERIOD:statusDeveloping 0.00000000000000037 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation matrix not shown by default, as p = 13 > 12.
## Use print(x, correlation=TRUE) or
## vcov(x) if you need it
#modelo con hiv.aids. measles y alcohol dejan de ser significativos. También la desnutrición. Baja el icc a 0.89 y aumenta el R2 a 0.98
mod_mixto10 <- lmer(life_expectancy_avg ~ PERIOD + status+ human.development.groups + diphtheria_z+measles_z + alcohol_z+ polio_z +PERIOD*status + malnutrition_z + hiv.aids + health.expenditure+ (1 | continent/country), REML = T, data = datos_long)
tab_model(mod_mixto10)
| life_expectancy_avg | |||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 62.54 | 59.33 – 65.75 | <0.001 |
| PERIOD | 0.25 | 0.23 – 0.28 | <0.001 |
| status [Developing] | -4.18 | -6.07 – -2.30 | <0.001 |
|
human development groups [Medium] |
4.72 | 3.05 – 6.39 | <0.001 |
|
human development groups [High] |
8.93 | 6.92 – 10.95 | <0.001 |
|
human development groups [Very High] |
12.36 | 10.00 – 14.71 | <0.001 |
| diphtheria z | -0.01 | -1.44 – 1.41 | 0.984 |
| measles z | 0.08 | -0.43 – 0.59 | 0.747 |
| alcohol z | -0.57 | -1.36 – 0.21 | 0.154 |
| polio z | 1.58 | 0.19 – 2.97 | 0.026 |
| malnutrition z | -0.26 | -0.93 – 0.41 | 0.448 |
| hiv aids | -0.60 | -0.72 – -0.48 | <0.001 |
| health expenditure | 0.16 | -0.09 – 0.41 | 0.197 |
|
PERIOD × status [Developing] |
0.12 | 0.09 – 0.14 | <0.001 |
| Random Effects | |||
| σ2 | 1.45 | ||
| τ00 country:continent | 9.91 | ||
| τ00 continent | 1.99 | ||
| ICC | 0.89 | ||
| N country | 183 | ||
| N continent | 5 | ||
| Observations | 2678 | ||
| Marginal R2 / Conditional R2 | 0.822 / 0.981 | ||
summary(mod_mixto10)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: life_expectancy_avg ~ PERIOD + status + human.development.groups +
## diphtheria_z + measles_z + alcohol_z + polio_z + PERIOD *
## status + malnutrition_z + hiv.aids + health.expenditure +
## (1 | continent/country)
## Data: datos_long
##
## REML criterion at convergence: 9449
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -12.207 -0.322 0.025 0.363 6.551
##
## Random effects:
## Groups Name Variance Std.Dev.
## country:continent (Intercept) 9.91 3.15
## continent (Intercept) 1.99 1.41
## Residual 1.45 1.21
## Number of obs: 2678, groups: country:continent, 183; continent, 5
##
## Fixed effects:
## Estimate Std. Error df t value
## (Intercept) 62.5381 1.6381 62.2020 38.18
## PERIOD 0.2523 0.0127 2491.2532 19.81
## statusDeveloping -4.1844 0.9601 171.8252 -4.36
## human.development.groupsMedium 4.7224 0.8522 167.0384 5.54
## human.development.groupsHigh 8.9343 1.0260 168.2121 8.71
## human.development.groupsVery High 12.3580 1.2014 166.9615 10.29
## diphtheria_z -0.0150 0.7276 168.4635 -0.02
## measles_z 0.0838 0.2600 166.1273 0.32
## alcohol_z -0.5742 0.4024 144.9877 -1.43
## polio_z 1.5805 0.7111 168.4899 2.22
## malnutrition_z -0.2582 0.3404 159.0736 -0.76
## hiv.aids -0.6005 0.0616 163.3631 -9.75
## health.expenditure 0.1646 0.1275 177.7563 1.29
## PERIOD:statusDeveloping 0.1152 0.0141 2491.5713 8.19
## Pr(>|t|)
## (Intercept) < 0.0000000000000002 ***
## PERIOD < 0.0000000000000002 ***
## statusDeveloping 0.00002250142696292 ***
## human.development.groupsMedium 0.00000011499563845 ***
## human.development.groupsHigh 0.00000000000000278 ***
## human.development.groupsVery High < 0.0000000000000002 ***
## diphtheria_z 0.984
## measles_z 0.748
## alcohol_z 0.156
## polio_z 0.028 *
## malnutrition_z 0.449
## hiv.aids < 0.0000000000000002 ***
## health.expenditure 0.199
## PERIOD:statusDeveloping 0.00000000000000041 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation matrix not shown by default, as p = 14 > 12.
## Use print(x, correlation=TRUE) or
## vcov(x) if you need it