---
title: "ssas11"
author: "daria agapova"
date: "2024-05-30"
output: html_document
---
## Loading Libraries and Data
```r
# Load necessary libraries
library(readr)
library(dplyr)
##
## Присоединяю пакет: 'dplyr'
## Следующие объекты скрыты от 'package:stats':
##
## filter, lag
## Следующие объекты скрыты от 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(stats)
library(agricolae)
## Warning: пакет 'agricolae' был собран под R версии 4.3.3
library(ggridges)
## Warning: пакет 'ggridges' был собран под R версии 4.3.3
library(heplots)
## Warning: пакет 'heplots' был собран под R версии 4.3.3
## Загрузка требуемого пакета: broom
library(DescTools)
## Warning: пакет 'DescTools' был собран под R версии 4.3.3
library(haven)
## Warning: пакет 'haven' был собран под R версии 4.3.3
library(foreign)
library(ggpubr)
## Warning: пакет 'ggpubr' был собран под R версии 4.3.3
library(psych)
## Warning: пакет 'psych' был собран под R версии 4.3.3
##
## Присоединяю пакет: 'psych'
## Следующие объекты скрыты от 'package:DescTools':
##
## AUC, ICC, SD
## Следующие объекты скрыты от 'package:ggplot2':
##
## %+%, alpha
library(sjlabelled)
## Warning: пакет 'sjlabelled' был собран под R версии 4.3.3
##
## Присоединяю пакет: 'sjlabelled'
## Следующие объекты скрыты от 'package:haven':
##
## as_factor, read_sas, read_spss, read_stata, write_sas, zap_labels
## Следующий объект скрыт от 'package:ggplot2':
##
## as_label
## Следующий объект скрыт от 'package:dplyr':
##
## as_label
library(sjPlot)
## Warning: пакет 'sjPlot' был собран под R версии 4.3.3
## Warning in check_dep_version(): ABI version mismatch:
## lme4 was built with Matrix ABI version 1
## Current Matrix ABI version is 0
## Please re-install lme4 from source or restore original 'Matrix' package
## Install package "strengejacke" from GitHub (`devtools::install_github("strengejacke/strengejacke")`) to load all sj-packages at once!
library(stargazer)
##
## Please cite as:
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(broom)
# Load the dataset
data <- read.csv("D:/Users/astsl/Documents/ESS6e02_6.csv")
# Filter Russian data and select relevant variables
datarus <- data %>%
filter(cntry == "RU") %>%
select(agea, marsts, health, gndr, isco08, hinctnta, edlvdru, domicil) %>%
na.omit()
# Describe the dataset
describe(datarus)
## vars n mean sd median trimmed mad min max range
## agea 1 2484 47.15 37.73 45 45.49 22.24 15 999 984
## marsts 2 2484 31.82 30.76 6 30.63 2.97 1 88 87
## health 3 2484 2.80 0.92 3 2.75 1.48 1 8 7
## gndr 4 2484 1.62 0.49 2 1.65 0.00 1 2 1
## isco08 5 2484 13801.72 22440.54 5223 8052.51 3392.93 110 99999 99889
## hinctnta 6 2484 22.03 30.60 8 16.85 4.45 1 88 87
## edlvdru 7 2484 6.91 2.47 7 7.05 4.45 1 11 10
## domicil 8 2484 2.38 1.23 3 2.34 1.48 1 8 7
## skew kurtosis se
## agea 19.40 486.55 0.76
## marsts 0.30 -1.86 0.62
## health 1.27 6.27 0.02
## gndr -0.48 -1.77 0.01
## isco08 2.16 2.81 450.25
## hinctnta 1.38 -0.01 0.61
## edlvdru -0.20 -0.98 0.05
## domicil 0.11 -1.10 0.02
# Remove invalid health responses
datarus <- datarus %>%
filter(health != 8, health != 9, health != 7)
datarus$health <- as.numeric(as.character(datarus$health))
# Clean age data
datarus <- datarus %>%
filter(agea != 999)
datarus$agea <- as.numeric(as.character(datarus$agea))
# Clean education data
datarus <- datarus %>%
filter(edlvdru != 5555, edlvdru != 7777, edlvdru != 8888, edlvdru != 9999)
# Clean place of residence data
datarus <- datarus %>%
filter(domicil != 7, domicil != 8, domicil != 9)
datarus$domicil <- factor(datarus$domicil, labels = c("Big city", "Suburb", "Town", "Village", "Countryside"))
# Clean marital status data
datarus <- datarus %>%
filter(marsts != 88, marsts != 99, marsts != 77, marsts != 66)
datarus$marsts <- factor(datarus$marsts, labels = c("Married", "Divorced", "Widowed", "Never married"))
# Recode occupation categories
datarus <- datarus %>%
mutate(occupation = case_when(
isco08 %in% 1000:1439 ~ "Managers",
isco08 %in% 2000:2659 ~ "Professionals",
isco08 %in% 3000:3522 ~ "Technicians",
isco08 %in% 4000:4419 ~ "Clerical",
isco08 %in% 5000:5419 ~ "Service",
isco08 %in% 6000:6340 ~ "Agricultural",
isco08 %in% 7000:7549 ~ "Crafts",
isco08 %in% 8000:8350 ~ "Operators",
isco08 %in% 9000:9629 ~ "Elementary",
isco08 %in% 0:1000 ~ "Armed Forces",
TRUE ~ NA_character_
))
datarus <- na.omit(datarus)
# Combine small occupation categories
datarus <- datarus %>%
mutate(occupation = case_when(
isco08 %in% 2000:2659 | isco08 %in% 1000:1439 ~ "Managers & Professionals",
isco08 %in% 3000:3522 | isco08 %in% 8000:8350 ~ "Tech & Operators",
isco08 %in% 5000:5419 | isco08 %in% 4000:4419 ~ "Service & Clerical",
isco08 %in% 6000:6340 ~ "Agricultural",
isco08 %in% 9000:9629 | isco08 %in% 7000:7549 | isco08 %in% 0:1000 ~ "Elementary & Others",
TRUE ~ NA_character_
))
# Clean income data
datarus <- datarus %>%
filter(hinctnta != 77, hinctnta != 88, hinctnta != 99)
datarus$hinctnta <- factor(datarus$hinctnta, labels = c("1st decile", "2nd decile", "3rd decile", "4th decile", "5th decile", "6th decile", "7th decile", "8th decile", "9th decile", "10th decile"))
# Convert categorical variables to factors
datarus$domicil <- as.factor(datarus$domicil)
datarus$marsts <- as.factor(datarus$marsts)
datarus$gndr <- as.factor(datarus$gndr)
datarus$occupation <- as.factor(datarus$occupation)
datarus$hinctnta <- as.factor(datarus$hinctnta)
datarus$edlvdru <- as.factor(datarus$edlvdru)
# Regression with occupation
model1 <- lm(health ~ agea + domicil + marsts + gndr + occupation, data = datarus)
summary(model1)
##
## Call:
## lm(formula = health ~ agea + domicil + marsts + gndr + occupation,
## data = datarus)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.56183 -0.42344 -0.07867 0.50796 2.53867
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.763086 0.250850 7.028 3.99e-12 ***
## agea 0.020376 0.001797 11.338 < 2e-16 ***
## domicilSuburb 0.291073 0.118994 2.446 0.01462 *
## domicilTown 0.031266 0.052342 0.597 0.55042
## domicilVillage -0.001688 0.063866 -0.026 0.97893
## domicilCountryside -0.496215 0.285777 -1.736 0.08282 .
## marstsDivorced 0.092344 0.144193 0.640 0.52205
## marstsWidowed 0.168820 0.149280 1.131 0.25839
## marstsNever married 0.069577 0.146581 0.475 0.63513
## gndr2 0.161139 0.056042 2.875 0.00413 **
## occupationElementary & Others -0.103811 0.184153 -0.564 0.57308
## occupationManagers & Professionals -0.219934 0.185620 -1.185 0.23637
## occupationService & Clerical -0.159634 0.182360 -0.875 0.38159
## occupationTech & Operators -0.185223 0.184817 -1.002 0.31651
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6913 on 946 degrees of freedom
## Multiple R-squared: 0.3044, Adjusted R-squared: 0.2948
## F-statistic: 31.84 on 13 and 946 DF, p-value: < 2.2e-16
# Regression with income
model2 <- lm(health ~ agea + domicil + marsts + gndr + hinctnta, data = datarus)
summary(model2)
##
## Call:
## lm(formula = health ~ agea + domicil + marsts + gndr + hinctnta,
## data = datarus)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.72364 -0.41032 -0.04739 0.47768 2.65441
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.90598 0.21212 8.985 <2e-16 ***
## agea 0.01831 0.00183 10.004 <2e-16 ***
## domicilSuburb 0.24547 0.11826 2.076 0.0382 *
## domicilTown -0.01007 0.05250 -0.192 0.8480
## domicilVillage -0.05501 0.06356 -0.866 0.3870
## domicilCountryside -0.62755 0.28344 -2.214 0.0271 *
## marstsDivorced 0.05196 0.14318 0.363 0.7168
## marstsWidowed 0.13166 0.14826 0.888 0.3748
## marstsNever married 0.03211 0.14544 0.221 0.8253
## gndr2 0.11385 0.05223 2.180 0.0295 *
## hinctnta2nd decile 0.16239 0.13359 1.216 0.2245
## hinctnta3rd decile -0.10432 0.13154 -0.793 0.4279
## hinctnta4th decile -0.13466 0.13772 -0.978 0.3284
## hinctnta5th decile -0.04156 0.13959 -0.298 0.7660
## hinctnta6th decile -0.15703 0.14536 -1.080 0.2803
## hinctnta7th decile -0.15816 0.14690 -1.077 0.2819
## hinctnta8th decile -0.16085 0.14182 -1.134 0.2570
## hinctnta9th decile -0.34719 0.14743 -2.355 0.0187 *
## hinctnta10th decile -0.24249 0.13774 -1.760 0.0787 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6831 on 941 degrees of freedom
## Multiple R-squared: 0.3244, Adjusted R-squared: 0.3114
## F-statistic: 25.1 on 18 and 941 DF, p-value: < 2.2e-16
# Regression with education
model3 <- lm(health ~ agea + domicil + marsts + gndr + edlvdru, data = datarus)
summary(model3)
##
## Call:
## lm(formula = health ~ agea + domicil + marsts + gndr + edlvdru,
## data = datarus)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.4535 -0.3938 -0.0424 0.4461 2.5103
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.0723322 0.4442516 4.665 3.54e-06 ***
## agea 0.0184885 0.0018380 10.059 < 2e-16 ***
## domicilSuburb 0.2662155 0.1185362 2.246 0.02494 *
## domicilTown 0.0008716 0.0526785 0.017 0.98680
## domicilVillage -0.0369340 0.0636236 -0.581 0.56171
## domicilCountryside -0.5810101 0.2840284 -2.046 0.04107 *
## marstsDivorced 0.0896977 0.1430017 0.627 0.53065
## marstsWidowed 0.1425085 0.1481595 0.962 0.33637
## marstsNever married 0.0288689 0.1460695 0.198 0.84337
## gndr2 0.1708134 0.0528608 3.231 0.00127 **
## edlvdru2 -0.1218580 0.4111868 -0.296 0.76702
## edlvdru3 0.0070514 0.4089650 0.017 0.98625
## edlvdru4 -0.2501271 0.4053332 -0.617 0.53732
## edlvdru5 -0.1737745 0.4223597 -0.411 0.68085
## edlvdru6 -0.3742941 0.4076482 -0.918 0.35876
## edlvdru7 -0.3793307 0.4022093 -0.943 0.34586
## edlvdru8 -0.3853976 0.4275614 -0.901 0.36761
## edlvdru9 -0.5014577 0.4917898 -1.020 0.30815
## edlvdru10 -0.4562500 0.4033345 -1.131 0.25826
## edlvdru11 -0.1045437 0.6283028 -0.166 0.86789
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6847 on 940 degrees of freedom
## Multiple R-squared: 0.3221, Adjusted R-squared: 0.3084
## F-statistic: 23.5 on 19 and 940 DF, p-value: < 2.2e-16
# Regression with all SES components
model4 <- lm(health ~ agea + domicil + marsts + gndr + occupation + hinctnta + edlvdru, data = datarus)
summary(model4)
##
## Call:
## lm(formula = health ~ agea + domicil + marsts + gndr + occupation +
## hinctnta + edlvdru, data = datarus)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.58079 -0.40005 -0.02921 0.44675 2.47623
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.3461463 0.4742306 4.947 8.94e-07 ***
## agea 0.0169440 0.0019038 8.900 < 2e-16 ***
## domicilSuburb 0.2352321 0.1187258 1.981 0.0479 *
## domicilTown -0.0336462 0.0535473 -0.628 0.5299
## domicilVillage -0.0867414 0.0657249 -1.320 0.1872
## domicilCountryside -0.6883675 0.2845440 -2.419 0.0157 *
## marstsDivorced 0.0525651 0.1434115 0.367 0.7141
## marstsWidowed 0.1075849 0.1488546 0.723 0.4700
## marstsNever married -0.0002134 0.1460380 -0.001 0.9988
## gndr2 0.1294158 0.0563552 2.296 0.0219 *
## occupationElementary & Others -0.0052255 0.1842914 -0.028 0.9774
## occupationManagers & Professionals 0.0459468 0.1918756 0.239 0.8108
## occupationService & Clerical 0.0135898 0.1840544 0.074 0.9412
## occupationTech & Operators 0.0013173 0.1867066 0.007 0.9944
## hinctnta2nd decile 0.1671630 0.1343130 1.245 0.2136
## hinctnta3rd decile -0.0613002 0.1330976 -0.461 0.6452
## hinctnta4th decile -0.0946339 0.1387885 -0.682 0.4955
## hinctnta5th decile -0.0130624 0.1407541 -0.093 0.9261
## hinctnta6th decile -0.1044022 0.1466775 -0.712 0.4768
## hinctnta7th decile -0.0953511 0.1481436 -0.644 0.5200
## hinctnta8th decile -0.0974085 0.1433001 -0.680 0.4968
## hinctnta9th decile -0.2824314 0.1487321 -1.899 0.0579 .
## hinctnta10th decile -0.1813481 0.1393124 -1.302 0.1933
## edlvdru2 -0.2281920 0.4142758 -0.551 0.5819
## edlvdru3 -0.1090045 0.4130441 -0.264 0.7919
## edlvdru4 -0.3081371 0.4092351 -0.753 0.4517
## edlvdru5 -0.2503901 0.4261620 -0.588 0.5570
## edlvdru6 -0.4518900 0.4121859 -1.096 0.2732
## edlvdru7 -0.4337507 0.4071817 -1.065 0.2870
## edlvdru8 -0.4540993 0.4326649 -1.050 0.2942
## edlvdru9 -0.5402753 0.4963668 -1.088 0.2767
## edlvdru10 -0.5051435 0.4092509 -1.234 0.2174
## edlvdru11 -0.1830310 0.6356633 -0.288 0.7735
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6812 on 927 degrees of freedom
## Multiple R-squared: 0.3383, Adjusted R-squared: 0.3154
## F-statistic: 14.81 on 32 and 927 DF, p-value: < 2.2e-16
# Compare models
anova(model1, model2, model3, model4)
## Analysis of Variance Table
##
## Model 1: health ~ agea + domicil + marsts + gndr + occupation
## Model 2: health ~ agea + domicil + marsts + gndr + hinctnta
## Model 3: health ~ agea + domicil + marsts + gndr + edlvdru
## Model 4: health ~ agea + domicil + marsts + gndr + occupation + hinctnta +
## edlvdru
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 946 452.13
## 2 941 439.15 5 12.9830 5.5962 4.335e-05 ***
## 3 940 440.64 1 -1.4984
## 4 927 430.12 13 10.5268 1.7452 0.04745 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Plotting the models
plot_model(model1)
plot_model(model2)
plot_model(model3)
plot_model(model4)
# Tabulate the models
tab_model(model1, model2, model3, model4)
| health | health | health | health | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Predictors | Estimates | CI | p | Estimates | CI | p | Estimates | CI | p | Estimates | CI | p |
| (Intercept) | 1.76 | 1.27 – 2.26 | <0.001 | 1.91 | 1.49 – 2.32 | <0.001 | 2.07 | 1.20 – 2.94 | <0.001 | 2.35 | 1.42 – 3.28 | <0.001 |
| agea | 0.02 | 0.02 – 0.02 | <0.001 | 0.02 | 0.01 – 0.02 | <0.001 | 0.02 | 0.01 – 0.02 | <0.001 | 0.02 | 0.01 – 0.02 | <0.001 |
| domicil [Suburb] | 0.29 | 0.06 – 0.52 | 0.015 | 0.25 | 0.01 – 0.48 | 0.038 | 0.27 | 0.03 – 0.50 | 0.025 | 0.24 | 0.00 – 0.47 | 0.048 |
| domicil [Town] | 0.03 | -0.07 – 0.13 | 0.550 | -0.01 | -0.11 – 0.09 | 0.848 | 0.00 | -0.10 – 0.10 | 0.987 | -0.03 | -0.14 – 0.07 | 0.530 |
| domicil [Village] | -0.00 | -0.13 – 0.12 | 0.979 | -0.06 | -0.18 – 0.07 | 0.387 | -0.04 | -0.16 – 0.09 | 0.562 | -0.09 | -0.22 – 0.04 | 0.187 |
| domicil [Countryside] | -0.50 | -1.06 – 0.06 | 0.083 | -0.63 | -1.18 – -0.07 | 0.027 | -0.58 | -1.14 – -0.02 | 0.041 | -0.69 | -1.25 – -0.13 | 0.016 |
| marsts [Divorced] | 0.09 | -0.19 – 0.38 | 0.522 | 0.05 | -0.23 – 0.33 | 0.717 | 0.09 | -0.19 – 0.37 | 0.531 | 0.05 | -0.23 – 0.33 | 0.714 |
| marsts [Widowed] | 0.17 | -0.12 – 0.46 | 0.258 | 0.13 | -0.16 – 0.42 | 0.375 | 0.14 | -0.15 – 0.43 | 0.336 | 0.11 | -0.18 – 0.40 | 0.470 |
| marsts [Never married] | 0.07 | -0.22 – 0.36 | 0.635 | 0.03 | -0.25 – 0.32 | 0.825 | 0.03 | -0.26 – 0.32 | 0.843 | -0.00 | -0.29 – 0.29 | 0.999 |
| gndr [2] | 0.16 | 0.05 – 0.27 | 0.004 | 0.11 | 0.01 – 0.22 | 0.030 | 0.17 | 0.07 – 0.27 | 0.001 | 0.13 | 0.02 – 0.24 | 0.022 |
|
occupation [Elementary & Others] |
-0.10 | -0.47 – 0.26 | 0.573 | -0.01 | -0.37 – 0.36 | 0.977 | ||||||
|
occupation [Managers & Professionals] |
-0.22 | -0.58 – 0.14 | 0.236 | 0.05 | -0.33 – 0.42 | 0.811 | ||||||
|
occupation [Service & Clerical] |
-0.16 | -0.52 – 0.20 | 0.382 | 0.01 | -0.35 – 0.37 | 0.941 | ||||||
|
occupation [Tech & Operators] |
-0.19 | -0.55 – 0.18 | 0.317 | 0.00 | -0.37 – 0.37 | 0.994 | ||||||
| hinctnta [2nd decile] | 0.16 | -0.10 – 0.42 | 0.224 | 0.17 | -0.10 – 0.43 | 0.214 | ||||||
| hinctnta [3rd decile] | -0.10 | -0.36 – 0.15 | 0.428 | -0.06 | -0.32 – 0.20 | 0.645 | ||||||
| hinctnta [4th decile] | -0.13 | -0.40 – 0.14 | 0.328 | -0.09 | -0.37 – 0.18 | 0.495 | ||||||
| hinctnta [5th decile] | -0.04 | -0.32 – 0.23 | 0.766 | -0.01 | -0.29 – 0.26 | 0.926 | ||||||
| hinctnta [6th decile] | -0.16 | -0.44 – 0.13 | 0.280 | -0.10 | -0.39 – 0.18 | 0.477 | ||||||
| hinctnta [7th decile] | -0.16 | -0.45 – 0.13 | 0.282 | -0.10 | -0.39 – 0.20 | 0.520 | ||||||
| hinctnta [8th decile] | -0.16 | -0.44 – 0.12 | 0.257 | -0.10 | -0.38 – 0.18 | 0.497 | ||||||
| hinctnta [9th decile] | -0.35 | -0.64 – -0.06 | 0.019 | -0.28 | -0.57 – 0.01 | 0.058 | ||||||
| hinctnta [10th decile] | -0.24 | -0.51 – 0.03 | 0.079 | -0.18 | -0.45 – 0.09 | 0.193 | ||||||
| edlvdru [2] | -0.12 | -0.93 – 0.69 | 0.767 | -0.23 | -1.04 – 0.58 | 0.582 | ||||||
| edlvdru [3] | 0.01 | -0.80 – 0.81 | 0.986 | -0.11 | -0.92 – 0.70 | 0.792 | ||||||
| edlvdru [4] | -0.25 | -1.05 – 0.55 | 0.537 | -0.31 | -1.11 – 0.49 | 0.452 | ||||||
| edlvdru [5] | -0.17 | -1.00 – 0.66 | 0.681 | -0.25 | -1.09 – 0.59 | 0.557 | ||||||
| edlvdru [6] | -0.37 | -1.17 – 0.43 | 0.359 | -0.45 | -1.26 – 0.36 | 0.273 | ||||||
| edlvdru [7] | -0.38 | -1.17 – 0.41 | 0.346 | -0.43 | -1.23 – 0.37 | 0.287 | ||||||
| edlvdru [8] | -0.39 | -1.22 – 0.45 | 0.368 | -0.45 | -1.30 – 0.40 | 0.294 | ||||||
| edlvdru [9] | -0.50 | -1.47 – 0.46 | 0.308 | -0.54 | -1.51 – 0.43 | 0.277 | ||||||
| edlvdru [10] | -0.46 | -1.25 – 0.34 | 0.258 | -0.51 | -1.31 – 0.30 | 0.217 | ||||||
| edlvdru [11] | -0.10 | -1.34 – 1.13 | 0.868 | -0.18 | -1.43 – 1.06 | 0.773 | ||||||
| Observations | 960 | 960 | 960 | 960 | ||||||||
| R2 / R2 adjusted | 0.304 / 0.295 | 0.324 / 0.311 | 0.322 / 0.308 | 0.338 / 0.315 | ||||||||
The \(R^2\) values indicate that the combined model (Model 4) explains the highest proportion of variance in health outcomes, suggesting that considering all SES components together provides the most comprehensive explanation for health inequalities.