Assignment 4 - Multilevel Modeling

Set Up

library(haven)
library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.4.3
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   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
library(sjstats)
Warning: package 'sjstats' was built under R version 4.4.3
library(lme4)
Loading required package: Matrix

Attaching package: 'Matrix'

The following objects are masked from 'package:tidyr':

    expand, pack, unpack
library(arm)
Loading required package: MASS

Attaching package: 'MASS'

The following object is masked from 'package:dplyr':

    select


arm (Version 1.14-4, built: 2024-4-1)

Working directory is C:/Users/Admin/Downloads
library(haven)
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(dplyr)

Hypothesis:

The higher the financial satisfaction, the higher the life satisfaction. The higher the health satisfaction, the higher the life satisfaction.

I expect developing countries, such as Iraq, Kenya, Libya, Mexico, and Malaysia, will have lower overall life satisfaction than developed countries like Germany, Japan, Russia, and the United States. However, after increasing financial and health satisfaction, overall life satisfaction will increase more among developing countries.

Control Variable:

I choose sex and immigration status as they are demographic variables.

Import the data

wvs_hw4_data <- read_dta("C:/Users/Admin/Downloads/wvs_hw4_data.dta")
head(wvs_hw4_data)
# A tibble: 6 × 63
  a_wave a_year a_study b_country b_country_alpha c_cow_num c_cow_alpha
   <dbl>  <dbl>   <dbl>     <dbl> <chr>               <dbl> <chr>      
1      7   2018       2       276 DEU                   255 GMY        
2      7   2018       2       276 DEU                   255 GMY        
3      7   2018       2       276 DEU                   255 GMY        
4      7   2018       2       276 DEU                   255 GMY        
5      7   2018       2       276 DEU                   255 GMY        
6      7   2018       2       276 DEU                   255 GMY        
# ℹ 56 more variables: d_interview <dbl>, s007 <dbl>, j_intdate <dbl>,
#   fw_end <dbl>, fw_start <dbl>, k_time_start <dbl>, k_time_end <dbl>,
#   k_duration <dbl>, q_mode <dbl>, n_region_iso <dbl>, n_region_wvs <dbl>,
#   n_region_nuts2 <dbl>, reg_nuts1 <dbl>, n_town <dbl>, g_townsize <dbl>,
#   g_townsize2 <dbl>, h_settlement <dbl>, h_urbrural <dbl>,
#   l_interviewer_number <dbl>, i_psu <dbl>, o1_longitude <dbl>,
#   o2_latitude <dbl>, s_intlanguage <dbl>, lnge_iso <chr>, e_respint <dbl>, …
unique(wvs_hw4_data$q49)
 [1]  8  7 10  9 -1  6  5  4  3  2  1 -2
unique(wvs_hw4_data$q50)
 [1]  8  7 10  9  6 -1  5  3  2  4  1 -2
unique(wvs_hw4_data$q47)
[1]  2  3  1  4  5 -2 -1
unique(wvs_hw4_data$q260)
[1]  1  2 -2 -1
unique(wvs_hw4_data$q263)
[1]  1  2 -2 -1
length(unique(wvs_hw4_data$b_country_alpha[!is.na(wvs_hw4_data$b_country_alpha)]))
[1] 9
unique(wvs_hw4_data$b_country_alpha[!is.na(wvs_hw4_data$b_country_alpha)])
[1] "DEU" "IRQ" "JPN" "KEN" "LBY" "MEX" "MYS" "RUS" "USA"

Clean the data

wvs <- wvs_hw4_data %>% dplyr::select(q49, q50, q47, q260, q263,b_country_alpha,gd_ppercap1)
wvs
# A tibble: 14,003 × 7
     q49   q50   q47  q260  q263 b_country_alpha gd_ppercap1
   <dbl> <dbl> <dbl> <dbl> <dbl> <chr>                 <dbl>
 1     8     8     2     1     1 DEU                  56052.
 2     7     7     3     2     1 DEU                  56052.
 3    10    10     3     1     1 DEU                  56052.
 4     9     9     1     2     1 DEU                  56052.
 5    10    10     3     2     1 DEU                  56052.
 6     8     6     2     2     1 DEU                  56052.
 7     9     6     2     1     1 DEU                  56052.
 8     7     8     2     2     1 DEU                  56052.
 9     8    10     2     1     1 DEU                  56052.
10     8     9     1     1     1 DEU                  56052.
# ℹ 13,993 more rows
wvs <- wvs %>%
  mutate(q49 = ifelse(q49 <= -1, NA, q49),
         q50 = ifelse(q50 <= -1, NA, q50), 
         q260 = ifelse(q260 <= -1, NA, q260),
         q263 = ifelse(q263 <= -1, NA, q263))

wvs<- wvs %>% 
mutate(q47 = case_when(
q47 ==1 ~ 5,
q47 ==2 ~ 4,
q47 ==3 ~ 3,
q47 ==4 ~ 2, 
q47 ==5 ~ 1, 
q47 <= -1~ NA),
q47 = labelled(q47, c(`Very poor` = 1, `Poor` = 2, `Fair` = 3, `Good` = 4, `Very good`=5)))

head(wvs$q47)
<labelled<double>[6]>
[1] 4 3 3 5 3 4

Labels:
 value     label
     1 Very poor
     2      Poor
     3      Fair
     4      Good
     5 Very good
unique(wvs$q47)
<labelled<double>[6]>
[1]  4  3  5  2  1 NA

Labels:
 value     label
     1 Very poor
     2      Poor
     3      Fair
     4      Good
     5 Very good
new_column_name <- c("satisfaction_with_life", "satisfaction_with_personal_finances", "personal_health_status", "biological_sex", "immigrant_or_not", "country_code","gdp_per_capita")

colnames(wvs) <- new_column_name
head(wvs)
# A tibble: 6 × 7
  satisfaction_with_life satisfaction_with_personal_fin…¹ personal_health_status
                   <dbl>                            <dbl> <dbl+lbl>             
1                      8                                8 4 [Good]              
2                      7                                7 3 [Fair]              
3                     10                               10 3 [Fair]              
4                      9                                9 5 [Very good]         
5                     10                               10 3 [Fair]              
6                      8                                6 4 [Good]              
# ℹ abbreviated name: ¹​satisfaction_with_personal_finances
# ℹ 4 more variables: biological_sex <dbl>, immigrant_or_not <dbl>,
#   country_code <chr>, gdp_per_capita <dbl>

Part 1

ICC

###Varying Intercept Model - For Interclass Correlation 
mlm <- lmer(satisfaction_with_life ~ 1 + (1|country_code), data = wvs)
summary(mlm)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ 1 + (1 | country_code)
   Data: wvs

REML criterion at convergence: 59111

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-3.5279 -0.6041  0.1189  0.7184  2.7337 

Random effects:
 Groups       Name        Variance Std.Dev.
 country_code (Intercept) 1.31     1.144   
 Residual                 4.09     2.022   
Number of obs: 13907, groups:  country_code, 9

Fixed effects:
            Estimate Std. Error t value
(Intercept)   6.8514     0.3819   17.94
icc<-1.266/(1.266+4.552)

print(icc)
[1] 0.2176006

Interpretation

To start, we often fit an unconditional means model that provides us information about how much of the total variance in the outcome variable is within-person variance and how much is between-person variance.

This is an unconditional means model that provides information about how much of the total variance in the outcome variable is in people’s satisfaction with life. 21.7% is between cluster variation, while 78.3% is within cluster variation. The ICC is small, which means less impact on the estimated standard errors, and the Type I error rate is increased.

Varying Intercept

mlm_1 <- lmer(satisfaction_with_life ~ satisfaction_with_personal_finances+ biological_sex+ immigrant_or_not+(1|country_code), data = wvs)
summary(mlm_1)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ satisfaction_with_personal_finances +  
    biological_sex + immigrant_or_not + (1 | country_code)
   Data: wvs

REML criterion at convergence: 53123.3

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-5.1924 -0.4929  0.1042  0.5087  3.6152 

Random effects:
 Groups       Name        Variance Std.Dev.
 country_code (Intercept) 0.5759   0.7589  
 Residual                 2.8055   1.6750  
Number of obs: 13712, groups:  country_code, 9

Fixed effects:
                                     Estimate Std. Error t value
(Intercept)                          3.871926   0.270753  14.301
satisfaction_with_personal_finances  0.489749   0.006235  78.545
biological_sex                       0.045913   0.028707   1.599
immigrant_or_not                    -0.009008   0.073133  -0.123

Correlation of Fixed Effects:
            (Intr) sts___ blgcl_
stsfctn_w__ -0.142              
biologcl_sx -0.162  0.012       
immgrnt_r_n -0.281  0.009  0.002
# State-level estimates
round(coef(mlm_1)$country_code, digits = 3)
    (Intercept) satisfaction_with_personal_finances biological_sex
DEU       4.193                                0.49          0.046
IRQ       2.231                                0.49          0.046
JPN       3.722                                0.49          0.046
KEN       3.427                                0.49          0.046
LBY       4.717                                0.49          0.046
MEX       4.740                                0.49          0.046
MYS       3.871                                0.49          0.046
RUS       3.765                                0.49          0.046
USA       4.182                                0.49          0.046
    immigrant_or_not
DEU           -0.009
IRQ           -0.009
JPN           -0.009
KEN           -0.009
LBY           -0.009
MEX           -0.009
MYS           -0.009
RUS           -0.009
USA           -0.009
# Average estimates
round(fixef(mlm_1), digits = 3)
                        (Intercept) satisfaction_with_personal_finances 
                              3.872                               0.490 
                     biological_sex                    immigrant_or_not 
                              0.046                              -0.009 
# State-level errors
round(ranef(mlm_1)$country_code, digits = 3)
    (Intercept)
DEU       0.321
IRQ      -1.641
JPN      -0.149
KEN      -0.445
LBY       0.845
MEX       0.868
MYS      -0.001
RUS      -0.107
USA       0.310
# Standard errors
round(se.fixef(mlm_1), digits = 3)
                        (Intercept) satisfaction_with_personal_finances 
                              0.271                               0.006 
                     biological_sex                    immigrant_or_not 
                              0.029                               0.073 

Varying Intercept-Varying Slopes Model

mlm_2 <- lmer(satisfaction_with_life ~ satisfaction_with_personal_finances+biological_sex+immigrant_or_not +(1+satisfaction_with_personal_finances|country_code), data = wvs)
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.004838 (tol = 0.002, component 1)
summary(mlm_2)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ satisfaction_with_personal_finances +  
    biological_sex + immigrant_or_not + (1 + satisfaction_with_personal_finances |  
    country_code)
   Data: wvs

REML criterion at convergence: 52562

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-5.0771 -0.5165  0.0093  0.5529  3.7221 

Random effects:
 Groups       Name                                Variance Std.Dev. Corr 
 country_code (Intercept)                         2.96762  1.7227        
              satisfaction_with_personal_finances 0.03958  0.1989   -0.98
 Residual                                         2.68775  1.6394        
Number of obs: 13712, groups:  country_code, 9

Fixed effects:
                                    Estimate Std. Error t value
(Intercept)                          3.76290    0.58209   6.465
satisfaction_with_personal_finances  0.52905    0.06663   7.940
biological_sex                       0.04561    0.02814   1.621
immigrant_or_not                    -0.02406    0.07165  -0.336

Correlation of Fixed Effects:
            (Intr) sts___ blgcl_
stsfctn_w__ -0.966              
biologcl_sx -0.073  0.000       
immgrnt_r_n -0.129  0.001  0.001
optimizer (nloptwrap) convergence code: 0 (OK)
Model failed to converge with max|grad| = 0.004838 (tol = 0.002, component 1)
# State-level estimates
round(coef(mlm_2)$country_code, digits = 3)
    (Intercept) satisfaction_with_personal_finances biological_sex
DEU       4.693                               0.422          0.046
IRQ      -0.033                               0.999          0.046
JPN       3.041                               0.604          0.046
KEN       3.620                               0.456          0.046
LBY       5.426                               0.383          0.046
MEX       5.876                               0.325          0.046
MYS       3.291                               0.585          0.046
RUS       3.611                               0.521          0.046
USA       4.342                               0.466          0.046
    immigrant_or_not
DEU           -0.024
IRQ           -0.024
JPN           -0.024
KEN           -0.024
LBY           -0.024
MEX           -0.024
MYS           -0.024
RUS           -0.024
USA           -0.024
# Average estimates
round(fixef(mlm_2), digits = 3)
                        (Intercept) satisfaction_with_personal_finances 
                              3.763                               0.529 
                     biological_sex                    immigrant_or_not 
                              0.046                              -0.024 
# State-level errors
round(ranef(mlm_2)$country_code, digits = 3)
    (Intercept) satisfaction_with_personal_finances
DEU       0.930                              -0.107
IRQ      -3.796                               0.470
JPN      -0.722                               0.075
KEN      -0.143                              -0.073
LBY       1.663                              -0.146
MEX       2.113                              -0.204
MYS      -0.472                               0.056
RUS      -0.152                              -0.008
USA       0.579                              -0.063
# Standard errors
round(se.fixef(mlm_2), digits = 3)
                        (Intercept) satisfaction_with_personal_finances 
                              0.582                               0.067 
                     biological_sex                    immigrant_or_not 
                              0.028                               0.072 

Table

modelsummary::msummary(list(
  "VI Only" = mlm_1,
  "VIVS" = mlm_2), 
  coef_rename = c("satisfaction_with_personal_finances" = "Satisfaction with personal finances", 
                         "biological_sex" = "Biological sex",
                         "immigrant_or_not" = "Immigrant or not",
"SD (Intercept country_code)" = "Country RE Intercept SD",
"SD (satisfaction_with_personal_finances country_code)" = "Country RE Satisfaction with personal finances SD", 
"Cor (Intercept~satisfaction_with_personal_finances country_code)" = "Correlation RE Satisfaction with personal finances",
"SD (Observations)" ="Observations RE SD"))
VI Only VIVS
(Intercept) 3.872 3.763
(0.271) (0.582)
Satisfaction with personal finances 0.490 0.529
(0.006) (0.067)
Biological sex 0.046 0.046
(0.029) (0.028)
Immigrant or not -0.009 -0.024
(0.073) (0.072)
Country RE Intercept SD 0.759 1.723
Country RE Satisfaction with personal finances SD 0.199
Correlation RE Satisfaction with personal finances -0.978
Observations RE SD 1.675 1.639
Num.Obs. 13712 13712
R2 Marg. 0.294 0.333
R2 Cond. 0.414 0.455
AIC 53135.3 52578.0
BIC 53180.4 52638.2
ICC 0.2 0.2
RMSE 1.67 1.64

Interpretation

The Varying Intercept Model shows a “fixed effects” model where the relationship between people’s satisfaction with life and personal finances is assumed to be the same at different country levels. According to the results, when one level of people’s satisfaction with personal finance, people’s satisfaction with life will increase by 0.49. It also means that this model only measures one coefficient. However, the intercept, which predicts people’s satisfaction with life under the circumstance that people’s satisfaction with personal finance is zero, varies. When financial satisfaction equals zero, Mexico has the highest level of life satisfaction, which is 4.740, and Iraq has the lowest life satisfaction, which is 2.231. The average for the coefficient is 0.49, and the average for the intercept is 3.872. The average error is 0.006 for the coefficient and 0.271 for the intercept.

Varying Intercept, Varying Slopes Model allows Independent variables to influence dependent variables at different rates based on the different group levels that individual is in. In this case, people’s satisfaction with personal finance will influence their satisfaction with life based on the country they are in. Accordingly, when increasing one level of people’s satisfaction about their finances satisfaction, people from Iraq will increase the highest about their life satisfaction, which is 0.999, while Mexico will increase lower about their life satisfaction, which is 0.325. When financial satisfaction equals zero, Iraq people’s life satisfaction is lowest, which is -0.033, and Mexico people’s life satisfaction is highest, which is 5.876. The average for the coefficient is 0.529 and for the intercept is 3.763. The average error for the coefficient is 0.067 and for the intercept is 0.582.

Regarding the control variable sex and immigration status, the coefficient is solid in two models. About sex, in the Varying Intercept Model, the coefficient is solid at 0.046, which is the same for the Varying Intercept-Varying Slopes Model. Regarding immigration status, the coefficient for the Varying Intercept Model is -0.009, while for the Varying Intercept-Varying Slopes Model is -0.024.

Varying Slopes

mlm_slop <- lmer(satisfaction_with_life ~ satisfaction_with_personal_finances+biological_sex+immigrant_or_not +(0+satisfaction_with_personal_finances|country_code), data = wvs)
summary(mlm_slop)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ satisfaction_with_personal_finances +  
    biological_sex + immigrant_or_not + (0 + satisfaction_with_personal_finances |  
    country_code)
   Data: wvs

REML criterion at convergence: 53987.4

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-5.1393 -0.5521  0.0264  0.5620  3.3327 

Random effects:
 Groups       Name                                Variance Std.Dev.
 country_code satisfaction_with_personal_finances 0.01034  0.1017  
 Residual                                         2.98870  1.7288  
Number of obs: 13712, groups:  country_code, 9

Fixed effects:
                                    Estimate Std. Error t value
(Intercept)                          3.70890    0.09918  37.395
satisfaction_with_personal_finances  0.49721    0.03451  14.407
biological_sex                       0.04241    0.02963   1.431
immigrant_or_not                     0.06135    0.07508   0.817

Correlation of Fixed Effects:
            (Intr) sts___ blgcl_
stsfctn_w__ -0.075              
biologcl_sx -0.456  0.002       
immgrnt_r_n -0.789  0.003  0.001
# State-level estimates
round(coef(mlm_slop)$country_code, digits = 3)
    (Intercept) satisfaction_with_personal_finances biological_sex
DEU       3.709                               0.537          0.042
IRQ       3.709                               0.269          0.042
JPN       3.709                               0.496          0.042
KEN       3.709                               0.426          0.042
LBY       3.709                               0.603          0.042
MEX       3.709                               0.597          0.042
MYS       3.709                               0.512          0.042
RUS       3.709                               0.492          0.042
USA       3.709                               0.543          0.042
    immigrant_or_not
DEU            0.061
IRQ            0.061
JPN            0.061
KEN            0.061
LBY            0.061
MEX            0.061
MYS            0.061
RUS            0.061
USA            0.061

Interpretation

When the intercept is the same, or the life satisfaction baseline for each country is the same, increasing one level of financial satisfaction, Iraq has the lowest increase in life satisfaction, and Libya has the highest increase in life satisfaction.

Part 2

The next two models show adding the index GDP to see if it influences satisfaction with life. This variable will not vary at the individual level and may not be included in the regular regression mode.

Varying Intercept

mlm_3 <- lmer(satisfaction_with_life ~ satisfaction_with_personal_finances + biological_sex+ immigrant_or_not + scale(gdp_per_capita)+(1|country_code), data = wvs)
summary(mlm_3)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ satisfaction_with_personal_finances +  
    biological_sex + immigrant_or_not + scale(gdp_per_capita) +  
    (1 | country_code)
   Data: wvs

REML criterion at convergence: 53123.3

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-5.1919 -0.4928  0.1043  0.5081  3.6162 

Random effects:
 Groups       Name        Variance Std.Dev.
 country_code (Intercept) 0.5938   0.7706  
 Residual                 2.8055   1.6750  
Number of obs: 13712, groups:  country_code, 9

Fixed effects:
                                     Estimate Std. Error t value
(Intercept)                          3.914785   0.278750  14.044
satisfaction_with_personal_finances  0.489682   0.006236  78.530
biological_sex                       0.045905   0.028707   1.599
immigrant_or_not                    -0.009768   0.073139  -0.134
scale(gdp_per_capita)                0.237504   0.272225   0.872

Correlation of Fixed Effects:
            (Intr) sts___ blgcl_ immg__
stsfctn_w__ -0.140                     
biologcl_sx -0.158  0.012              
immgrnt_r_n -0.275  0.009  0.002       
scl(gdp_p_)  0.176 -0.011  0.000 -0.012
# State-level estimates
round(coef(mlm_3)$country_code, digits = 3)
    (Intercept) satisfaction_with_personal_finances biological_sex
DEU       3.943                                0.49          0.046
IRQ       2.495                                0.49          0.046
JPN       3.620                                0.49          0.046
KEN       3.770                                0.49          0.046
LBY       4.930                                0.49          0.046
MEX       4.900                                0.49          0.046
MYS       3.926                                0.49          0.046
RUS       3.825                                0.49          0.046
USA       3.824                                0.49          0.046
    immigrant_or_not scale(gdp_per_capita)
DEU            -0.01                 0.238
IRQ            -0.01                 0.238
JPN            -0.01                 0.238
KEN            -0.01                 0.238
LBY            -0.01                 0.238
MEX            -0.01                 0.238
MYS            -0.01                 0.238
RUS            -0.01                 0.238
USA            -0.01                 0.238
# Average estimates
round(fixef(mlm_3), digits = 3)
                        (Intercept) satisfaction_with_personal_finances 
                              3.915                               0.490 
                     biological_sex                    immigrant_or_not 
                              0.046                              -0.010 
              scale(gdp_per_capita) 
                              0.238 
# State-level errors
round(ranef(mlm_3)$country_code, digits = 3)
    (Intercept)
DEU       0.028
IRQ      -1.420
JPN      -0.295
KEN      -0.144
LBY       1.015
MEX       0.986
MYS       0.011
RUS      -0.090
USA      -0.091
# Standard errors
round(se.fixef(mlm_3), digits = 3)
                        (Intercept) satisfaction_with_personal_finances 
                              0.279                               0.006 
                     biological_sex                    immigrant_or_not 
                              0.029                               0.073 
              scale(gdp_per_capita) 
                              0.272 

Varying Intercept-Varying Slopes Model

mlm_4 <- lmer(satisfaction_with_life ~ satisfaction_with_personal_finances + biological_sex+ immigrant_or_not+ scale(gdp_per_capita)+(1+satisfaction_with_personal_finances|country_code), data = wvs)
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.00672541 (tol = 0.002, component 1)
summary(mlm_4)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ satisfaction_with_personal_finances +  
    biological_sex + immigrant_or_not + scale(gdp_per_capita) +  
    (1 + satisfaction_with_personal_finances | country_code)
   Data: wvs

REML criterion at convergence: 52564

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-5.0775 -0.5166  0.0092  0.5522  3.7222 

Random effects:
 Groups       Name                                Variance Std.Dev. Corr 
 country_code (Intercept)                         2.95067  1.718         
              satisfaction_with_personal_finances 0.03962  0.199    -0.97
 Residual                                         2.68774  1.639         
Number of obs: 13712, groups:  country_code, 9

Fixed effects:
                                    Estimate Std. Error t value
(Intercept)                          3.77233    0.58108   6.492
satisfaction_with_personal_finances  0.52898    0.06666   7.935
biological_sex                       0.04564    0.02814   1.622
immigrant_or_not                    -0.02460    0.07167  -0.343
scale(gdp_per_capita)                0.05006    0.13744   0.364

Correlation of Fixed Effects:
            (Intr) sts___ blgcl_ immg__
stsfctn_w__ -0.963                     
biologcl_sx -0.073  0.000              
immgrnt_r_n -0.130  0.001  0.001       
scl(gdp_p_)  0.046 -0.004  0.001 -0.022
optimizer (nloptwrap) convergence code: 0 (OK)
Model failed to converge with max|grad| = 0.00672541 (tol = 0.002, component 1)
# State-level estimates
round(coef(mlm_4)$country_code, digits = 3)
    (Intercept) satisfaction_with_personal_finances biological_sex
DEU       4.640                               0.422          0.046
IRQ       0.022                               0.999          0.046
JPN       3.019                               0.604          0.046
KEN       3.696                               0.454          0.046
LBY       5.470                               0.383          0.046
MEX       5.910                               0.325          0.046
MYS       3.303                               0.585          0.046
RUS       3.625                               0.521          0.046
USA       4.266                               0.467          0.046
    immigrant_or_not scale(gdp_per_capita)
DEU           -0.025                  0.05
IRQ           -0.025                  0.05
JPN           -0.025                  0.05
KEN           -0.025                  0.05
LBY           -0.025                  0.05
MEX           -0.025                  0.05
MYS           -0.025                  0.05
RUS           -0.025                  0.05
USA           -0.025                  0.05
# Average estimates
round(fixef(mlm_4), digits = 3)
                        (Intercept) satisfaction_with_personal_finances 
                              3.772                               0.529 
                     biological_sex                    immigrant_or_not 
                              0.046                              -0.025 
              scale(gdp_per_capita) 
                              0.050 
# State-level errors
round(ranef(mlm_4)$country_code, digits = 3)
    (Intercept) satisfaction_with_personal_finances
DEU       0.867                              -0.107
IRQ      -3.750                               0.470
JPN      -0.753                               0.075
KEN      -0.076                              -0.075
LBY       1.698                              -0.146
MEX       2.137                              -0.204
MYS      -0.469                               0.056
RUS      -0.147                              -0.008
USA       0.493                              -0.062
# Standard errors
round(se.fixef(mlm_4), digits = 3)
                        (Intercept) satisfaction_with_personal_finances 
                              0.581                               0.067 
                     biological_sex                    immigrant_or_not 
                              0.028                               0.072 
              scale(gdp_per_capita) 
                              0.137 

Table

modelsummary::msummary(list(
  "VI + GDP" = mlm_3,
  "VIVS+GDP" = mlm_4), coef_rename = c("satisfaction_with_personal_finances" = "Satisfaction with personal finances", 
                         "biological_sex" = "Biological sex",
                         "immigrant_or_not" = "Immigrant or not",
                         "scale(gdp_per_capita)"= "GDP per Capita",
"SD (Intercept country_code)" = "Country RE Intercept SD",
"SD (satisfaction_with_personal_finances country_code)" = "Country RE Satisfaction with personal finances SD", 
"Cor (Intercept~satisfaction_with_personal_finances country_code)" = "Correlation RE Satisfaction with personal finances",
"SD (Observations)" ="Observations RE SD"))
VI + GDP VIVS+GDP
(Intercept) 3.915 3.772
(0.279) (0.581)
Satisfaction with personal finances 0.490 0.529
(0.006) (0.067)
Biological sex 0.046 0.046
(0.029) (0.028)
Immigrant or not -0.010 -0.025
(0.073) (0.072)
GDP per Capita 0.238 0.050
(0.272) (0.137)
Country RE Intercept SD 0.771 1.718
Country RE Satisfaction with personal finances SD 0.199
Correlation RE Satisfaction with personal finances -0.975
Observations RE SD 1.675 1.639
Num.Obs. 13712 13712
R2 Marg. 0.313 0.335
R2 Cond. 0.433 0.458
AIC 53137.3 52582.0
BIC 53190.0 52649.8
ICC 0.2 0.2
RMSE 1.67 1.64

Interpretation

After adding the GDP index, for the Varying Intercept Model, Libya becomes the highest life satisfaction country when the people’s financial satisfaction is zero, and Iraq is still the country that has the lowest life satisfaction. For the Varying Intercept-Varying Slopes Model, when one level of financial satisfaction increases, Iraq is still the country that increases the most life satisfaction, which is 0.999, and Mexico is the country that increases least, which is 0.325.

Varying Slopes

mlm_slop_gdp <- lmer(satisfaction_with_life ~ satisfaction_with_personal_finances+biological_sex+immigrant_or_not+ scale(gdp_per_capita)+ +(0+satisfaction_with_personal_finances|country_code), data = wvs)
summary(mlm_slop_gdp)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ satisfaction_with_personal_finances +  
    biological_sex + immigrant_or_not + scale(gdp_per_capita) +  
    +(0 + satisfaction_with_personal_finances | country_code)
   Data: wvs

REML criterion at convergence: 53903.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-5.2066 -0.5360  0.0157  0.5721  3.5739 

Random effects:
 Groups       Name                                Variance Std.Dev.
 country_code satisfaction_with_personal_finances 0.00814  0.09022 
 Residual                                         2.97000  1.72337 
Number of obs: 13712, groups:  country_code, 9

Fixed effects:
                                    Estimate Std. Error t value
(Intercept)                         3.822679   0.099610  38.376
satisfaction_with_personal_finances 0.502217   0.030773  16.320
biological_sex                      0.038116   0.029543   1.290
immigrant_or_not                    0.004776   0.075085   0.064
scale(gdp_per_capita)               0.362682   0.038359   9.455

Correlation of Fixed Effects:
            (Intr) sts___ blgcl_ immg__
stsfctn_w__ -0.082                     
biologcl_sx -0.455  0.002              
immgrnt_r_n -0.790  0.002  0.002       
scl(gdp_p_)  0.122  0.017 -0.015 -0.080
# State-level estimates
round(coef(mlm_slop_gdp)$country_code, digits = 3)
    (Intercept) satisfaction_with_personal_finances biological_sex
DEU       3.823                               0.482          0.038
IRQ       3.823                               0.337          0.038
JPN       3.823                               0.466          0.038
KEN       3.823                               0.500          0.038
LBY       3.823                               0.639          0.038
MEX       3.823                               0.622          0.038
MYS       3.823                               0.517          0.038
RUS       3.823                               0.498          0.038
USA       3.823                               0.459          0.038
    immigrant_or_not scale(gdp_per_capita)
DEU            0.005                 0.363
IRQ            0.005                 0.363
JPN            0.005                 0.363
KEN            0.005                 0.363
LBY            0.005                 0.363
MEX            0.005                 0.363
MYS            0.005                 0.363
RUS            0.005                 0.363
USA            0.005                 0.363

Interpretation

After adding the GDP index, the Varying Slopes outcome is similar to the one that not adding the GDP index. The finding is increasing one level of financial satisfaction, Iraq has the lowest increase in life satisfaction, and Libya has the highest increase in life satisfaction.

Different Independent variables

This part measures another independent variable, health satisfaction.

Varying Intercept

mlm_5 <- lmer(satisfaction_with_life ~ personal_health_status + biological_sex+ immigrant_or_not +(1|country_code), data = wvs)
summary(mlm_5)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ personal_health_status + biological_sex +  
    immigrant_or_not + (1 | country_code)
   Data: wvs

REML criterion at convergence: 57327.4

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.1517 -0.6030  0.0644  0.6829  3.4961 

Random effects:
 Groups       Name        Variance Std.Dev.
 country_code (Intercept) 1.179    1.086   
 Residual                 3.708    1.926   
Number of obs: 13803, groups:  country_code, 9

Fixed effects:
                       Estimate Std. Error t value
(Intercept)             4.07878    0.38322  10.643
personal_health_status  0.73037    0.01944  37.572
biological_sex          0.06572    0.03291   1.997
immigrant_or_not       -0.11398    0.08386  -1.359

Correlation of Fixed Effects:
            (Intr) prsn__ blgcl_
prsnl_hlth_ -0.195              
biologcl_sx -0.136  0.032       
immgrnt_r_n -0.224 -0.013  0.002
# State-level estimates
round(coef(mlm_5)$country_code, digits = 3)
    (Intercept) personal_health_status biological_sex immigrant_or_not
DEU       5.035                   0.73          0.066           -0.114
IRQ       1.855                   0.73          0.066           -0.114
JPN       4.207                   0.73          0.066           -0.114
KEN       2.903                   0.73          0.066           -0.114
LBY       4.757                   0.73          0.066           -0.114
MEX       5.326                   0.73          0.066           -0.114
MYS       4.222                   0.73          0.066           -0.114
RUS       4.000                   0.73          0.066           -0.114
USA       4.404                   0.73          0.066           -0.114
mlm_6 <- lmer(satisfaction_with_life ~ personal_health_status + biological_sex+immigrant_or_not +(1+personal_health_status|country_code), data = wvs)
summary(mlm_6)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ personal_health_status + biological_sex +  
    immigrant_or_not + (1 + personal_health_status | country_code)
   Data: wvs

REML criterion at convergence: 57230.5

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.0690 -0.6151  0.0516  0.6920  3.2238 

Random effects:
 Groups       Name                   Variance Std.Dev. Corr 
 country_code (Intercept)            0.99871  0.9994        
              personal_health_status 0.04585  0.2141   -0.28
 Residual                            3.67731  1.9176        
Number of obs: 13803, groups:  country_code, 9

Fixed effects:
                       Estimate Std. Error t value
(Intercept)             4.11644    0.35681  11.537
personal_health_status  0.72568    0.07412   9.791
biological_sex          0.05627    0.03282   1.714
immigrant_or_not       -0.11440    0.08360  -1.368

Correlation of Fixed Effects:
            (Intr) prsn__ blgcl_
prsnl_hlth_ -0.313              
biologcl_sx -0.146  0.008       
immgrnt_r_n -0.241 -0.002  0.003
# State-level estimates
round(coef(mlm_6)$country_code, digits = 3)
    (Intercept) personal_health_status biological_sex immigrant_or_not
DEU       5.219                  0.685          0.056           -0.114
IRQ       3.097                  0.389          0.056           -0.114
JPN       3.661                  0.890          0.056           -0.114
KEN       3.823                  0.508          0.056           -0.114
LBY       4.739                  0.738          0.056           -0.114
MEX       5.980                  0.565          0.056           -0.114
MYS       3.337                  0.967          0.056           -0.114
RUS       3.697                  0.821          0.056           -0.114
USA       3.495                  0.968          0.056           -0.114
mlm_7 <- lmer(satisfaction_with_life ~ personal_health_status + biological_sex+ immigrant_or_not + scale(gdp_per_capita)+(1|country_code), data = wvs)
summary(mlm_7)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ personal_health_status + biological_sex +  
    immigrant_or_not + scale(gdp_per_capita) + (1 | country_code)
   Data: wvs

REML criterion at convergence: 57325.5

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.1514 -0.6029  0.0638  0.6826  3.4966 

Random effects:
 Groups       Name        Variance Std.Dev.
 country_code (Intercept) 1.020    1.010   
 Residual                 3.708    1.926   
Number of obs: 13803, groups:  country_code, 9

Fixed effects:
                       Estimate Std. Error t value
(Intercept)             4.17313    0.36492  11.436
personal_health_status  0.73053    0.01944  37.581
biological_sex          0.06572    0.03291   1.997
immigrant_or_not       -0.11509    0.08386  -1.372
scale(gdp_per_capita)   0.53434    0.35657   1.499

Correlation of Fixed Effects:
            (Intr) prsn__ blgcl_ immg__
prsnl_hlth_ -0.204                     
biologcl_sx -0.143  0.032              
immgrnt_r_n -0.237 -0.013  0.002       
scl(gdp_p_)  0.173  0.005  0.000 -0.010
# State-level estimates
round(coef(mlm_7)$country_code, digits = 3)
    (Intercept) personal_health_status biological_sex immigrant_or_not
DEU       4.469                  0.731          0.066           -0.115
IRQ       2.450                  0.731          0.066           -0.115
JPN       3.973                  0.731          0.066           -0.115
KEN       3.674                  0.731          0.066           -0.115
LBY       5.235                  0.731          0.066           -0.115
MEX       5.684                  0.731          0.066           -0.115
MYS       4.344                  0.731          0.066           -0.115
RUS       4.131                  0.731          0.066           -0.115
USA       3.597                  0.731          0.066           -0.115
    scale(gdp_per_capita)
DEU                 0.534
IRQ                 0.534
JPN                 0.534
KEN                 0.534
LBY                 0.534
MEX                 0.534
MYS                 0.534
RUS                 0.534
USA                 0.534
mlm_8 <- lmer(satisfaction_with_life ~ personal_health_status + biological_sex+ immigrant_or_not + scale(gdp_per_capita)+(1+personal_health_status|country_code), data = wvs)
summary(mlm_8)
Linear mixed model fit by REML ['lmerMod']
Formula: satisfaction_with_life ~ personal_health_status + biological_sex +  
    immigrant_or_not + scale(gdp_per_capita) + (1 + personal_health_status |  
    country_code)
   Data: wvs

REML criterion at convergence: 57230.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.0653 -0.6129  0.0517  0.6889  3.2280 

Random effects:
 Groups       Name                   Variance Std.Dev. Corr 
 country_code (Intercept)            1.25510  1.1203        
              personal_health_status 0.04594  0.2143   -0.46
 Residual                            3.67731  1.9176        
Number of obs: 13803, groups:  country_code, 9

Fixed effects:
                       Estimate Std. Error t value
(Intercept)             4.17571    0.39940  10.455
personal_health_status  0.72586    0.07419   9.784
biological_sex          0.05632    0.03282   1.716
immigrant_or_not       -0.11458    0.08360  -1.371
scale(gdp_per_capita)   0.33983    0.35259   0.964

Correlation of Fixed Effects:
            (Intr) prsn__ blgcl_ immg__
prsnl_hlth_ -0.466                     
biologcl_sx -0.130  0.008              
immgrnt_r_n -0.217 -0.002  0.003       
scl(gdp_p_)  0.152  0.005  0.001 -0.008
# State-level estimates
round(coef(mlm_8)$country_code, digits = 3)
    (Intercept) personal_health_status biological_sex immigrant_or_not
DEU       4.880                  0.679          0.056           -0.115
IRQ       3.458                  0.394          0.056           -0.115
JPN       3.509                  0.891          0.056           -0.115
KEN       4.297                  0.513          0.056           -0.115
LBY       5.050                  0.736          0.056           -0.115
MEX       6.234                  0.558          0.056           -0.115
MYS       3.397                  0.971          0.056           -0.115
RUS       3.775                  0.823          0.056           -0.115
USA       2.982                  0.967          0.056           -0.115
    scale(gdp_per_capita)
DEU                  0.34
IRQ                  0.34
JPN                  0.34
KEN                  0.34
LBY                  0.34
MEX                  0.34
MYS                  0.34
RUS                  0.34
USA                  0.34
modelsummary::msummary(list( "VI"=mlm_5,
  "VIVS"= mlm_6,
  "VI + GDP" = mlm_7,
  "VIVS+GDP" = mlm_8), coef_rename = c("personal_health_status" = "Personal health status", 
                         "biological_sex" = "Biological sex",
                         "immigrant_or_not" = "Immigrant or not",
                         "scale(gdp_per_capita)"= "GDP per Capita", 
"SD (Intercept country_code)" = "Country RE Intercept SD",
"SD (personal_health_status country_code)" = "Country RE Satisfaction with personal health SD", 
"Cor (Intercept~personal_health_status country_code)" = "Correlation RE Satisfaction with personal health",
"SD (Observations)" ="Observations RE SD"))
VI VIVS VI + GDP VIVS+GDP
(Intercept) 4.079 4.116 4.173 4.176
(0.383) (0.357) (0.365) (0.399)
Personal health status 0.730 0.726 0.731 0.726
(0.019) (0.074) (0.019) (0.074)
Biological sex 0.066 0.056 0.066 0.056
(0.033) (0.033) (0.033) (0.033)
Immigrant or not -0.114 -0.114 -0.115 -0.115
(0.084) (0.084) (0.084) (0.084)
GDP per Capita 0.534 0.340
(0.357) (0.353)
Country RE Intercept SD 1.086 0.999 1.010 1.120
Country RE Satisfaction with personal health SD 0.214 0.214
Correlation RE Satisfaction with personal health -0.283 -0.459
Observations RE SD 1.926 1.918 1.926 1.918
Num.Obs. 13803 13803 13803 13803
R2 Marg. 0.077 0.076 0.121 0.093
R2 Cond. 0.300 0.309 0.311 0.304
AIC 57339.4 57246.5 57339.5 57248.2
BIC 57384.6 57306.8 57392.2 57316.0
ICC 0.2 0.3 0.2 0.2
RMSE 1.92 1.92 1.92 1.92

Interpretation

Before adding the GDP indicator, in the Varying Intercept Model, the result is similar to financial satisfaction, which is that Iraq has the lowest life satisfaction and Mexico has the highest satisfaction. Things are interesting in the Varying Intercept, Varying Slopes Model. Americans have the highest increase in life satisfaction when increasing one level of health satisfaction, and Iraq is the country that has the lowest increase in life satisfaction when increasing one level of health satisfaction. When adding the GDP indicator, the result is the same as in the Varying Intercept Model before adding this indicator. In the Varying Intercept, Varying Slopes Model, Malaysia has the highest increase in life satisfaction when increasing one level of health satisfaction.

Conclusion

It is interesting to see that some developing countries, like Mexico, have high levels of life satisfaction and will not be impacted much when increase financial and health satisfaction. Accordingly, my hypothesis of use developing and developed countries to classify the level of life satisfaction. Besides, health satisfaction is a crucial indicator for the United States. After increasing it, the overall life satisfaction will be increased.

Reference

A Cheatsheet for Building Multilevel Models in R

Nested Models Power Point