Setup

Libraries

Minimum set of libraries

remove(list=ls())

library(readxl)
library(tidyverse)
library(labelled)
library(ggcorrplot)
library(gridExtra) 
library(GGally)
library(knitr)
library(kableExtra)
require(psych)
library(GPArotation)  
library(Hmisc)

require(lavaan)
require(lavaanPlot)
require(ResourceSelection)
require(semPlot)
require(tidySEM)
require(performance)
require(car)
library(semPlot)

Functions

Correlation, printing, and citing

corplot <- function(d, m = "pearson", sz = 2.5, title = NULL) {
  d_num  <- d %>% dplyr::select(where(is.numeric))
  if (ncol(d_num) < 2) return(NULL)
  mycorr <- cor(d_num, use = "pairwise.complete.obs", method = m)
  p.mat  <- ggcorrplot::cor_pmat(d_num)

  ggcorrplot(mycorr,
             hc.order  = TRUE,
             type      = "lower",
             colors    = c("red","white","green"),
             tl.cex    = 8,
             tl.col    = "black",
             lab       = TRUE,
             lab_size  = sz,
             p.mat     = p.mat,
             sig.level = 0.01,
             insig     = "pch",
             pch       = 4) +
    ggplot2::ggtitle(title %||% "")
}

myprint=function(x){x%>%kbl()%>%kable_classic(html_font = "Cambria")}

Data

# Import Data
raw_data <- read_excel("../data/raw/economic-freedom-of-the-world-2024-master-index-data-for-researchers-iso.xlsx",
                 sheet = "EFW Data 2024 Report", 
                 range = "B5:CH4790"
                 )
## New names:
## • `data` -> `data...9`
## • `data` -> `data...11`
## • `data` -> `data...13`
## • `data` -> `data...15`
## • `data` -> `data...17`
## • `data` -> `data...35`
## • `data` -> `data...37`
## • `data` -> `data...39`
## • `data` -> `data...44`
## • `data` -> `data...46`
## • `data` -> `data...48`
df <- raw_data
#names(df)
#str(df)

Data Cleaning

Area 1: Size of Government

  • 1A: Government consumption

  • 1B: Transfers and subsidies

  • 1C: Government investment

  • 1D: Top marginal tax rate

      i. 1Di: Top marginal income tax rate

      ii. 1Dii: Top marginal income and payroll tax rates

  • 1E: State ownership of assets

# --- Rename only Area 1 columns ---
df <- df %>%
  rename(
    `1A`          = `Government consumption`,                          # score
    `1A_data`     = `data...9`,                                         # underlying data

    `1B`          = `Transfers and subsidies`,                          # score
    `1B_data`     = `data...11`,                                        # underlying data

    `1C`          = `Government investment`,                            # score
    `1C_data`     = `data...13`,                                        # underlying data

    `1D_i`        = `Top marginal income tax rate`,                     # score
    `1D_i_data`   = `data...15`,                                        # underlying data

    `1D_ii`       = `Top marginal income and payroll tax rate`,         # score
    `1D_ii_data`  = `data...17`,                                        # underlying data

    `1D`          = `Top marginal tax rate`,                            # combined top rate
    `1E`          = `State ownership of Assets`,                        # score

    `Area1`       = `Size of Government`,                               # Area 1 summary score
    `Area1_rank`  = `Area 1 Rank`                                       # Area 1 rank
  )

# --- Attach labels so you keep the readable names ---
var_label(df$`1A`)         <- "Government consumption"
var_label(df$`1A_data`)    <- "Government consumption – data"

var_label(df$`1B`)         <- "Transfers and subsidies"
var_label(df$`1B_data`)    <- "Transfers and subsidies – data"

var_label(df$`1C`)         <- "Government investment"
var_label(df$`1C_data`)    <- "Government investment – data"

var_label(df$`1D_i`)       <- "Top marginal income tax rate"
var_label(df$`1D_i_data`)  <- "Top marginal income tax rate – data"

var_label(df$`1D_ii`)      <- "Top marginal income and payroll tax rate"
var_label(df$`1D_ii_data`) <- "Top marginal income and payroll tax rate – data"

var_label(df$`1D`)         <- "Top marginal tax rate (aggregate score)"
var_label(df$`1E`)         <- "State ownership of Assets"

var_label(df$Area1)        <- "Area 1: Size of Government (summary score)"
var_label(df$Area1_rank)   <- "Area 1 Rank"


#dplyr::glimpse(df)                  # see new names
#sapply(df[c("1A","1B","1C","1D","1E","Area1")], var_label)  # see labels

Area 3: Sound Money

df <- df %>%
  rename(
    `3A`      = `Money growth`,
    `3A_data` = `data...35`,
    `3B`      = `Standard deviation of inflation`,
    `3B_data` = `data...37`,
    `3C`      = `Inflation: Most recent year`,
    `3C_data` = `data...39`,
    `3D`      = `Freedom to own foreign currency bank accounts`,
    Area3      = `Sound Money`,
    Area3_rank = `Area 3 Rank`
  )

var_label(df$`3A`)      <- "Money growth"
var_label(df$`3A_data`) <- "Money growth – data"
var_label(df$`3B`)      <- "Standard deviation of inflation"
var_label(df$`3B_data`) <- "Standard deviation of inflation – data"
var_label(df$`3C`)      <- "Inflation: Most recent year"
var_label(df$`3C_data`) <- "Inflation: Most recent year – data"
var_label(df$`3D`)      <- "Freedom to own foreign currency bank accounts"
var_label(df$Area3)      <- "Area 3: Sound Money (summary score)"
var_label(df$Area3_rank) <- "Area 3: Rank"

Area 4: Freedom to Trade Internationally

df <- df %>%
  rename(
    `4A_i`      = `Revenue from trade taxes (% of trade sector)`,
    `4A_i_data` = `data...44`,
    `4A_ii`     = `Mean tariff rate`,
    `4A_ii_data`= `data...46`,
    `4A_iii`    = `Standard deviation of tariff rates`,
    `4A_iii_data`= `data...48`,
    `4A`        = `Tariffs`,
    `4B_i`      = `Non-tariff trade barriers`,
    `4B_ii`     = `Compliance costs of importing and exporting`,
    `4B`        = `Regulatory trade barriers`,
    `4C`        = `Black market exchange rates`,
    `4D_i`      = `Financial openness`,
    `4D_ii`     = `Capital controls`,
    `4D_iii`    = `Freedom of foreigners to visit`,
    `4D_iv`     = `Protection of foreign assets`,
    `4D`        = `Controls of the movement of capital and people`,
    Area4       = `Freedom to trade internationally`,
    Area4_rank  = `Area 4 Rank`
  )

var_label(df$`4A_i`)      <- "Revenue from trade taxes (% of trade sector)"
var_label(df$`4A_i_data`) <- "Revenue from trade taxes – data"
var_label(df$`4A_ii`)     <- "Mean tariff rate"
var_label(df$`4A_ii_data`)<- "Mean tariff rate – data"
var_label(df$`4A_iii`)    <- "Standard deviation of tariff rates"
var_label(df$`4A_iii_data`)<- "Standard deviation of tariff rates – data"
var_label(df$`4A`)        <- "Tariffs (aggregate score)"
var_label(df$`4B_i`)      <- "Non-tariff trade barriers"
var_label(df$`4B_ii`)     <- "Compliance costs of importing and exporting"
var_label(df$`4B`)        <- "Regulatory trade barriers (aggregate score)"
var_label(df$`4C`)        <- "Black market exchange rates"
var_label(df$`4D_i`)      <- "Financial openness"
var_label(df$`4D_ii`)     <- "Capital controls"
var_label(df$`4D_iii`)    <- "Freedom of foreigners to visit"
var_label(df$`4D_iv`)     <- "Protection of foreign assets"
var_label(df$`4D`)        <- "Controls of the movement of capital and people (aggregate score)"
var_label(df$Area4)       <- "Area 4: Freedom to trade internationally (summary score)"
var_label(df$Area4_rank)  <- "Area 4: Rank"

Area 5: Regulation

df <- df %>%
  rename(
    `5A_i`   = `Ownership of banks`,
    `5A_ii`  = `Private sector credit`,
    `5A_iii` = `Interest rate controls/negative real interest rates)`,
    `5A`     = `Credit market regulations`,
    `5B_i`   = `Hiring regulations and minimum wage`,
    `5B_ii`  = `Hiring and firing regulations`,
    `5B_iii` = `Centralized collective bargaining`,
    `5B_iv`  = `Hours Regulations`,
    `5B_v`   = `Mandated cost of worker dismissal`,
    `5B_vi`  = `Conscription`,
    `5B_vii` = `Foreign Labor`,
    `5B`     = `Labor market regulations`,
    `5C_i`   = `Regulatory Burden`,
    `5C_ii`  = `Bureacracy costs`,
    `5C_iii` = `Impartial Public Administration`,
    `5C_iv`  = `Tax compliance`,
    `5C`     = `Business regulations`,
    `5D_i`   = `Market openness`,
    `5D_ii`  = `Business Permits`,
    `5D_iii` = `Distorton of the business environment`,
    `5D`     = `Freedom to enter markets and compete`,
    Area5      = `Regulation`,
    Area5_rank = `Area 5 Rank`
  )

var_label(df$`5A_i`)   <- "Ownership of banks"
var_label(df$`5A_ii`)  <- "Private sector credit"
var_label(df$`5A_iii`) <- "Interest rate controls / negative real interest rates"
var_label(df$`5A`)     <- "Credit market regulations (aggregate score)"
var_label(df$`5B_i`)   <- "Hiring regulations and minimum wage"
var_label(df$`5B_ii`)  <- "Hiring and firing regulations"
var_label(df$`5B_iii`) <- "Centralized collective bargaining"
var_label(df$`5B_iv`)  <- "Hours Regulations"
var_label(df$`5B_v`)   <- "Mandated cost of worker dismissal"
var_label(df$`5B_vi`)  <- "Conscription"
var_label(df$`5B_vii`) <- "Foreign Labor"
var_label(df$`5B`)     <- "Labor market regulations (aggregate score)"
var_label(df$`5C_i`)   <- "Regulatory Burden"
var_label(df$`5C_ii`)  <- "Bureaucracy costs"
var_label(df$`5C_iii`) <- "Impartial Public Administration"
var_label(df$`5C_iv`)  <- "Tax compliance"
var_label(df$`5C`)     <- "Business regulations (aggregate score)"
var_label(df$`5D_i`)   <- "Market openness"
var_label(df$`5D_ii`)  <- "Business Permits"
var_label(df$`5D_iii`) <- "Distortion of the business environment"
var_label(df$`5D`)     <- "Freedom to enter markets and compete (aggregate score)"
var_label(df$Area5)      <- "Area 5: Regulation (summary score)"
var_label(df$Area5_rank) <- "Area 5: Rank"
library(writexl)

# export
write_xlsx(x = df, path = "economic_freedom_cleaned.xlsx")

Descriptive

Create scaled variables for models

str(df)
## tibble [4,785 × 86] (S3: tbl_df/tbl/data.frame)
##  $ Year                                                  : num [1:4785] 2022 2022 2022 2022 2022 ...
##  $ ISO Code 2                                            : chr [1:4785] "AL" "DZ" "AO" "AR" ...
##  $ ISO Code 3                                            : chr [1:4785] "ALB" "DZA" "AGO" "ARG" ...
##  $ Countries                                             : chr [1:4785] "Albania" "Algeria" "Angola" "Argentina" ...
##  $ Economic Freedom Summary Index                        : num [1:4785] 7.48 4.46 4.79 4.55 7.49 7.98 7.62 5.8 6.65 7.51 ...
##  $ Rank                                                  : num [1:4785] 38 161 155 159 36 9 23 128 81 34 ...
##  $ Quartile                                              : num [1:4785] 1 4 4 4 1 1 1 4 2 1 ...
##  $ 1A                                                    : num [1:4785] 8.28 3.49 7.94 6.17 7.06 ...
##   ..- attr(*, "label")= chr "Government consumption"
##  $ 1A_data                                               : num [1:4785] 11.8 28.1 13 19 16 ...
##   ..- attr(*, "label")= chr "Government consumption – data"
##  $ 1B                                                    : num [1:4785] 7.13 7.82 9.7 5.54 7.88 ...
##   ..- attr(*, "label")= chr "Transfers and subsidies"
##  $ 1B_data                                               : num [1:4785] 11.02 8.51 1.59 16.88 8.27 ...
##   ..- attr(*, "label")= chr "Transfers and subsidies – data"
##  $ 1C                                                    : num [1:4785] 7.55 4 7.74 8.7 8.98 ...
##   ..- attr(*, "label")= chr "Government investment"
##  $ 1C_data                                               : num [1:4785] 23.6 36 22.9 19.5 18.6 ...
##   ..- attr(*, "label")= chr "Government investment – data"
##  $ 1D_i                                                  : num [1:4785] 9 7 9 7 9 5 4 9 10 10 ...
##   ..- attr(*, "label")= chr "Top marginal income tax rate"
##  $ 1D_i_data                                             : chr [1:4785] "23" "35" "25" "35" ...
##   ..- attr(*, "label")= chr "Top marginal income tax rate – data"
##  $ 1D_ii                                                 : num [1:4785] 7 2 7 1 7 4 3 4 10 10 ...
##   ..- attr(*, "label")= chr "Top marginal income and payroll tax rate"
##  $ 1D_ii_data                                            : chr [1:4785] "34" "53" "33" "57" ...
##   ..- attr(*, "label")= chr "Top marginal income and payroll tax rate – data"
##  $ 1D                                                    : num [1:4785] 8 4.5 8 4 8 4.5 3.5 6.5 10 10 ...
##   ..- attr(*, "label")= chr "Top marginal tax rate (aggregate score)"
##  $ 1E                                                    : num [1:4785] 8.08 2.44 4.13 6.69 8.11 ...
##   ..- attr(*, "label")= chr "State ownership of Assets"
##  $ Area1                                                 : num [1:4785] 7.81 4.45 7.5 6.22 8.01 ...
##   ..- attr(*, "label")= chr "Area 1: Size of Government (summary score)"
##  $ Area1_rank                                            : num [1:4785] 24 162 36 111 20 117 147 159 3 41 ...
##   ..- attr(*, "label")= chr "Area 1 Rank"
##  $ 2A                                                    : num [1:4785] 4.61 4.01 3.81 4.84 4.56 ...
##   ..- attr(*, "label")= chr "Judicial independence"
##  $ 2B                                                    : num [1:4785] 4.68 3.02 2.93 4.26 4.68 ...
##   ..- attr(*, "label")= chr "Impartial courts"
##  $ 2C                                                    : num [1:4785] 4.42 5.06 3.39 4.79 5.45 ...
##   ..- attr(*, "label")= chr "Protection of property rights"
##  $ 2D                                                    : num [1:4785] 8.33 3.33 4.17 7.5 5 ...
##   ..- attr(*, "label")= chr "Military interference in rule of law and politics"
##  $ 2E                                                    : num [1:4785] 5.75 4.76 3.69 4.52 5.64 ...
##   ..- attr(*, "label")= chr "Integrity of the legal system"
##  $ 2F                                                    : num [1:4785] 3.65 2.84 1.15 3.38 4.29 ...
##   ..- attr(*, "label")= chr "Legal enforcement of contracts"
##  $ 2G                                                    : num [1:4785] 6.72 6.63 5.52 6.86 9.82 ...
##   ..- attr(*, "label")= chr "Regulatory restrictions on the sale of real property"
##  $ 2H                                                    : num [1:4785] 5.3 6.13 2.3 5.96 7.08 ...
##   ..- attr(*, "label")= chr "Reliability of police"
##  $ 2_adj                                                 : num [1:4785] 1 0.706 0.882 0.882 1 ...
##   ..- attr(*, "label")= chr "Gender Legal Rights Adjustment"
##  $ 2_wo_gen                                              : num [1:4785] 5.43 4.47 3.37 5.26 5.81 ...
##   ..- attr(*, "label")= chr "Legal System & Property Rights (without Gender Adjustment)"
##  $ 2_with_gen                                            : num [1:4785] 5.43 3.82 3.17 4.95 5.81 ...
##   ..- attr(*, "label")= chr "Legal System & Property Rights (with Gender Adjustment)"
##  $ Area2                                                 : num [1:4785] 5.43 3.82 3.17 4.95 5.81 ...
##   ..- attr(*, "label")= chr "Area 2: Legal System & Property Rights (summary score)"
##  $ Area2_rank                                            : num [1:4785] 66 127 145 85 56 9 10 91 68 75 ...
##   ..- attr(*, "label")= chr "Area 2: Rank"
##  $ 3A                                                    : num [1:4785] 9.48 8.68 7.52 0 8.54 ...
##   ..- attr(*, "label")= chr "Money growth"
##  $ 3A_data                                               : num [1:4785] 2.58 6.59 12.41 53.37 7.3 ...
##   ..- attr(*, "label")= chr "Money growth – data"
##  $ 3B                                                    : num [1:4785] 8.23 5.51 6.01 5.18 8.79 ...
##   ..- attr(*, "label")= chr "Standard deviation of inflation"
##  $ 3B_data                                               : num [1:4785] 4.42 11.23 9.97 12.05 3.01 ...
##   ..- attr(*, "label")= chr "Standard deviation of inflation – data"
##  $ 3C                                                    : num [1:4785] 7.31 6.29 1.46 0 6.54 ...
##   ..- attr(*, "label")= chr "Inflation: Most recent year"
##  $ 3C_data                                               : num [1:4785] 6.73 9.27 21.36 71.43 8.64 ...
##   ..- attr(*, "label")= chr "Inflation: Most recent year – data"
##  $ 3D                                                    : num [1:4785] 10 5 5 5 10 10 10 10 0 10 ...
##   ..- attr(*, "label")= chr "Freedom to own foreign currency bank accounts"
##  $ Area3                                                 : num [1:4785] 8.76 6.37 5 2.55 8.47 ...
##   ..- attr(*, "label")= chr "Area 3: Sound Money (summary score)"
##  $ Area3_rank                                            : num [1:4785] 28 123 147 162 46 23 49 127 131 12 ...
##   ..- attr(*, "label")= chr "Area 3: Rank"
##  $ 4A_i                                                  : num [1:4785] 9.65 8.48 9.39 4.21 9.56 ...
##   ..- attr(*, "label")= chr "Revenue from trade taxes (% of trade sector)"
##  $ 4A_i_data                                             : num [1:4785] 0.53 2.28 0.91 8.68 0.66 ...
##   ..- attr(*, "label")= chr "Revenue from trade taxes – data"
##  $ 4A_ii                                                 : num [1:4785] 9.28 6.22 7.8 7.34 8.74 9.52 8.98 8.36 3.5 9.1 ...
##   ..- attr(*, "label")= chr "Mean tariff rate"
##  $ 4A_ii_data                                            : num [1:4785] 3.6 18.9 11 13.3 6.3 2.4 5.1 8.2 32.5 4.5 ...
##   ..- attr(*, "label")= chr "Mean tariff rate – data"
##  $ 4A_iii                                                : num [1:4785] 8.08 5.84 3.71 5.85 8.21 ...
##   ..- attr(*, "label")= chr "Standard deviation of tariff rates"
##  $ 4A_iii_data                                           : num [1:4785] 4.79 10.39 15.73 10.37 4.47 ...
##   ..- attr(*, "label")= chr "Standard deviation of tariff rates – data"
##  $ 4A                                                    : num [1:4785] 9 6.85 6.97 5.8 8.84 ...
##   ..- attr(*, "label")= chr "Tariffs (aggregate score)"
##  $ 4B_i                                                  : num [1:4785] 8.4 2.92 3.6 4.23 4.09 ...
##   ..- attr(*, "label")= chr "Non-tariff trade barriers"
##  $ 4B_ii                                                 : num [1:4785] 9.405 0.479 2.515 5.65 9.315 ...
##   ..- attr(*, "label")= chr "Compliance costs of importing and exporting"
##  $ 4B                                                    : num [1:4785] 8.9 1.7 3.06 4.94 6.71 ...
##   ..- attr(*, "label")= chr "Regulatory trade barriers (aggregate score)"
##  $ 4C                                                    : num [1:4785] 10 2.17 0 2.17 10 ...
##   ..- attr(*, "label")= chr "Black market exchange rates"
##  $ 4D_i                                                  : num [1:4785] 4.02 1.46 2.5 2.66 7.94 ...
##   ..- attr(*, "label")= chr "Financial openness"
##  $ 4D_ii                                                 : num [1:4785] 4.615 0.769 1.538 0 5.385 ...
##   ..- attr(*, "label")= chr "Capital controls"
##  $ 4D_iii                                                : num [1:4785] 9.27 0.75 0 8.83 8.73 0.11 9.16 2.59 10 7.11 ...
##   ..- attr(*, "label")= chr "Freedom of foreigners to visit"
##  $ 4D_iv                                                 : num [1:4785] 6.9 4.33 3.38 4.37 5.05 ...
##   ..- attr(*, "label")= chr "Protection of foreign assets"
##  $ 4D                                                    : num [1:4785] 6.2 1.83 1.85 3.97 6.78 ...
##   ..- attr(*, "label")= chr "Controls of the movement of capital and people (aggregate score)"
##  $ Area4                                                 : num [1:4785] 8.53 3.14 2.97 4.22 8.08 ...
##   ..- attr(*, "label")= chr "Area 4: Freedom to trade internationally (summary score)"
##  $ Area4_rank                                            : num [1:4785] 34 161 164 155 56 52 26 85 145 45 ...
##   ..- attr(*, "label")= chr "Area 4: Rank"
##  $ 5A_i                                                  : num [1:4785] 10 0 5 5 10 10 8 5 10 10 ...
##   ..- attr(*, "label")= chr "Ownership of banks"
##  $ 5A_ii                                                 : num [1:4785] 7.59 6 10 6.07 9.06 ...
##   ..- attr(*, "label")= chr "Private sector credit"
##  $ 5A_iii                                                : num [1:4785] 9 5 9 0 10 10 10 5 10 10 ...
##   ..- attr(*, "label")= chr "Interest rate controls / negative real interest rates"
##  $ 5A                                                    : num [1:4785] 8.86 3.67 8 3.69 9.69 ...
##   ..- attr(*, "label")= chr "Credit market regulations (aggregate score)"
##  $ 5B_i                                                  : num [1:4785] 6.53 4.03 6.25 3.88 5.83 ...
##   ..- attr(*, "label")= chr "Hiring regulations and minimum wage"
##  $ 5B_ii                                                 : num [1:4785] 5.65 5.82 4.57 1.66 7.13 ...
##   ..- attr(*, "label")= chr "Hiring and firing regulations"
##  $ 5B_iii                                                : num [1:4785] 5.58 6.52 6.97 3.19 7.25 ...
##   ..- attr(*, "label")= chr "Centralized collective bargaining"
##  $ 5B_iv                                                 : num [1:4785] 8 6 4 10 10 10 6 6 8 8 ...
##   ..- attr(*, "label")= chr "Hours Regulations"
##  $ 5B_v                                                  : num [1:4785] 6.3 7.76 6.63 2.52 9.25 ...
##   ..- attr(*, "label")= chr "Mandated cost of worker dismissal"
##  $ 5B_vi                                                 : num [1:4785] 10 3 0 10 0 10 3 1 10 10 ...
##   ..- attr(*, "label")= chr "Conscription"
##  $ 5B_vii                                                : num [1:4785] 7.76 3.23 3.56 7.09 6.02 ...
##   ..- attr(*, "label")= chr "Foreign Labor"
##  $ 5B                                                    : num [1:4785] 7.12 5.19 4.57 5.48 6.5 ...
##   ..- attr(*, "label")= chr "Labor market regulations (aggregate score)"
##  $ 5C_i                                                  : num [1:4785] 5.65 4.22 2.94 2.71 5.17 ...
##   ..- attr(*, "label")= chr "Regulatory Burden"
##  $ 5C_ii                                                 : num [1:4785] 6.22 3.78 5.33 5.11 4.67 ...
##   ..- attr(*, "label")= chr "Bureaucracy costs"
##  $ 5C_iii                                                : num [1:4785] 6.06 2.61 4.86 7.55 6.41 ...
##   ..- attr(*, "label")= chr "Impartial Public Administration"
##  $ 5C_iv                                                 : num [1:4785] 3.59 4.76 4.64 4.5 6.02 ...
##   ..- attr(*, "label")= chr "Tax compliance"
##  $ 5C                                                    : num [1:4785] 5.38 3.84 4.44 4.97 5.57 ...
##   ..- attr(*, "label")= chr "Business regulations (aggregate score)"
##  $ 5D_i                                                  : num [1:4785] 6.81 4.64 3.43 6.14 5.59 ...
##   ..- attr(*, "label")= chr "Market openness"
##  $ 5D_ii                                                 : num [1:4785] 5.62 8.77 7.92 5.73 9.3 ...
##   ..- attr(*, "label")= chr "Business Permits"
##  $ 5D_iii                                                : num [1:4785] 6.25 2.58 1.25 3.38 5 ...
##   ..- attr(*, "label")= chr "Distortion of the business environment"
##  $ 5D                                                    : num [1:4785] 6.23 5.33 4.2 5.08 6.63 ...
##   ..- attr(*, "label")= chr "Freedom to enter markets and compete (aggregate score)"
##  $ Area5                                                 : num [1:4785] 6.9 4.51 5.3 4.8 7.1 ...
##   ..- attr(*, "label")= chr "Area 5: Regulation (summary score)"
##  $ Area5_rank                                            : num [1:4785] 55 156 140 148 45 6 40 107 30 21 ...
##   ..- attr(*, "label")= chr "Area 5: Rank"
##  $ World Bank Region                                     : chr [1:4785] "Europe & Central Asia" "Middle East & North Africa" "Sub-Saharan Africa" "Latin America & the Caribbean" ...
##  $ World Bank Current Income Classification, 1990-Present: chr [1:4785] "UM" "LM" "LM" "UM" ...
# Compute scaling factor
scaling_factor <- (1 + df$`2_adj`) / 2

# Create new scaled variables and assign descriptive names
df$`2A_scaled` <- df$`2A` / scaling_factor
label(df$`2A_scaled`) <- "Judicial independence*"

df$`2B_scaled` <- df$`2B` / scaling_factor
label(df$`2B_scaled`) <- "Impartial courts*"

df$`2C_scaled` <- df$`2C` / scaling_factor
label(df$`2C_scaled`) <- "Protection of property rights*"

df$`2D_scaled` <- df$`2D` / scaling_factor
label(df$`2D_scaled`) <- "Military interference in rule of law and politics*"

df$`2E_scaled` <- df$`2E` / scaling_factor
label(df$`2E_scaled`) <- "Integrity of the legal system *"

df$`2F_scaled` <- df$`2F` / scaling_factor
label(df$`2F_scaled`) <- "Legal enforcement of contracts*"

df$`2G_scaled` <- df$`2G` / scaling_factor
label(df$`2G_scaled`) <- "Regulatory restrictions on property*"

df$`2H_scaled` <- df$`2H` / scaling_factor
label(df$`2H_scaled`) <- "Reliability of police*"

Descriptive prior to normalizing (year 2022 only)

df_2022 <- df %>%
  filter(Year == 2022) %>%
  select(
    Year, Countries, `Economic Freedom Summary Index`, Rank,
    
    # Area 1
    `1A`, `1B`, `1C`, `1D_i`, `1D_ii`, `1D`, `1E`, Area1, Area1_rank,
    
    # Area 2
    `2A`, `2B`, `2C`, `2D`, `2E`, `2F`, `2G`, `2H`, `2_adj`, `2_wo_gen`, `2_with_gen`, Area2, Area2_rank,
    
    # Scaled variables from Area 2
    `2A_scaled`, `2B_scaled`, `2C_scaled`, `2D_scaled`, `2E_scaled`, `2F_scaled`, `2G_scaled`, `2H_scaled`,
    
    # Area 3
    `3A`, `3B`, `3C`, `3D`, Area3, Area3_rank,
    
    # Area 4
    `4A_i`, `4A_ii`, `4A_iii`, `4A`, `4B_i`, `4B_ii`, `4B`, `4C`,
    `4D_i`, `4D_ii`, `4D_iii`, `4D_iv`, `4D`, Area4, Area4_rank,
    
    # Area 5
    `5A_i`, `5A_ii`, `5A_iii`, `5A`,
    `5B_i`, `5B_ii`, `5B_iii`, `5B_iv`, `5B_v`, `5B_vi`, `5B_vii`, `5B`,
    `5C_i`, `5C_ii`, `5C_iii`, `5C_iv`, `5C`,
    `5D_i`, `5D_ii`, `5D_iii`, `5D`,
    Area5, Area5_rank
  )

# myprint(describe(mydata))

Clean Summary Stats Table

str(df_2022 )
## tibble [165 × 78] (S3: tbl_df/tbl/data.frame)
##  $ Year                          : num [1:165] 2022 2022 2022 2022 2022 ...
##  $ Countries                     : chr [1:165] "Albania" "Algeria" "Angola" "Argentina" ...
##  $ Economic Freedom Summary Index: num [1:165] 7.48 4.46 4.79 4.55 7.49 7.98 7.62 5.8 6.65 7.51 ...
##  $ Rank                          : num [1:165] 38 161 155 159 36 9 23 128 81 34 ...
##  $ 1A                            : num [1:165] 8.28 3.49 7.94 6.17 7.06 ...
##   ..- attr(*, "label")= chr "Government consumption"
##  $ 1B                            : num [1:165] 7.13 7.82 9.7 5.54 7.88 ...
##   ..- attr(*, "label")= chr "Transfers and subsidies"
##  $ 1C                            : num [1:165] 7.55 4 7.74 8.7 8.98 ...
##   ..- attr(*, "label")= chr "Government investment"
##  $ 1D_i                          : num [1:165] 9 7 9 7 9 5 4 9 10 10 ...
##   ..- attr(*, "label")= chr "Top marginal income tax rate"
##  $ 1D_ii                         : num [1:165] 7 2 7 1 7 4 3 4 10 10 ...
##   ..- attr(*, "label")= chr "Top marginal income and payroll tax rate"
##  $ 1D                            : num [1:165] 8 4.5 8 4 8 4.5 3.5 6.5 10 10 ...
##   ..- attr(*, "label")= chr "Top marginal tax rate (aggregate score)"
##  $ 1E                            : num [1:165] 8.08 2.44 4.13 6.69 8.11 ...
##   ..- attr(*, "label")= chr "State ownership of Assets"
##  $ Area1                         : num [1:165] 7.81 4.45 7.5 6.22 8.01 ...
##   ..- attr(*, "label")= chr "Area 1: Size of Government (summary score)"
##  $ Area1_rank                    : num [1:165] 24 162 36 111 20 117 147 159 3 41 ...
##   ..- attr(*, "label")= chr "Area 1 Rank"
##  $ 2A                            : num [1:165] 4.61 4.01 3.81 4.84 4.56 ...
##   ..- attr(*, "label")= chr "Judicial independence"
##  $ 2B                            : num [1:165] 4.68 3.02 2.93 4.26 4.68 ...
##   ..- attr(*, "label")= chr "Impartial courts"
##  $ 2C                            : num [1:165] 4.42 5.06 3.39 4.79 5.45 ...
##   ..- attr(*, "label")= chr "Protection of property rights"
##  $ 2D                            : num [1:165] 8.33 3.33 4.17 7.5 5 ...
##   ..- attr(*, "label")= chr "Military interference in rule of law and politics"
##  $ 2E                            : num [1:165] 5.75 4.76 3.69 4.52 5.64 ...
##   ..- attr(*, "label")= chr "Integrity of the legal system"
##  $ 2F                            : num [1:165] 3.65 2.84 1.15 3.38 4.29 ...
##   ..- attr(*, "label")= chr "Legal enforcement of contracts"
##  $ 2G                            : num [1:165] 6.72 6.63 5.52 6.86 9.82 ...
##   ..- attr(*, "label")= chr "Regulatory restrictions on the sale of real property"
##  $ 2H                            : num [1:165] 5.3 6.13 2.3 5.96 7.08 ...
##   ..- attr(*, "label")= chr "Reliability of police"
##  $ 2_adj                         : num [1:165] 1 0.706 0.882 0.882 1 ...
##   ..- attr(*, "label")= chr "Gender Legal Rights Adjustment"
##  $ 2_wo_gen                      : num [1:165] 5.43 4.47 3.37 5.26 5.81 ...
##   ..- attr(*, "label")= chr "Legal System & Property Rights (without Gender Adjustment)"
##  $ 2_with_gen                    : num [1:165] 5.43 3.82 3.17 4.95 5.81 ...
##   ..- attr(*, "label")= chr "Legal System & Property Rights (with Gender Adjustment)"
##  $ Area2                         : num [1:165] 5.43 3.82 3.17 4.95 5.81 ...
##   ..- attr(*, "label")= chr "Area 2: Legal System & Property Rights (summary score)"
##  $ Area2_rank                    : num [1:165] 66 127 145 85 56 9 10 91 68 75 ...
##   ..- attr(*, "label")= chr "Area 2: Rank"
##  $ 2A_scaled                     : 'labelled' num [1:165] 4.61 4.71 4.04 5.15 4.56 ...
##   ..- attr(*, "label")= chr "Judicial independence*"
##  $ 2B_scaled                     : 'labelled' num [1:165] 4.68 3.54 3.11 4.52 4.68 ...
##   ..- attr(*, "label")= chr "Impartial courts*"
##  $ 2C_scaled                     : 'labelled' num [1:165] 4.42 5.94 3.6 5.09 5.45 ...
##   ..- attr(*, "label")= chr "Protection of property rights*"
##  $ 2D_scaled                     : 'labelled' num [1:165] 8.33 3.91 4.43 7.97 5 ...
##   ..- attr(*, "label")= chr "Military interference in rule of law and politics*"
##  $ 2E_scaled                     : 'labelled' num [1:165] 5.75 5.58 3.93 4.81 5.64 ...
##   ..- attr(*, "label")= chr "Integrity of the legal system *"
##  $ 2F_scaled                     : 'labelled' num [1:165] 3.65 3.33 1.22 3.59 4.29 ...
##   ..- attr(*, "label")= chr "Legal enforcement of contracts*"
##  $ 2G_scaled                     : 'labelled' num [1:165] 6.72 7.77 5.87 7.29 9.82 ...
##   ..- attr(*, "label")= chr "Regulatory restrictions on property*"
##  $ 2H_scaled                     : 'labelled' num [1:165] 5.3 7.19 2.45 6.33 7.08 ...
##   ..- attr(*, "label")= chr "Reliability of police*"
##  $ 3A                            : num [1:165] 9.48 8.68 7.52 0 8.54 ...
##   ..- attr(*, "label")= chr "Money growth"
##  $ 3B                            : num [1:165] 8.23 5.51 6.01 5.18 8.79 ...
##   ..- attr(*, "label")= chr "Standard deviation of inflation"
##  $ 3C                            : num [1:165] 7.31 6.29 1.46 0 6.54 ...
##   ..- attr(*, "label")= chr "Inflation: Most recent year"
##  $ 3D                            : num [1:165] 10 5 5 5 10 10 10 10 0 10 ...
##   ..- attr(*, "label")= chr "Freedom to own foreign currency bank accounts"
##  $ Area3                         : num [1:165] 8.76 6.37 5 2.55 8.47 ...
##   ..- attr(*, "label")= chr "Area 3: Sound Money (summary score)"
##  $ Area3_rank                    : num [1:165] 28 123 147 162 46 23 49 127 131 12 ...
##   ..- attr(*, "label")= chr "Area 3: Rank"
##  $ 4A_i                          : num [1:165] 9.65 8.48 9.39 4.21 9.56 ...
##   ..- attr(*, "label")= chr "Revenue from trade taxes (% of trade sector)"
##  $ 4A_ii                         : num [1:165] 9.28 6.22 7.8 7.34 8.74 9.52 8.98 8.36 3.5 9.1 ...
##   ..- attr(*, "label")= chr "Mean tariff rate"
##  $ 4A_iii                        : num [1:165] 8.08 5.84 3.71 5.85 8.21 ...
##   ..- attr(*, "label")= chr "Standard deviation of tariff rates"
##  $ 4A                            : num [1:165] 9 6.85 6.97 5.8 8.84 ...
##   ..- attr(*, "label")= chr "Tariffs (aggregate score)"
##  $ 4B_i                          : num [1:165] 8.4 2.92 3.6 4.23 4.09 ...
##   ..- attr(*, "label")= chr "Non-tariff trade barriers"
##  $ 4B_ii                         : num [1:165] 9.405 0.479 2.515 5.65 9.315 ...
##   ..- attr(*, "label")= chr "Compliance costs of importing and exporting"
##  $ 4B                            : num [1:165] 8.9 1.7 3.06 4.94 6.71 ...
##   ..- attr(*, "label")= chr "Regulatory trade barriers (aggregate score)"
##  $ 4C                            : num [1:165] 10 2.17 0 2.17 10 ...
##   ..- attr(*, "label")= chr "Black market exchange rates"
##  $ 4D_i                          : num [1:165] 4.02 1.46 2.5 2.66 7.94 ...
##   ..- attr(*, "label")= chr "Financial openness"
##  $ 4D_ii                         : num [1:165] 4.615 0.769 1.538 0 5.385 ...
##   ..- attr(*, "label")= chr "Capital controls"
##  $ 4D_iii                        : num [1:165] 9.27 0.75 0 8.83 8.73 0.11 9.16 2.59 10 7.11 ...
##   ..- attr(*, "label")= chr "Freedom of foreigners to visit"
##  $ 4D_iv                         : num [1:165] 6.9 4.33 3.38 4.37 5.05 ...
##   ..- attr(*, "label")= chr "Protection of foreign assets"
##  $ 4D                            : num [1:165] 6.2 1.83 1.85 3.97 6.78 ...
##   ..- attr(*, "label")= chr "Controls of the movement of capital and people (aggregate score)"
##  $ Area4                         : num [1:165] 8.53 3.14 2.97 4.22 8.08 ...
##   ..- attr(*, "label")= chr "Area 4: Freedom to trade internationally (summary score)"
##  $ Area4_rank                    : num [1:165] 34 161 164 155 56 52 26 85 145 45 ...
##   ..- attr(*, "label")= chr "Area 4: Rank"
##  $ 5A_i                          : num [1:165] 10 0 5 5 10 10 8 5 10 10 ...
##   ..- attr(*, "label")= chr "Ownership of banks"
##  $ 5A_ii                         : num [1:165] 7.59 6 10 6.07 9.06 ...
##   ..- attr(*, "label")= chr "Private sector credit"
##  $ 5A_iii                        : num [1:165] 9 5 9 0 10 10 10 5 10 10 ...
##   ..- attr(*, "label")= chr "Interest rate controls / negative real interest rates"
##  $ 5A                            : num [1:165] 8.86 3.67 8 3.69 9.69 ...
##   ..- attr(*, "label")= chr "Credit market regulations (aggregate score)"
##  $ 5B_i                          : num [1:165] 6.53 4.03 6.25 3.88 5.83 ...
##   ..- attr(*, "label")= chr "Hiring regulations and minimum wage"
##  $ 5B_ii                         : num [1:165] 5.65 5.82 4.57 1.66 7.13 ...
##   ..- attr(*, "label")= chr "Hiring and firing regulations"
##  $ 5B_iii                        : num [1:165] 5.58 6.52 6.97 3.19 7.25 ...
##   ..- attr(*, "label")= chr "Centralized collective bargaining"
##  $ 5B_iv                         : num [1:165] 8 6 4 10 10 10 6 6 8 8 ...
##   ..- attr(*, "label")= chr "Hours Regulations"
##  $ 5B_v                          : num [1:165] 6.3 7.76 6.63 2.52 9.25 ...
##   ..- attr(*, "label")= chr "Mandated cost of worker dismissal"
##  $ 5B_vi                         : num [1:165] 10 3 0 10 0 10 3 1 10 10 ...
##   ..- attr(*, "label")= chr "Conscription"
##  $ 5B_vii                        : num [1:165] 7.76 3.23 3.56 7.09 6.02 ...
##   ..- attr(*, "label")= chr "Foreign Labor"
##  $ 5B                            : num [1:165] 7.12 5.19 4.57 5.48 6.5 ...
##   ..- attr(*, "label")= chr "Labor market regulations (aggregate score)"
##  $ 5C_i                          : num [1:165] 5.65 4.22 2.94 2.71 5.17 ...
##   ..- attr(*, "label")= chr "Regulatory Burden"
##  $ 5C_ii                         : num [1:165] 6.22 3.78 5.33 5.11 4.67 ...
##   ..- attr(*, "label")= chr "Bureaucracy costs"
##  $ 5C_iii                        : num [1:165] 6.06 2.61 4.86 7.55 6.41 ...
##   ..- attr(*, "label")= chr "Impartial Public Administration"
##  $ 5C_iv                         : num [1:165] 3.59 4.76 4.64 4.5 6.02 ...
##   ..- attr(*, "label")= chr "Tax compliance"
##  $ 5C                            : num [1:165] 5.38 3.84 4.44 4.97 5.57 ...
##   ..- attr(*, "label")= chr "Business regulations (aggregate score)"
##  $ 5D_i                          : num [1:165] 6.81 4.64 3.43 6.14 5.59 ...
##   ..- attr(*, "label")= chr "Market openness"
##  $ 5D_ii                         : num [1:165] 5.62 8.77 7.92 5.73 9.3 ...
##   ..- attr(*, "label")= chr "Business Permits"
##  $ 5D_iii                        : num [1:165] 6.25 2.58 1.25 3.38 5 ...
##   ..- attr(*, "label")= chr "Distortion of the business environment"
##  $ 5D                            : num [1:165] 6.23 5.33 4.2 5.08 6.63 ...
##   ..- attr(*, "label")= chr "Freedom to enter markets and compete (aggregate score)"
##  $ Area5                         : num [1:165] 6.9 4.51 5.3 4.8 7.1 ...
##   ..- attr(*, "label")= chr "Area 5: Regulation (summary score)"
##  $ Area5_rank                    : num [1:165] 55 156 140 148 45 6 40 107 30 21 ...
##   ..- attr(*, "label")= chr "Area 5: Rank"
# Step 1: Extract variable labels (fallback to variable name if missing)
# --- Create clean variable labels for df_2022 ---
lab_vec <- vapply(
  names(df_2022),
  function(n) {
    lb <- attr(df_2022[[n]], "label", exact = TRUE)

    if (is.null(lb) || is.na(lb) || lb == "") {
      return(n)
    }

    # Remove redundant repetition of variable name inside the label
    lb_clean <- sub(paste0("^", n, "\\s*[:\\-]?\\s*", collapse = ""), "", lb)

    # Output as "varname: cleaned label"
    paste0(n, ": ", lb_clean)
  },
  character(1)
)



# Step 2: Run describe() only on numeric columns
desc <- psych::describe(select(df_2022, where(is.numeric)), fast = FALSE)

# Step 3: Apply labels as rownames
rownames(desc) <- lab_vec[rownames(desc)]

# Step 4: Create final summary data.frame
desc_df <- desc %>%
  as.data.frame() %>%
  tibble::rownames_to_column("Variable") %>%
  select(Variable, n, mean, sd, min, max) %>%
  rename(
    N    = n,
    Mean = mean,
    SD   = sd,
    Min  = min,
    Max  = max
  )

# Step 5: Render as nicely formatted table
kable(
  desc_df,
  digits = 2,
  col.names = c("Variable", "N", "Mean", "SD", "Min", "Max"),
  align = "lccccc",
  caption = "Summary Statistics with Labels (Including Scaled Variables)"
) %>%
  kable_styling(full_width = FALSE, position = "center", font_size = 12)
Summary Statistics with Labels (Including Scaled Variables)
Variable N Mean SD Min Max
Year 165 2022.00 0.00 2022.00 2022.00
Economic Freedom Summary Index 165 6.53 1.05 3.02 8.58
Rank 165 82.78 47.80 1.00 165.00
1A: Government consumption 165 5.47 2.46 0.00 10.00
1B: Transfers and subsidies 156 7.53 2.05 1.82 10.00
1C: Government investment 161 7.12 3.28 0.00 10.00
1D_i: Top marginal income tax rate 165 7.47 2.19 2.00 10.00
1D_ii: Top marginal income and payroll tax rate 162 5.48 2.63 0.00 10.00
1D: Top marginal tax rate (aggregate score) 165 6.50 2.23 1.00 10.00
1E: State ownership of Assets 162 6.66 1.58 2.44 9.52
Area1: Area 1: Size of Government (summary score) 165 6.64 1.12 3.62 9.06
Area1_rank: Area 1 Rank 165 83.00 47.78 1.00 165.00
2A: Judicial independence 165 5.51 1.45 2.45 8.64
2B: Impartial courts 165 4.66 1.89 0.83 8.84
2C: Protection of property rights 165 5.44 2.16 0.00 9.67
2D: Military interference in rule of law and politics 138 6.29 2.66 0.00 10.00
2E: Integrity of the legal system 164 5.83 1.85 1.70 9.80
2F: Legal enforcement of contracts 165 3.97 1.98 0.00 8.73
2G: Regulatory restrictions on the sale of real property 163 7.59 1.52 2.67 9.98
2H: Reliability of police 165 5.21 2.42 0.00 9.77
2_adj: Gender Legal Rights Adjustment 165 0.87 0.17 0.29 1.00
2_wo_gen: Legal System & Property Rights (without Gender Adjustment) 165 5.53 1.66 1.98 9.10
2_with_gen: Legal System & Property Rights (with Gender Adjustment) 165 5.23 1.79 1.63 9.10
Area2: Area 2: Legal System & Property Rights (summary score) 165 5.23 1.79 1.63 9.10
Area2_rank: Area 2: Rank 165 83.00 47.78 1.00 165.00
2A_scaled: Judicial independence* 165 5.89 1.42 2.45 8.64
2B_scaled: Impartial courts* 165 4.95 1.88 1.00 8.84
2C_scaled: Protection of property rights* 165 5.78 2.15 0.00 9.93
2D_scaled: Military interference in rule of law and politics* 138 6.66 2.65 0.00 11.33
2E_scaled: Integrity of the legal system * 164 6.21 1.81 1.70 9.80
2F_scaled: Legal enforcement of contracts* 165 4.22 2.00 0.00 8.73
2G_scaled: Regulatory restrictions on property* 163 8.16 1.75 3.02 13.81
2H_scaled: Reliability of police* 165 5.55 2.59 0.00 12.13
3A: Money growth 163 8.24 1.61 0.00 9.98
3B: Standard deviation of inflation 165 7.65 2.52 0.00 9.74
3C: Inflation: Most recent year 165 5.88 2.61 0.00 9.46
3D: Freedom to own foreign currency bank accounts 165 7.15 3.95 0.00 10.00
Area3: Area 3: Sound Money (summary score) 165 7.23 1.71 0.74 9.55
Area3_rank: Area 3: Rank 165 82.99 47.77 1.00 165.00
4A_i: Revenue from trade taxes (% of trade sector) 156 8.63 1.47 3.33 10.00
4A_ii: Mean tariff rate 164 8.26 1.02 3.50 10.00
4A_iii: Standard deviation of tariff rates 165 6.06 2.13 0.00 10.00
4A: Tariffs (aggregate score) 165 7.62 1.18 3.92 10.00
4B_i: Non-tariff trade barriers 165 5.75 1.80 0.00 9.18
4B_ii: Compliance costs of importing and exporting 165 6.46 3.01 0.00 9.98
4B: Regulatory trade barriers (aggregate score) 165 6.11 2.11 1.69 9.41
4C: Black market exchange rates 165 9.22 2.47 0.00 10.00
4D_i: Financial openness 165 5.84 3.02 0.00 10.00
4D_ii: Capital controls 164 3.52 2.76 0.00 10.00
4D_iii: Freedom of foreigners to visit 165 7.10 3.38 0.00 10.00
4D_iv: Protection of foreign assets 165 5.73 2.10 0.00 9.27
4D: Controls of the movement of capital and people (aggregate score) 165 5.55 2.15 0.69 9.40
Area4: Area 4: Freedom to trade internationally (summary score) 165 7.12 1.49 2.48 9.66
Area4_rank: Area 4: Rank 165 83.00 47.78 1.00 165.00
5A_i: Ownership of banks 151 7.59 2.78 0.00 10.00
5A_ii: Private sector credit 162 7.39 2.53 0.00 10.00
5A_iii: Interest rate controls / negative real interest rates 163 8.35 2.27 0.00 10.00
5A: Credit market regulations (aggregate score) 164 7.74 1.63 0.00 10.00
5B_i: Hiring regulations and minimum wage 165 5.81 1.80 1.25 9.45
5B_ii: Hiring and firing regulations 165 5.64 1.97 0.00 10.00
5B_iii: Centralized collective bargaining 141 6.48 1.22 1.61 8.67
5B_iv: Hours Regulations 165 7.84 1.94 2.00 10.00
5B_v: Mandated cost of worker dismissal 162 6.49 2.83 0.00 10.00
5B_vi: Conscription 165 6.61 4.20 0.00 10.00
5B_vii: Foreign Labor 165 5.02 1.49 0.00 8.14
5B: Labor market regulations (aggregate score) 165 6.25 1.22 2.67 9.14
5C_i: Regulatory Burden 158 4.15 1.22 1.14 7.44
5C_ii: Bureaucracy costs 165 5.04 2.22 0.00 9.56
5C_iii: Impartial Public Administration 162 5.62 2.48 0.34 9.91
5C_iv: Tax compliance 165 5.90 1.92 0.00 9.87
5C: Business regulations (aggregate score) 165 5.17 1.55 0.60 9.05
5D_i: Market openness 165 6.07 1.80 1.24 10.00
5D_ii: Business Permits 161 8.39 1.14 4.98 10.00
5D_iii: Distortion of the business environment 165 5.20 2.29 0.00 10.00
5D: Freedom to enter markets and compete (aggregate score) 165 6.52 1.44 2.59 9.86
Area5: Area 5: Regulation (summary score) 165 6.41 1.13 2.54 8.86
Area5_rank: Area 5: Rank 165 83.00 47.78 1.00 165.00

Correlation plots by Area

# ---- Helper that ignores missing vars gracefully ----
sel_vars <- function(df_2022, vars) dplyr::select(df, dplyr::any_of(vars))

# ============
# GROUPS by Area (matches your current columns)
# ============

groups <- list(
  A1 = c("1A","1B","1C","1D_i","1D_ii","1D","1E","Area1"),
  A2 = c("2A","2B","2C","2D","2E","2F","2G","2H","2_adj","2_wo_gen","2_with_gen","Area2"),
  A2_scaled = c("2A_scaled","2B_scaled","2C_scaled","2D_scaled", "2E_scaled","2F_scaled","2G_scaled","2H_scaled", "Area2"),
  A3 = c("3A","3B","3C","3D","Area3"),
  A4 = c("4A_i","4A_ii","4A_iii","4A","4B_i","4B_ii","4B","4C","4D_i","4D_ii","4D_iii","4D_iv","4D","Area4"),
  A5 = c("5A_i","5A_ii","5A_iii","5A",
         "5B_i","5B_ii","5B_iii","5B_iv","5B_v","5B_vi","5B_vii","5B",
         "5C_i","5C_ii","5C_iii","5C_iv","5C",
         "5D_i","5D_ii","5D_iii","5D","Area5")
)

# Optional: keep rank columns for reference or plotting separately
ranks <- c("Area1_rank","Area2_rank","Area3_rank","Area4_rank","Area5_rank")

# ============
# EXAMPLE: build a 2x3 grid of correlation plots by Area
# (skips a plot if not enough numeric columns)
# ============

plots <- list(
  corplot(sel_vars(df_2002, groups$A1), title = "Area 1 (1A–1E + Area1)"),
  corplot(sel_vars(df_2002, groups$A2), title = "Area 2 (2A–2H + adj & summaries)"),
  corplot(sel_vars(df_2002, groups$A2_scaled), title = "Area 2 (scaled variables)"),
  corplot(sel_vars(df_2002, groups$A3), title = "Area 3 (3A–3D + Area3)"),
  corplot(sel_vars(df_2002, groups$A4), title = "Area 4 (4A–4D + Area4)"),
  corplot(sel_vars(df_2002, groups$A5), title = "Area 5 (5A–5D + Area5)")
)

# Drop NULLs (in case a group had <2 numeric vars)
plots <- Filter(Negate(is.null), plots)

# Arrange (2 columns looks small)
# if (length(plots) > 0) gridExtra::grid.arrange(grobs = plots, ncol = 1)

# Print each correlation plot separately
for (i in seq_along(plots)) {
  print(plots[[i]])
}

all_vars <- unique(unlist(groups))
plot_all <- corplot(sel_vars(df_2002, all_vars), sz = 2, title = "All Areas: indicators + Area summaries")
if (!is.null(plot_all)) print(plot_all)

KDE Pairs Plot 1

KDE Pairs of data - not evaluted for speeding computations

Normalize

Z-scores to adjust for magnitudes

# 1) drop overall index/ranks and Area summaries/ranks
df_2022_clean <- df_2022 %>%
  select(
    -`Economic Freedom Summary Index`,
    -Rank,
    -matches("^Area[1-5]$"),
    -matches("^Area[1-5]_rank$")
  )


# 2) standardize all numeric columns except Year (Countries is chr, so untouched)
num_cols <- df_2022_clean %>%
  select(where(is.numeric)) %>%
  names() %>%
  setdiff("Year")

df_2022_std <- df_2022_clean %>%
  mutate(across(all_of(num_cols), ~ as.numeric(scale(.))))

mydata_std has Year, Countries, all other numeric columns z-scored, labels preserved

Descriptive of Standardized Data

# 1. Rename variables to make them lavaan-safe (prepend "X")
df_2022_std <- df_2022_std %>%
  dplyr::rename_with(.fn = ~ paste0("X", .x), .cols = matches("^[0-9]"))

# names(mydata_std)[1:20] # check: now you have X1A, X1B, X1C, X1D_i, ...


# Step 2: Run describe() only on numeric columns
desc_std <- psych::describe(select(df_2022_std, where(is.numeric)), fast = FALSE)

# Step 4: Create final summary data.frame
desc_std_df <- desc_std %>%
  as.data.frame() %>%
  tibble::rownames_to_column("Variable") %>%
  select(Variable, n, mean, sd, min, max) %>%
  rename(
    N    = n,
    Mean = mean,
    SD   = sd,
    Min  = min,
    Max  = max
  )
# Note: labels are lost after renaming variables to lavaan-safe names

# Step 5: Render as nicely formatted table
kable(
  desc_std_df,
  digits = 2,
  col.names = c("Variable", "N", "Mean", "SD", "Min", "Max"),
  align = "lccccc",
  caption = "Summary Statistics with Labels (Including Scaled Variables)"
) %>%
  kable_styling(full_width = FALSE, position = "center", font_size = 12)
Summary Statistics with Labels (Including Scaled Variables)
Variable N Mean SD Min Max
Year 165 2022 0 2022.00 2022.00
X1A 165 0 1 -2.23 1.84
X1B 156 0 1 -2.78 1.20
X1C 161 0 1 -2.17 0.88
X1D_i 165 0 1 -2.49 1.15
X1D_ii 162 0 1 -2.08 1.72
X1D 165 0 1 -2.47 1.57
X1E 162 0 1 -2.68 1.81
X2A 165 0 1 -2.12 2.16
X2B 165 0 1 -2.03 2.22
X2C 165 0 1 -2.52 1.96
X2D 138 0 1 -2.37 1.39
X2E 164 0 1 -2.23 2.15
X2F 165 0 1 -2.00 2.40
X2G 163 0 1 -3.24 1.57
X2H 165 0 1 -2.15 1.89
X2_adj 165 0 1 -3.45 0.77
X2_wo_gen 165 0 1 -2.13 2.15
X2_with_gen 165 0 1 -2.01 2.16
X2A_scaled 165 0 1 -2.43 1.94
X2B_scaled 165 0 1 -2.10 2.08
X2C_scaled 165 0 1 -2.68 1.93
X2D_scaled 138 0 1 -2.51 1.76
X2E_scaled 164 0 1 -2.49 1.99
X2F_scaled 165 0 1 -2.11 2.26
X2G_scaled 163 0 1 -2.93 3.22
X2H_scaled 165 0 1 -2.14 2.54
X3A 163 0 1 -5.11 1.08
X3B 165 0 1 -3.04 0.83
X3C 165 0 1 -2.25 1.37
X3D 165 0 1 -1.81 0.72
X4A_i 156 0 1 -3.61 0.93
X4A_ii 164 0 1 -4.68 1.71
X4A_iii 165 0 1 -2.85 1.85
X4A 165 0 1 -3.15 2.02
X4B_i 165 0 1 -3.19 1.90
X4B_ii 165 0 1 -2.14 1.17
X4B 165 0 1 -2.09 1.57
X4C 165 0 1 -3.73 0.32
X4D_i 165 0 1 -1.94 1.38
X4D_ii 164 0 1 -1.28 2.35
X4D_iii 165 0 1 -2.10 0.86
X4D_iv 165 0 1 -2.73 1.69
X4D 165 0 1 -2.27 1.79
X5A_i 151 0 1 -2.73 0.87
X5A_ii 162 0 1 -2.92 1.03
X5A_iii 163 0 1 -3.68 0.73
X5A 164 0 1 -4.75 1.38
X5B_i 165 0 1 -2.54 2.02
X5B_ii 165 0 1 -2.87 2.21
X5B_iii 141 0 1 -3.99 1.80
X5B_iv 165 0 1 -3.01 1.11
X5B_v 162 0 1 -2.29 1.24
X5B_vi 165 0 1 -1.57 0.81
X5B_vii 165 0 1 -3.36 2.09
X5B 165 0 1 -2.93 2.36
X5C_i 158 0 1 -2.46 2.69
X5C_ii 165 0 1 -2.27 2.04
X5C_iii 162 0 1 -2.13 1.73
X5C_iv 165 0 1 -3.07 2.07
X5C 165 0 1 -2.95 2.51
X5D_i 165 0 1 -2.69 2.19
X5D_ii 161 0 1 -2.99 1.41
X5D_iii 165 0 1 -2.27 2.10
X5D 165 0 1 -2.73 2.33
# export
write_xlsx(x = df_2022_std, 
           path = "economic_freedom_cleaned_standardised.xlsx")

Models

CFA

Once the data has been normalized (see previous section), we build the models to test the assumption of equal weighting at three levels:

  1. Across the five Areas (Area 1–Area 5),

  2. Across the subcategories within each Area, and

  3. Across the individual indicators within each subcategory.

Equal/Current Model

equal_mod <- '
Economic_Freedom =~ Area1 + Area2 + Area3 + Area4 + Area5

Area1 =~ X1A + X1B + X1C + X1D + X1E

Area2 =~ X2A_scaled + X2B_scaled + X2C_scaled + X2D_scaled + X2E_scaled + X2F_scaled + X2G_scaled + X2H_scaled

Area3 =~ X3A + X3B + X3C + X3D

Area4 =~ X4A + X4B + X4C + X4D

Area5 =~ X5A + X5B + X5C + X5D
'


?cfa
## Help on topic 'cfa' was found in the following packages:
## 
##   Package               Library
##   sem                   /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
##   lavaan                /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
## 
## 
## Using the first match ...
fit_equal_mod <- cfa(model = equal_mod, 
           data = df_2022_std, 
           estimator = "MLR", 
           std.lv = TRUE, 
           missing = "fiml"
           )

summary(object = fit_equal_mod, 
        standardized = TRUE, 
        fit.measures = TRUE
        )
## lavaan 0.6-19 ended normally after 111 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        80
## 
##   Number of observations                           165
##   Number of missing patterns                        13
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                              1061.792     945.712
##   Degrees of freedom                               270         270
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.123
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                              3120.950    2735.681
##   Degrees of freedom                               300         300
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.141
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.719       0.723
##   Tucker-Lewis Index (TLI)                       0.688       0.692
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.727
##   Robust Tucker-Lewis Index (TLI)                            0.697
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -4741.476   -4741.476
##   Scaling correction factor                                  1.228
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)      -4210.580   -4210.580
##   Scaling correction factor                                  1.147
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                9642.951    9642.951
##   Bayesian (BIC)                              9891.427    9891.427
##   Sample-size adjusted Bayesian (SABIC)       9638.147    9638.147
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.133       0.123
##   90 Percent confidence interval - lower         0.125       0.115
##   90 Percent confidence interval - upper         0.142       0.131
##   P-value H_0: RMSEA <= 0.050                    0.000       0.000
##   P-value H_0: RMSEA >= 0.080                    1.000       1.000
##                                                                   
##   Robust RMSEA                                               0.131
##   90 Percent confidence interval - lower                     0.122
##   90 Percent confidence interval - upper                     0.141
##   P-value H_0: Robust RMSEA <= 0.050                         0.000
##   P-value H_0: Robust RMSEA >= 0.080                         1.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.121       0.121
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                       Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   Economic_Freedom =~                                                      
##     Area1               -1.290    0.432   -2.987    0.003   -0.790   -0.790
##     Area2                2.264    0.390    5.801    0.000    0.915    0.915
##     Area3                0.479    0.127    3.768    0.000    0.432    0.432
##     Area4                2.075    0.386    5.377    0.000    0.901    0.901
##     Area5                9.627   14.891    0.646    0.518    0.995    0.995
##   Area1 =~                                                                 
##     X1A                  0.307    0.075    4.082    0.000    0.502    0.503
##     X1B                  0.446    0.150    2.978    0.003    0.728    0.732
##     X1C                 -0.281    0.071   -3.949    0.000   -0.459   -0.461
##     X1D                  0.217    0.102    2.125    0.034    0.354    0.355
##     X1E                 -0.259    0.067   -3.857    0.000   -0.423   -0.425
##   Area2 =~                                                                 
##     X2A_scaled           0.348    0.056    6.192    0.000    0.861    0.863
##     X2B_scaled           0.385    0.055    6.997    0.000    0.953    0.955
##     X2C_scaled           0.359    0.050    7.146    0.000    0.887    0.890
##     X2D_scaled           0.291    0.043    6.711    0.000    0.720    0.735
##     X2E_scaled           0.351    0.051    6.893    0.000    0.869    0.873
##     X2F_scaled           0.320    0.045    7.079    0.000    0.793    0.795
##     X2G_scaled           0.076    0.037    2.041    0.041    0.187    0.188
##     X2H_scaled           0.310    0.049    6.277    0.000    0.766    0.769
##   Area3 =~                                                                 
##     X3A                  0.639    0.151    4.225    0.000    0.709    0.712
##     X3B                  0.457    0.108    4.217    0.000    0.507    0.509
##     X3C                  0.736    0.070   10.451    0.000    0.816    0.818
##     X3D                  0.108    0.080    1.352    0.176    0.120    0.120
##   Area4 =~                                                                 
##     X4A                  0.212    0.048    4.387    0.000    0.488    0.490
##     X4B                  0.374    0.062    6.064    0.000    0.862    0.865
##     X4C                  0.170    0.048    3.534    0.000    0.392    0.393
##     X4D                  0.360    0.053    6.811    0.000    0.828    0.831
##   Area5 =~                                                                 
##     X5A                  0.043    0.067    0.644    0.520    0.419    0.420
##     X5B                  0.054    0.082    0.658    0.511    0.521    0.523
##     X5C                  0.095    0.146    0.651    0.515    0.917    0.920
##     X5D                  0.083    0.127    0.653    0.514    0.801    0.803
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .X1A               0.000    0.078    0.000    1.000    0.000    0.000
##    .X1B               0.016    0.078    0.207    0.836    0.016    0.016
##    .X1C              -0.005    0.079   -0.060    0.952   -0.005   -0.005
##    .X1D               0.000    0.078    0.000    1.000    0.000    0.000
##    .X1E               0.001    0.078    0.008    0.994    0.001    0.001
##    .X2A_scaled       -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X2B_scaled       -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X2C_scaled       -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X2D_scaled       -0.061    0.080   -0.756    0.450   -0.061   -0.062
##    .X2E_scaled       -0.003    0.078   -0.035    0.972   -0.003   -0.003
##    .X2F_scaled       -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X2G_scaled       -0.002    0.078   -0.028    0.978   -0.002   -0.002
##    .X2H_scaled        0.000    0.078    0.000    1.000    0.000    0.000
##    .X3A               0.004    0.077    0.047    0.963    0.004    0.004
##    .X3B              -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X3C               0.000    0.078    0.000    1.000    0.000    0.000
##    .X3D              -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X4A              -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X4B               0.000    0.078    0.000    1.000    0.000    0.000
##    .X4C              -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X4D               0.000    0.078    0.000    1.000    0.000    0.000
##    .X5A              -0.005    0.078   -0.063    0.950   -0.005   -0.005
##    .X5B               0.000    0.078    0.000    1.000    0.000    0.000
##    .X5C              -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X5D              -0.000    0.078   -0.000    1.000   -0.000   -0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .X1A               0.742    0.123    6.048    0.000    0.742    0.747
##    .X1B               0.460    0.145    3.172    0.002    0.460    0.465
##    .X1C               0.782    0.093    8.411    0.000    0.782    0.788
##    .X1D               0.869    0.087    9.948    0.000    0.869    0.874
##    .X1E               0.813    0.099    8.255    0.000    0.813    0.819
##    .X2A_scaled        0.253    0.036    6.971    0.000    0.253    0.254
##    .X2B_scaled        0.087    0.019    4.508    0.000    0.087    0.087
##    .X2C_scaled        0.207    0.037    5.571    0.000    0.207    0.208
##    .X2D_scaled        0.442    0.053    8.293    0.000    0.442    0.461
##    .X2E_scaled        0.236    0.032    7.474    0.000    0.236    0.238
##    .X2F_scaled        0.365    0.048    7.669    0.000    0.365    0.368
##    .X2G_scaled        0.959    0.133    7.224    0.000    0.959    0.965
##    .X2H_scaled        0.407    0.056    7.204    0.000    0.407    0.409
##    .X3A               0.488    0.139    3.500    0.000    0.488    0.493
##    .X3B               0.737    0.148    4.978    0.000    0.737    0.741
##    .X3C               0.328    0.097    3.390    0.001    0.328    0.330
##    .X3D               0.980    0.091   10.752    0.000    0.980    0.985
##    .X4A               0.755    0.103    7.360    0.000    0.755    0.760
##    .X4B               0.251    0.050    4.983    0.000    0.251    0.252
##    .X4C               0.841    0.178    4.717    0.000    0.841    0.846
##    .X4D               0.308    0.054    5.745    0.000    0.308    0.309
##    .X5A               0.821    0.133    6.193    0.000    0.821    0.824
##    .X5B               0.722    0.080    9.079    0.000    0.722    0.727
##    .X5C               0.152    0.030    5.072    0.000    0.152    0.153
##    .X5D               0.352    0.054    6.480    0.000    0.352    0.355
##     Economic_Fredm    1.000                               1.000    1.000
##    .Area1             1.000                               0.375    0.375
##    .Area2             1.000                               0.163    0.163
##    .Area3             1.000                               0.813    0.813
##    .Area4             1.000                               0.189    0.189
##    .Area5             1.000                               0.011    0.011
# --- (Optional) factor scores for Areas and EFI ---
scores_equal_mod <- lavPredict(fit_equal_mod)   # matrix with Area1..Area5 and EFI scores
head(scores_equal_mod)
##      Economic_Freedom       Area1      Area2      Area3      Area4      Area5
## [1,]        0.1693968 -0.06153098 -0.5728420  0.6688394  1.4848666   1.620732
## [2,]       -1.1016796  1.21285791 -1.5696241 -0.1092653 -3.9504531 -10.627482
## [3,]       -1.2658848  2.04237700 -3.0676169 -1.4452406 -3.7176650 -11.938752
## [4,]       -0.5892202 -0.29831512 -0.8889231 -3.3572114 -1.8926603  -5.682556
## [5,]        0.1745439 -0.07445816 -0.4113683  0.3299082  0.8714919   1.786236
## [6,]        1.5077831 -2.07860552  4.2653192  0.7415639  2.3430630  14.621932
# --- (Optional) path diagram ---
lavaanPlot(model = fit_equal_mod, coefs = TRUE, covs = FALSE,
           graph_options = list(rankdir = "LR"),
           edge_options  = list(color = "grey40"))

Free Model

  • All individual indicators within each subcategory.
mod_free_mod <- '
Economic_Freedom =~ Area1 + Area2 + Area3 + Area4 + Area5


Area1 =~ X1A + X1B + X1C + X1D_i + X1D_ii + X1E

Area2 =~ X2A_scaled + X2B_scaled + X2C_scaled +  X2D_scaled + X2E_scaled + X2F_scaled + X2G_scaled + X2H_scaled 

Area3 =~ X3A + X3B + X3C + X3D

Area4 =~ X4A_i + X4A_ii + X4A_iii +
         X4B_i + X4B_ii +
         X4C +
         X4D_i + X4D_ii + X4D_iii + X4D_iv

Area5 =~ X5A_i + X5A_ii + X5A_iii +
         X5B_i + X5B_ii + X5B_iii + X5B_iv + X5B_v + X5B_vi + X5B_vii +
         X5C_i + X5C_ii + X5C_iii + X5C_iv +
         X5D_i + X5D_ii + X5D_iii
'


fit_free_mod <- cfa(mod_free_mod, 
                    data = df_2022_std, 
                    estimator = "MLR", 
                    std.lv = TRUE, 
                    missing = "fiml"
                    )

summary(object = fit_free_mod,
        standardized = TRUE, 
        fit.measures = TRUE
        )
## lavaan 0.6-19 ended normally after 125 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                       140
## 
##   Number of observations                           165
##   Number of missing patterns                        31
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                              3029.053    2863.543
##   Degrees of freedom                               940         940
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.058
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                              6008.987    5603.398
##   Degrees of freedom                               990         990
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.072
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.584       0.583
##   Tucker-Lewis Index (TLI)                       0.562       0.561
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.589
##   Robust Tucker-Lewis Index (TLI)                            0.567
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -8849.971   -8849.971
##   Scaling correction factor                                  1.204
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)      -7335.445   -7335.445
##   Scaling correction factor                                  1.077
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                               17979.942   17979.942
##   Bayesian (BIC)                             18414.774   18414.774
##   Sample-size adjusted Bayesian (SABIC)      17971.534   17971.534
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.116       0.111
##   90 Percent confidence interval - lower         0.111       0.107
##   90 Percent confidence interval - upper         0.121       0.116
##   P-value H_0: RMSEA <= 0.050                    0.000       0.000
##   P-value H_0: RMSEA >= 0.080                    1.000       1.000
##                                                                   
##   Robust RMSEA                                               0.115
##   90 Percent confidence interval - lower                     0.110
##   90 Percent confidence interval - upper                     0.121
##   P-value H_0: Robust RMSEA <= 0.050                         0.000
##   P-value H_0: Robust RMSEA >= 0.080                         1.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.117       0.117
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                       Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   Economic_Freedom =~                                                      
##     Area1               -1.058    0.292   -3.623    0.000   -0.727   -0.727
##     Area2                1.849    0.278    6.655    0.000    0.880    0.880
##     Area3                0.470    0.127    3.689    0.000    0.425    0.425
##     Area4                2.488    0.540    4.611    0.000    0.928    0.928
##     Area5                5.182    2.654    1.952    0.051    0.982    0.982
##   Area1 =~                                                                 
##     X1A                  0.299    0.068    4.418    0.000    0.436    0.437
##     X1B                  0.523    0.101    5.186    0.000    0.761    0.766
##     X1C                 -0.316    0.064   -4.937    0.000   -0.460   -0.461
##     X1D_i                0.324    0.120    2.705    0.007    0.472    0.474
##     X1D_ii               0.302    0.125    2.414    0.016    0.440    0.442
##     X1E                 -0.305    0.070   -4.357    0.000   -0.445   -0.446
##   Area2 =~                                                                 
##     X2A_scaled           0.410    0.053    7.698    0.000    0.861    0.864
##     X2B_scaled           0.453    0.050    9.138    0.000    0.953    0.956
##     X2C_scaled           0.424    0.044    9.719    0.000    0.891    0.894
##     X2D_scaled           0.341    0.042    8.177    0.000    0.717    0.731
##     X2E_scaled           0.411    0.049    8.436    0.000    0.865    0.869
##     X2F_scaled           0.378    0.041    9.149    0.000    0.794    0.796
##     X2G_scaled           0.089    0.042    2.135    0.033    0.188    0.189
##     X2H_scaled           0.364    0.046    7.853    0.000    0.764    0.767
##   Area3 =~                                                                 
##     X3A                  0.643    0.152    4.245    0.000    0.711    0.714
##     X3B                  0.460    0.109    4.226    0.000    0.508    0.510
##     X3C                  0.735    0.069   10.636    0.000    0.813    0.815
##     X3D                  0.112    0.081    1.389    0.165    0.124    0.124
##   Area4 =~                                                                 
##     X4A_i                0.211    0.051    4.145    0.000    0.566    0.568
##     X4A_ii               0.244    0.057    4.289    0.000    0.653    0.656
##     X4A_iii              0.061    0.033    1.835    0.066    0.164    0.165
##     X4B_i                0.304    0.061    4.983    0.000    0.814    0.817
##     X4B_ii               0.256    0.047    5.483    0.000    0.686    0.688
##     X4C                  0.138    0.041    3.377    0.001    0.371    0.372
##     X4D_i                0.331    0.065    5.118    0.000    0.887    0.890
##     X4D_ii               0.189    0.050    3.793    0.000    0.507    0.509
##     X4D_iii              0.145    0.038    3.796    0.000    0.388    0.389
##     X4D_iv               0.328    0.057    5.709    0.000    0.879    0.882
##   Area5 =~                                                                 
##     X5A_i                0.070    0.038    1.850    0.064    0.370    0.370
##     X5A_ii               0.037    0.022    1.680    0.093    0.197    0.197
##     X5A_iii              0.033    0.023    1.418    0.156    0.174    0.175
##     X5B_i                0.078    0.045    1.728    0.084    0.410    0.411
##     X5B_ii               0.100    0.056    1.791    0.073    0.527    0.528
##     X5B_iii              0.029    0.025    1.172    0.241    0.155    0.155
##     X5B_iv               0.016    0.018    0.872    0.383    0.082    0.083
##     X5B_v                0.066    0.037    1.769    0.077    0.348    0.349
##     X5B_vi               0.024    0.019    1.241    0.215    0.125    0.125
##     X5B_vii              0.118    0.062    1.908    0.056    0.625    0.627
##     X5C_i                0.076    0.039    1.977    0.048    0.402    0.402
##     X5C_ii               0.152    0.073    2.102    0.036    0.805    0.807
##     X5C_iii              0.135    0.063    2.142    0.032    0.714    0.718
##     X5C_iv               0.132    0.066    2.001    0.045    0.695    0.697
##     X5D_i                0.161    0.082    1.968    0.049    0.848    0.851
##     X5D_ii               0.041    0.027    1.480    0.139    0.214    0.215
##     X5D_iii              0.146    0.077    1.888    0.059    0.770    0.772
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .X1A               0.000    0.078    0.000    1.000    0.000    0.000
##    .X1B               0.017    0.078    0.219    0.827    0.017    0.017
##    .X1C              -0.006    0.079   -0.072    0.942   -0.006   -0.006
##    .X1D_i             0.000    0.078    0.000    1.000    0.000    0.000
##    .X1D_ii            0.007    0.079    0.087    0.931    0.007    0.007
##    .X1E              -0.002    0.079   -0.026    0.979   -0.002   -0.002
##    .X2A_scaled       -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X2B_scaled       -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X2C_scaled       -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X2D_scaled       -0.063    0.081   -0.784    0.433   -0.063   -0.064
##    .X2E_scaled       -0.003    0.078   -0.038    0.970   -0.003   -0.003
##    .X2F_scaled       -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X2G_scaled       -0.002    0.078   -0.028    0.978   -0.002   -0.002
##    .X2H_scaled       -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X3A               0.004    0.077    0.048    0.961    0.004    0.004
##    .X3B              -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X3C              -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X3D              -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X4A_i            -0.024    0.081   -0.291    0.771   -0.024   -0.024
##    .X4A_ii           -0.001    0.078   -0.016    0.987   -0.001   -0.001
##    .X4A_iii          -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X4B_i            -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X4B_ii           -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X4C              -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X4D_i            -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X4D_ii            0.003    0.078    0.038    0.969    0.003    0.003
##    .X4D_iii          -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X4D_iv           -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X5A_i            -0.028    0.084   -0.334    0.739   -0.028   -0.028
##    .X5A_ii           -0.005    0.079   -0.058    0.954   -0.005   -0.005
##    .X5A_iii          -0.003    0.079   -0.044    0.965   -0.003   -0.003
##    .X5B_i            -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X5B_ii           -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X5B_iii          -0.020    0.081   -0.252    0.801   -0.020   -0.020
##    .X5B_iv           -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X5B_v            -0.007    0.079   -0.095    0.924   -0.007   -0.008
##    .X5B_vi           -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X5B_vii          -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X5C_i            -0.020    0.079   -0.248    0.804   -0.020   -0.020
##    .X5C_ii           -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X5C_iii           0.003    0.078    0.036    0.971    0.003    0.003
##    .X5C_iv           -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X5D_i            -0.000    0.078   -0.000    1.000   -0.000   -0.000
##    .X5D_ii           -0.009    0.079   -0.108    0.914   -0.009   -0.009
##    .X5D_iii          -0.000    0.078   -0.000    1.000   -0.000   -0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .X1A               0.804    0.129    6.239    0.000    0.804    0.809
##    .X1B               0.408    0.105    3.890    0.000    0.408    0.413
##    .X1C               0.781    0.089    8.758    0.000    0.781    0.787
##    .X1D_i             0.771    0.108    7.162    0.000    0.771    0.776
##    .X1D_ii            0.800    0.101    7.948    0.000    0.800    0.805
##    .X1E               0.794    0.096    8.273    0.000    0.794    0.801
##    .X2A_scaled        0.252    0.036    6.963    0.000    0.252    0.254
##    .X2B_scaled        0.086    0.020    4.352    0.000    0.086    0.087
##    .X2C_scaled        0.200    0.038    5.306    0.000    0.200    0.201
##    .X2D_scaled        0.448    0.054    8.282    0.000    0.448    0.465
##    .X2E_scaled        0.243    0.032    7.592    0.000    0.243    0.245
##    .X2F_scaled        0.364    0.048    7.609    0.000    0.364    0.366
##    .X2G_scaled        0.959    0.132    7.238    0.000    0.959    0.964
##    .X2H_scaled        0.410    0.057    7.161    0.000    0.410    0.412
##    .X3A               0.485    0.138    3.525    0.000    0.485    0.490
##    .X3B               0.735    0.148    4.954    0.000    0.735    0.740
##    .X3C               0.334    0.094    3.550    0.000    0.334    0.336
##    .X3D               0.979    0.091   10.704    0.000    0.979    0.985
##    .X4A_i             0.674    0.120    5.638    0.000    0.674    0.678
##    .X4A_ii            0.565    0.117    4.815    0.000    0.565    0.569
##    .X4A_iii           0.967    0.154    6.293    0.000    0.967    0.973
##    .X4B_i             0.331    0.058    5.715    0.000    0.331    0.333
##    .X4B_ii            0.524    0.069    7.574    0.000    0.524    0.527
##    .X4C               0.856    0.185    4.624    0.000    0.856    0.861
##    .X4D_i             0.207    0.041    5.006    0.000    0.207    0.208
##    .X4D_ii            0.737    0.103    7.119    0.000    0.737    0.741
##    .X4D_iii           0.843    0.084   10.013    0.000    0.843    0.849
##    .X4D_iv            0.221    0.040    5.464    0.000    0.221    0.222
##    .X5A_i             0.860    0.092    9.359    0.000    0.860    0.863
##    .X5A_ii            0.956    0.138    6.922    0.000    0.956    0.961
##    .X5A_iii           0.964    0.153    6.313    0.000    0.964    0.969
##    .X5B_i             0.826    0.086    9.597    0.000    0.826    0.831
##    .X5B_ii            0.716    0.081    8.856    0.000    0.716    0.721
##    .X5B_iii           0.970    0.180    5.402    0.000    0.970    0.976
##    .X5B_iv            0.987    0.107    9.255    0.000    0.987    0.993
##    .X5B_v             0.877    0.089    9.839    0.000    0.877    0.879
##    .X5B_vi            0.978    0.056   17.487    0.000    0.978    0.984
##    .X5B_vii           0.603    0.083    7.227    0.000    0.603    0.607
##    .X5C_i             0.837    0.091    9.161    0.000    0.837    0.838
##    .X5C_ii            0.347    0.041    8.400    0.000    0.347    0.349
##    .X5C_iii           0.478    0.069    6.886    0.000    0.478    0.484
##    .X5C_iv            0.511    0.067    7.599    0.000    0.511    0.514
##    .X5D_i             0.275    0.042    6.468    0.000    0.275    0.276
##    .X5D_ii            0.950    0.127    7.493    0.000    0.950    0.954
##    .X5D_iii           0.401    0.068    5.860    0.000    0.401    0.404
##     Economic_Fredm    1.000                               1.000    1.000
##    .Area1             1.000                               0.472    0.472
##    .Area2             1.000                               0.226    0.226
##    .Area3             1.000                               0.819    0.819
##    .Area4             1.000                               0.139    0.139
##    .Area5             1.000                               0.036    0.036
# --- (Optional) factor scores for Areas and EFI ---
scores_free_mod <- lavPredict(fit_free_mod)   # matrix with Area1..Area5 and EFI scores
head(scores_free_mod)
##      Economic_Freedom      Area1      Area2      Area3      Area4      Area5
## [1,]        0.3142640 -0.0285082 -0.5016252  0.6867110  1.2853752  1.8469396
## [2,]       -1.1293803  0.8222416 -1.2781262 -0.1126493 -3.8907686 -5.9546947
## [3,]       -1.2837399  1.8067887 -2.6025663 -1.4339128 -3.5706036 -6.4708314
## [4,]       -0.6547537 -0.6176454 -0.7422474 -3.3720247 -2.6824339 -3.1704754
## [5,]        0.1035932  0.1123482 -0.4098862  0.3209719  0.4793034  0.6856501
## [6,]        1.4546878 -1.7654570  3.6350048  0.7300353  3.0872796  7.6868876
# --- (Optional) path diagram ---
lavaanPlot(model = fit_free_mod, coefs = TRUE, covs = FALSE,
           graph_options = list(rankdir = "LR"),
           edge_options  = list(color = "grey40"))

Free vs Equal Model

Ideally, we would like to check/show that the equal model of EFI is significantly worse than free model.

#summary(fit_free_mod,  standardized = TRUE, fit.measures = TRUE)
#summary(fit_equal_mod, standardized = TRUE, fit.measures = TRUE)

anova(fit_equal_mod, fit_free_mod)
## Warning: lavaan->lavTestLRT():  
##    some models are based on a different set of observed variables
## 
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
## 
## lavaan->lavTestLRT():  
##    lavaan NOTE: The "Chisq" column contains standard test statistics, not the 
##    robust test that should be reported per model. A robust difference test is 
##    a function of two standard (not robust) statistics.
##                Df   AIC     BIC  Chisq Chisq diff Df diff Pr(>Chisq)    
## fit_equal_mod 270  9643  9891.4 1061.8                                  
## fit_free_mod  940 17980 18414.8 3029.1       1907     670  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(lavaan)
library(dplyr)
library(semPlot)


# --- Model definitions ------------------------------------------------------
mod_5areas <- '
  Economic_Freedom =~ Area1 + Area2 + Area3 + Area4 + Area5

  Area1 =~ X1A + X1B + X1C + X1D_i + X1D_ii + X1E
  Area2 =~ X2A_scaled + X2B_scaled + X2C_scaled + X2D_scaled +
           X2E_scaled + X2F_scaled + X2G_scaled + X2H_scaled
  Area3 =~ X3A + X3B + X3C + X3D
  Area4 =~ X4A_i + X4A_ii + X4A_iii +
           X4B_i + X4B_ii + X4C +
           X4D_i + X4D_ii + X4D_iii + X4D_iv
  Area5 =~ X5A_i + X5A_ii + X5A_iii +
           X5B_i + X5B_ii + X5B_iii + X5B_iv + X5B_v + X5B_vi + X5B_vii +
           X5C_i + X5C_ii + X5C_iii + X5C_iv +
           X5D_i + X5D_ii + X5D_iii
'

mod_4areas <- '
  Economic_Freedom =~ Area1 + Area2 + Area3 + Area45

  Area1  =~ X1A + X1B + X1C + X1D_i + X1D_ii + X1E
  Area2  =~ X2A_scaled + X2B_scaled + X2C_scaled + X2D_scaled +
            X2E_scaled + X2F_scaled + X2G_scaled + X2H_scaled
  Area3  =~ X3A + X3B + X3C + X3D
  Area45 =~ X4A_i + X4A_ii + X4A_iii +
            X4B_i + X4B_ii + X4C +
            X4D_i + X4D_ii + X4D_iii + X4D_iv +
            X5A_i + X5A_ii + X5A_iii +
            X5B_i + X5B_ii + X5B_iii + X5B_iv + X5B_v + X5B_vi + X5B_vii +
            X5C_i + X5C_ii + X5C_iii + X5C_iv +
            X5D_i + X5D_ii + X5D_iii
'

mod_6areas <- '
  Economic_Freedom =~ Area1 + Area2a + Area2b + Area3 + Area4 + Area5

  Area1  =~ X1A + X1B + X1C + X1D_i + X1D_ii + X1E
  Area2a =~ X2A_scaled + X2B_scaled + X2C_scaled + X2D_scaled
  Area2b =~ X2E_scaled + X2F_scaled + X2G_scaled + X2H_scaled
  Area3  =~ X3A + X3B + X3C + X3D
  Area4  =~ X4A_i + X4A_ii + X4A_iii +
            X4B_i + X4B_ii + X4C +
            X4D_i + X4D_ii + X4D_iii + X4D_iv
  Area5  =~ X5A_i + X5A_ii + X5A_iii +
            X5B_i + X5B_ii + X5B_iii + X5B_iv + X5B_v + X5B_vi + X5B_vii +
            X5C_i + X5C_ii + X5C_iii + X5C_iv +
            X5D_i + X5D_ii + X5D_iii
'

# --- Fit models --------------------------------------------------------------
fit_5 <- cfa(mod_5areas, data = df_2022_std , std.lv = TRUE, estimator = "MLR")
fit_4 <- cfa(mod_4areas, data = df_2022_std , std.lv = TRUE, estimator = "MLR")
fit_6 <- cfa(mod_6areas, data = df_2022_std , std.lv = TRUE, estimator = "MLR")

# --- Summaries (optional, comment out if too long) ---------------------------
summary(fit_5, fit.measures = TRUE, standardized = TRUE)
## lavaan 0.6-19 ended normally after 172 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        95
## 
##                                                   Used       Total
##   Number of observations                           108         165
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                              2602.082    2593.232
##   Degrees of freedom                               940         940
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.003
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                              4845.188    4758.297
##   Degrees of freedom                               990         990
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.018
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.569       0.561
##   Tucker-Lewis Index (TLI)                       0.546       0.538
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.568
##   Robust Tucker-Lewis Index (TLI)                            0.545
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -5460.590   -5460.590
##   Scaling correction factor                                  1.343
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)      -4159.549   -4159.549
##   Scaling correction factor                                  1.035
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                               11111.180   11111.180
##   Bayesian (BIC)                             11365.983   11365.983
##   Sample-size adjusted Bayesian (SABIC)      11065.811   11065.811
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.128       0.128
##   90 Percent confidence interval - lower         0.122       0.122
##   90 Percent confidence interval - upper         0.134       0.133
##   P-value H_0: RMSEA <= 0.050                    0.000       0.000
##   P-value H_0: RMSEA >= 0.080                    1.000       1.000
##                                                                   
##   Robust RMSEA                                               0.128
##   90 Percent confidence interval - lower                     0.122
##   90 Percent confidence interval - upper                     0.134
##   P-value H_0: Robust RMSEA <= 0.050                         0.000
##   P-value H_0: Robust RMSEA >= 0.080                         1.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.127       0.127
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                       Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   Economic_Freedom =~                                                      
##     Area1               -0.873    0.216   -4.049    0.000   -0.658   -0.658
##     Area2                1.498    0.250    5.983    0.000    0.832    0.832
##     Area3                0.630    0.166    3.801    0.000    0.533    0.533
##     Area4                3.273    1.132    2.891    0.004    0.956    0.956
##     Area5               10.825   35.994    0.301    0.764    0.996    0.996
##   Area1 =~                                                                 
##     X1A                  0.439    0.063    7.007    0.000    0.583    0.629
##     X1B                  0.671    0.102    6.597    0.000    0.890    0.849
##     X1C                 -0.256    0.057   -4.531    0.000   -0.340   -0.432
##     X1D_i                0.380    0.113    3.355    0.001    0.504    0.490
##     X1D_ii               0.343    0.112    3.053    0.002    0.456    0.458
##     X1E                 -0.238    0.062   -3.856    0.000   -0.316   -0.346
##   Area2 =~                                                                 
##     X2A_scaled           0.505    0.063    8.068    0.000    0.910    0.909
##     X2B_scaled           0.516    0.056    9.248    0.000    0.929    0.967
##     X2C_scaled           0.454    0.048    9.378    0.000    0.818    0.912
##     X2D_scaled           0.365    0.049    7.515    0.000    0.657    0.701
##     X2E_scaled           0.431    0.058    7.473    0.000    0.776    0.866
##     X2F_scaled           0.436    0.051    8.602    0.000    0.786    0.828
##     X2G_scaled           0.105    0.051    2.068    0.039    0.189    0.217
##     X2H_scaled           0.408    0.055    7.469    0.000    0.735    0.795
##   Area3 =~                                                                 
##     X3A                  0.493    0.170    2.903    0.004    0.583    0.633
##     X3B                  0.482    0.108    4.477    0.000    0.570    0.703
##     X3C                  0.655    0.092    7.109    0.000    0.774    0.830
##     X3D                  0.196    0.077    2.534    0.011    0.232    0.258
##   Area4 =~                                                                 
##     X4A_i                0.151    0.050    3.003    0.003    0.516    0.595
##     X4A_ii               0.192    0.070    2.732    0.006    0.657    0.719
##     X4A_iii              0.075    0.040    1.878    0.060    0.256    0.249
##     X4B_i                0.222    0.070    3.170    0.002    0.761    0.873
##     X4B_ii               0.198    0.068    2.933    0.003    0.678    0.732
##     X4C                  0.143    0.059    2.432    0.015    0.488    0.495
##     X4D_i                0.256    0.085    3.016    0.003    0.878    0.900
##     X4D_ii               0.174    0.064    2.718    0.007    0.594    0.620
##     X4D_iii              0.080    0.040    1.997    0.046    0.275    0.319
##     X4D_iv               0.240    0.069    3.470    0.001    0.820    0.903
##   Area5 =~                                                                 
##     X5A_i                0.033    0.109    0.303    0.762    0.360    0.377
##     X5A_ii               0.022    0.074    0.302    0.762    0.244    0.298
##     X5A_iii              0.012    0.039    0.301    0.763    0.127    0.137
##     X5B_i                0.041    0.136    0.300    0.764    0.444    0.473
##     X5B_ii               0.054    0.182    0.300    0.764    0.592    0.569
##     X5B_iii              0.014    0.049    0.291    0.771    0.154    0.144
##     X5B_iv               0.005    0.018    0.278    0.781    0.053    0.053
##     X5B_v                0.039    0.127    0.304    0.761    0.422    0.398
##     X5B_vi               0.007    0.024    0.294    0.769    0.077    0.078
##     X5B_vii              0.045    0.153    0.294    0.769    0.491    0.555
##     X5C_i                0.034    0.111    0.309    0.757    0.374    0.370
##     X5C_ii               0.059    0.193    0.307    0.759    0.642    0.763
##     X5C_iii              0.056    0.179    0.311    0.756    0.604    0.641
##     X5C_iv               0.055    0.179    0.305    0.761    0.594    0.653
##     X5D_i                0.075    0.251    0.298    0.766    0.815    0.854
##     X5D_ii               0.014    0.046    0.300    0.764    0.149    0.151
##     X5D_iii              0.078    0.263    0.298    0.766    0.851    0.877
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .X1A               0.521    0.103    5.050    0.000    0.521    0.605
##    .X1B               0.306    0.107    2.861    0.004    0.306    0.278
##    .X1C               0.505    0.084    5.976    0.000    0.505    0.813
##    .X1D_i             0.805    0.119    6.796    0.000    0.805    0.760
##    .X1D_ii            0.782    0.097    8.100    0.000    0.782    0.790
##    .X1E               0.732    0.120    6.079    0.000    0.732    0.880
##    .X2A_scaled        0.173    0.028    6.120    0.000    0.173    0.173
##    .X2B_scaled        0.060    0.017    3.616    0.000    0.060    0.065
##    .X2C_scaled        0.135    0.028    4.814    0.000    0.135    0.168
##    .X2D_scaled        0.447    0.061    7.284    0.000    0.447    0.509
##    .X2E_scaled        0.201    0.030    6.583    0.000    0.201    0.250
##    .X2F_scaled        0.284    0.046    6.144    0.000    0.284    0.315
##    .X2G_scaled        0.724    0.120    6.041    0.000    0.724    0.953
##    .X2H_scaled        0.316    0.061    5.197    0.000    0.316    0.369
##    .X3A               0.508    0.170    2.995    0.003    0.508    0.600
##    .X3B               0.332    0.098    3.378    0.001    0.332    0.506
##    .X3C               0.271    0.101    2.698    0.007    0.271    0.312
##    .X3D               0.755    0.124    6.082    0.000    0.755    0.933
##    .X4A_i             0.486    0.123    3.943    0.000    0.486    0.646
##    .X4A_ii            0.403    0.074    5.409    0.000    0.403    0.483
##    .X4A_iii           0.989    0.198    4.991    0.000    0.989    0.938
##    .X4B_i             0.181    0.028    6.408    0.000    0.181    0.238
##    .X4B_ii            0.398    0.062    6.387    0.000    0.398    0.464
##    .X4C               0.734    0.177    4.150    0.000    0.734    0.755
##    .X4D_i             0.180    0.042    4.324    0.000    0.180    0.189
##    .X4D_ii            0.567    0.099    5.726    0.000    0.567    0.616
##    .X4D_iii           0.666    0.108    6.155    0.000    0.666    0.898
##    .X4D_iv            0.152    0.035    4.275    0.000    0.152    0.184
##    .X5A_i             0.780    0.104    7.469    0.000    0.780    0.858
##    .X5A_ii            0.611    0.127    4.799    0.000    0.611    0.911
##    .X5A_iii           0.852    0.181    4.699    0.000    0.852    0.981
##    .X5B_i             0.683    0.091    7.542    0.000    0.683    0.776
##    .X5B_ii            0.733    0.089    8.219    0.000    0.733    0.676
##    .X5B_iii           1.112    0.223    4.992    0.000    1.112    0.979
##    .X5B_iv            0.985    0.120    8.209    0.000    0.985    0.997
##    .X5B_v             0.945    0.111    8.474    0.000    0.945    0.842
##    .X5B_vi            0.973    0.069   14.089    0.000    0.973    0.994
##    .X5B_vii           0.540    0.080    6.721    0.000    0.540    0.692
##    .X5C_i             0.883    0.125    7.072    0.000    0.883    0.863
##    .X5C_ii            0.297    0.054    5.510    0.000    0.297    0.418
##    .X5C_iii           0.523    0.094    5.543    0.000    0.523    0.589
##    .X5C_iv            0.475    0.078    6.109    0.000    0.475    0.574
##    .X5D_i             0.246    0.044    5.572    0.000    0.246    0.270
##    .X5D_ii            0.954    0.143    6.686    0.000    0.954    0.977
##    .X5D_iii           0.216    0.049    4.426    0.000    0.216    0.230
##     Economic_Fredm    1.000                               1.000    1.000
##    .Area1             1.000                               0.567    0.567
##    .Area2             1.000                               0.308    0.308
##    .Area3             1.000                               0.716    0.716
##    .Area4             1.000                               0.085    0.085
##    .Area5             1.000                               0.008    0.008
summary(fit_4, fit.measures = TRUE, standardized = TRUE)
## lavaan 0.6-19 ended normally after 86 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        94
## 
##                                                   Used       Total
##   Number of observations                           108         165
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                              2608.019    2592.893
##   Degrees of freedom                               941         941
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.006
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                              4845.188    4758.297
##   Degrees of freedom                               990         990
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.018
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.568       0.562
##   Tucker-Lewis Index (TLI)                       0.545       0.539
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.567
##   Robust Tucker-Lewis Index (TLI)                            0.544
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -5463.558   -5463.558
##   Scaling correction factor                                  1.322
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)      -4159.549   -4159.549
##   Scaling correction factor                                  1.035
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                               11115.117   11115.117
##   Bayesian (BIC)                             11367.237   11367.237
##   Sample-size adjusted Bayesian (SABIC)      11070.225   11070.225
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.128       0.127
##   90 Percent confidence interval - lower         0.122       0.122
##   90 Percent confidence interval - upper         0.134       0.133
##   P-value H_0: RMSEA <= 0.050                    0.000       0.000
##   P-value H_0: RMSEA >= 0.080                    1.000       1.000
##                                                                   
##   Robust RMSEA                                               0.128
##   90 Percent confidence interval - lower                     0.122
##   90 Percent confidence interval - upper                     0.134
##   P-value H_0: Robust RMSEA <= 0.050                         0.000
##   P-value H_0: Robust RMSEA >= 0.080                         1.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.128       0.128
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                       Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   Economic_Freedom =~                                                      
##     Area1               -1.096    0.301   -3.645    0.000   -0.739   -0.739
##     Area2                2.263    0.726    3.118    0.002    0.915    0.915
##     Area3                0.584    0.163    3.582    0.000    0.505    0.505
##     Area45               1.886    0.510    3.697    0.000    0.883    0.883
##   Area1 =~                                                                 
##     X1A                  0.415    0.058    7.105    0.000    0.616    0.664
##     X1B                  0.586    0.115    5.096    0.000    0.870    0.830
##     X1C                 -0.230    0.057   -4.030    0.000   -0.341   -0.432
##     X1D_i                0.345    0.109    3.178    0.001    0.512    0.498
##     X1D_ii               0.294    0.114    2.567    0.010    0.436    0.438
##     X1E                 -0.200    0.064   -3.103    0.002   -0.297   -0.326
##   Area2 =~                                                                 
##     X2A_scaled           0.367    0.098    3.743    0.000    0.909    0.909
##     X2B_scaled           0.375    0.097    3.866    0.000    0.928    0.966
##     X2C_scaled           0.330    0.088    3.733    0.000    0.817    0.912
##     X2D_scaled           0.267    0.071    3.756    0.000    0.661    0.705
##     X2E_scaled           0.314    0.083    3.780    0.000    0.778    0.869
##     X2F_scaled           0.317    0.081    3.907    0.000    0.785    0.827
##     X2G_scaled           0.076    0.042    1.807    0.071    0.188    0.215
##     X2H_scaled           0.297    0.081    3.656    0.000    0.735    0.795
##   Area3 =~                                                                 
##     X3A                  0.502    0.170    2.945    0.003    0.581    0.631
##     X3B                  0.478    0.111    4.305    0.000    0.554    0.683
##     X3C                  0.689    0.094    7.327    0.000    0.798    0.856
##     X3D                  0.190    0.079    2.389    0.017    0.220    0.244
##   Area45 =~                                                                
##     X4A_i                0.234    0.071    3.273    0.001    0.499    0.575
##     X4A_ii               0.297    0.070    4.214    0.000    0.633    0.693
##     X4A_iii              0.114    0.052    2.183    0.029    0.243    0.237
##     X4B_i                0.353    0.079    4.485    0.000    0.753    0.863
##     X4B_ii               0.313    0.067    4.655    0.000    0.667    0.721
##     X4C                  0.226    0.069    3.271    0.001    0.483    0.489
##     X4D_i                0.403    0.086    4.692    0.000    0.859    0.882
##     X4D_ii               0.269    0.065    4.154    0.000    0.575    0.599
##     X4D_iii              0.119    0.053    2.242    0.025    0.254    0.295
##     X4D_iv               0.390    0.089    4.373    0.000    0.833    0.917
##     X5A_i                0.176    0.060    2.916    0.004    0.375    0.393
##     X5A_ii               0.113    0.049    2.302    0.021    0.241    0.294
##     X5A_iii              0.064    0.053    1.209    0.227    0.137    0.146
##     X5B_i                0.199    0.060    3.339    0.001    0.425    0.453
##     X5B_ii               0.269    0.071    3.759    0.000    0.573    0.551
##     X5B_iii              0.078    0.055    1.420    0.156    0.166    0.155
##     X5B_iv               0.012    0.043    0.280    0.779    0.026    0.026
##     X5B_v                0.189    0.057    3.348    0.001    0.404    0.382
##     X5B_vi               0.047    0.047    0.985    0.325    0.099    0.100
##     X5B_vii              0.237    0.067    3.536    0.000    0.505    0.572
##     X5C_i                0.163    0.053    3.071    0.002    0.348    0.344
##     X5C_ii               0.300    0.067    4.508    0.000    0.641    0.761
##     X5C_iii              0.274    0.055    4.950    0.000    0.585    0.620
##     X5C_iv               0.277    0.072    3.844    0.000    0.591    0.650
##     X5D_i                0.372    0.087    4.283    0.000    0.795    0.833
##     X5D_ii               0.058    0.047    1.231    0.218    0.124    0.125
##     X5D_iii              0.398    0.093    4.289    0.000    0.849    0.875
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .X1A               0.481    0.106    4.557    0.000    0.481    0.559
##    .X1B               0.341    0.100    3.418    0.001    0.341    0.311
##    .X1C               0.504    0.085    5.937    0.000    0.504    0.813
##    .X1D_i             0.797    0.118    6.768    0.000    0.797    0.752
##    .X1D_ii            0.800    0.099    8.107    0.000    0.800    0.808
##    .X1E               0.743    0.122    6.097    0.000    0.743    0.894
##    .X2A_scaled        0.174    0.028    6.194    0.000    0.174    0.174
##    .X2B_scaled        0.062    0.016    3.754    0.000    0.062    0.067
##    .X2C_scaled        0.135    0.028    4.812    0.000    0.135    0.168
##    .X2D_scaled        0.441    0.062    7.112    0.000    0.441    0.502
##    .X2E_scaled        0.197    0.030    6.483    0.000    0.197    0.246
##    .X2F_scaled        0.285    0.046    6.188    0.000    0.285    0.316
##    .X2G_scaled        0.724    0.120    6.037    0.000    0.724    0.954
##    .X2H_scaled        0.316    0.061    5.217    0.000    0.316    0.369
##    .X3A               0.510    0.170    3.002    0.003    0.510    0.602
##    .X3B               0.351    0.105    3.339    0.001    0.351    0.533
##    .X3C               0.233    0.112    2.077    0.038    0.233    0.268
##    .X3D               0.760    0.124    6.138    0.000    0.760    0.940
##    .X4A_i             0.503    0.121    4.148    0.000    0.503    0.669
##    .X4A_ii            0.434    0.073    5.921    0.000    0.434    0.520
##    .X4A_iii           0.995    0.197    5.038    0.000    0.995    0.944
##    .X4B_i             0.194    0.028    6.881    0.000    0.194    0.255
##    .X4B_ii            0.412    0.063    6.593    0.000    0.412    0.481
##    .X4C               0.740    0.179    4.128    0.000    0.740    0.761
##    .X4D_i             0.212    0.040    5.272    0.000    0.212    0.223
##    .X4D_ii            0.590    0.100    5.881    0.000    0.590    0.641
##    .X4D_iii           0.677    0.111    6.122    0.000    0.677    0.913
##    .X4D_iv            0.130    0.028    4.717    0.000    0.130    0.158
##    .X5A_i             0.769    0.100    7.665    0.000    0.769    0.845
##    .X5A_ii            0.612    0.129    4.744    0.000    0.612    0.913
##    .X5A_iii           0.850    0.180    4.722    0.000    0.850    0.979
##    .X5B_i             0.700    0.089    7.867    0.000    0.700    0.795
##    .X5B_ii            0.756    0.086    8.803    0.000    0.756    0.697
##    .X5B_iii           1.109    0.222    4.986    0.000    1.109    0.976
##    .X5B_iv            0.987    0.121    8.154    0.000    0.987    0.999
##    .X5B_v             0.959    0.108    8.877    0.000    0.959    0.854
##    .X5B_vi            0.969    0.070   13.773    0.000    0.969    0.990
##    .X5B_vii           0.526    0.076    6.955    0.000    0.526    0.673
##    .X5C_i             0.902    0.127    7.104    0.000    0.902    0.882
##    .X5C_ii            0.298    0.050    5.907    0.000    0.298    0.420
##    .X5C_iii           0.546    0.085    6.461    0.000    0.546    0.615
##    .X5C_iv            0.479    0.076    6.283    0.000    0.479    0.578
##    .X5D_i             0.278    0.036    7.802    0.000    0.278    0.306
##    .X5D_ii            0.961    0.143    6.730    0.000    0.961    0.984
##    .X5D_iii           0.220    0.037    5.964    0.000    0.220    0.234
##     Economic_Fredm    1.000                               1.000    1.000
##    .Area1             1.000                               0.454    0.454
##    .Area2             1.000                               0.163    0.163
##    .Area3             1.000                               0.745    0.745
##    .Area45            1.000                               0.220    0.220
summary(fit_6, fit.measures = TRUE, standardized = TRUE)
## lavaan 0.6-19 ended normally after 107 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        96
## 
##                                                   Used       Total
##   Number of observations                           108         165
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                              2656.602    2655.209
##   Degrees of freedom                               939         939
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  1.001
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                              4845.188    4758.297
##   Degrees of freedom                               990         990
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  1.018
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.554       0.545
##   Tucker-Lewis Index (TLI)                       0.530       0.520
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.552
##   Robust Tucker-Lewis Index (TLI)                            0.528
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -5487.850   -5487.850
##   Scaling correction factor                                  1.367
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)      -4159.549   -4159.549
##   Scaling correction factor                                  1.035
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                               11167.699   11167.699
##   Bayesian (BIC)                             11425.184   11425.184
##   Sample-size adjusted Bayesian (SABIC)      11121.852   11121.852
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.130       0.130
##   90 Percent confidence interval - lower         0.124       0.124
##   90 Percent confidence interval - upper         0.136       0.136
##   P-value H_0: RMSEA <= 0.050                    0.000       0.000
##   P-value H_0: RMSEA >= 0.080                    1.000       1.000
##                                                                   
##   Robust RMSEA                                               0.130
##   90 Percent confidence interval - lower                     0.124
##   90 Percent confidence interval - upper                     0.136
##   P-value H_0: Robust RMSEA <= 0.050                         0.000
##   P-value H_0: Robust RMSEA >= 0.080                         1.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.131       0.131
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                       Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   Economic_Freedom =~                                                      
##     Area1               -1.028    0.260   -3.952    0.000   -0.717   -0.717
##     Area2a               3.967    2.413    1.644    0.100    0.970    0.970
##     Area2b               3.072    1.346    2.282    0.022    0.951    0.951
##     Area3                0.549    0.138    3.969    0.000    0.481    0.481
##     Area4                1.504    0.403    3.726    0.000    0.833    0.833
##     Area5                2.130    0.860    2.476    0.013    0.905    0.905
##   Area1 =~                                                                 
##     X1A                  0.437    0.053    8.224    0.000    0.627    0.676
##     X1B                  0.604    0.109    5.544    0.000    0.867    0.827
##     X1C                 -0.233    0.056   -4.126    0.000   -0.334   -0.424
##     X1D_i                0.361    0.108    3.343    0.001    0.517    0.502
##     X1D_ii               0.303    0.114    2.664    0.008    0.435    0.437
##     X1E                 -0.194    0.064   -3.040    0.002   -0.278   -0.305
##   Area2a =~                                                                
##     X2A_scaled           0.221    0.124    1.774    0.076    0.903    0.903
##     X2B_scaled           0.228    0.129    1.766    0.077    0.933    0.971
##     X2C_scaled           0.201    0.112    1.788    0.074    0.822    0.917
##     X2D_scaled           0.159    0.087    1.821    0.069    0.650    0.694
##   Area2b =~                                                                
##     X2E_scaled           0.236    0.082    2.879    0.004    0.763    0.852
##     X2F_scaled           0.256    0.106    2.415    0.016    0.829    0.873
##     X2G_scaled           0.076    0.049    1.567    0.117    0.247    0.283
##     X2H_scaled           0.240    0.096    2.498    0.012    0.777    0.839
##   Area3 =~                                                                 
##     X3A                  0.512    0.173    2.952    0.003    0.584    0.634
##     X3B                  0.479    0.113    4.224    0.000    0.546    0.673
##     X3C                  0.707    0.090    7.868    0.000    0.806    0.864
##     X3D                  0.189    0.080    2.368    0.018    0.215    0.239
##   Area4 =~                                                                 
##     X4A_i                0.287    0.071    4.054    0.000    0.519    0.599
##     X4A_ii               0.374    0.082    4.578    0.000    0.675    0.739
##     X4A_iii              0.141    0.061    2.302    0.021    0.255    0.248
##     X4B_i                0.418    0.079    5.279    0.000    0.755    0.866
##     X4B_ii               0.377    0.078    4.851    0.000    0.681    0.736
##     X4C                  0.267    0.084    3.164    0.002    0.482    0.489
##     X4D_i                0.497    0.095    5.243    0.000    0.898    0.921
##     X4D_ii               0.344    0.074    4.651    0.000    0.622    0.648
##     X4D_iii              0.165    0.062    2.656    0.008    0.298    0.346
##     X4D_iv               0.438    0.079    5.561    0.000    0.791    0.871
##   Area5 =~                                                                 
##     X5A_i                0.141    0.064    2.184    0.029    0.331    0.347
##     X5A_ii               0.099    0.050    1.998    0.046    0.233    0.284
##     X5A_iii              0.044    0.050    0.865    0.387    0.103    0.110
##     X5B_i                0.205    0.079    2.587    0.010    0.483    0.514
##     X5B_ii               0.261    0.102    2.567    0.010    0.615    0.591
##     X5B_iii              0.064    0.055    1.174    0.240    0.152    0.142
##     X5B_iv               0.040    0.042    0.941    0.347    0.094    0.094
##     X5B_v                0.188    0.075    2.495    0.013    0.442    0.417
##     X5B_vi               0.017    0.044    0.376    0.707    0.039    0.039
##     X5B_vii              0.195    0.091    2.129    0.033    0.458    0.518
##     X5C_i                0.189    0.062    3.058    0.002    0.444    0.439
##     X5C_ii               0.269    0.085    3.184    0.001    0.634    0.753
##     X5C_iii              0.258    0.075    3.444    0.001    0.608    0.645
##     X5C_iv               0.261    0.082    3.191    0.001    0.615    0.675
##     X5D_i                0.346    0.134    2.581    0.010    0.814    0.853
##     X5D_ii               0.086    0.047    1.843    0.065    0.202    0.205
##     X5D_iii              0.349    0.136    2.560    0.010    0.820    0.846
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .X1A               0.467    0.102    4.602    0.000    0.467    0.543
##    .X1B               0.347    0.102    3.400    0.001    0.347    0.316
##    .X1C               0.509    0.086    5.895    0.000    0.509    0.820
##    .X1D_i             0.792    0.117    6.784    0.000    0.792    0.748
##    .X1D_ii            0.800    0.100    8.021    0.000    0.800    0.809
##    .X1E               0.754    0.122    6.159    0.000    0.754    0.907
##    .X2A_scaled        0.184    0.030    6.083    0.000    0.184    0.184
##    .X2B_scaled        0.052    0.021    2.443    0.015    0.052    0.057
##    .X2C_scaled        0.128    0.032    4.042    0.000    0.128    0.159
##    .X2D_scaled        0.456    0.064    7.093    0.000    0.456    0.519
##    .X2E_scaled        0.220    0.055    3.997    0.000    0.220    0.274
##    .X2F_scaled        0.215    0.048    4.490    0.000    0.215    0.239
##    .X2G_scaled        0.699    0.115    6.061    0.000    0.699    0.920
##    .X2H_scaled        0.253    0.051    4.927    0.000    0.253    0.295
##    .X3A               0.507    0.170    2.985    0.003    0.507    0.598
##    .X3B               0.359    0.106    3.378    0.001    0.359    0.546
##    .X3C               0.221    0.115    1.923    0.054    0.221    0.253
##    .X3D               0.762    0.122    6.225    0.000    0.762    0.943
##    .X4A_i             0.483    0.130    3.725    0.000    0.483    0.642
##    .X4A_ii            0.378    0.067    5.639    0.000    0.378    0.453
##    .X4A_iii           0.989    0.199    4.974    0.000    0.989    0.939
##    .X4B_i             0.190    0.036    5.332    0.000    0.190    0.250
##    .X4B_ii            0.394    0.063    6.271    0.000    0.394    0.459
##    .X4C               0.740    0.181    4.085    0.000    0.740    0.761
##    .X4D_i             0.143    0.038    3.817    0.000    0.143    0.151
##    .X4D_ii            0.533    0.093    5.759    0.000    0.533    0.580
##    .X4D_iii           0.653    0.107    6.125    0.000    0.653    0.880
##    .X4D_iv            0.198    0.039    5.102    0.000    0.198    0.241
##    .X5A_i             0.800    0.111    7.232    0.000    0.800    0.880
##    .X5A_ii            0.616    0.129    4.792    0.000    0.616    0.919
##    .X5A_iii           0.858    0.186    4.613    0.000    0.858    0.988
##    .X5B_i             0.648    0.092    7.074    0.000    0.648    0.735
##    .X5B_ii            0.706    0.096    7.385    0.000    0.706    0.651
##    .X5B_iii           1.113    0.224    4.967    0.000    1.113    0.980
##    .X5B_iv            0.979    0.118    8.316    0.000    0.979    0.991
##    .X5B_v             0.927    0.117    7.932    0.000    0.927    0.826
##    .X5B_vi            0.978    0.068   14.318    0.000    0.978    0.998
##    .X5B_vii           0.571    0.086    6.671    0.000    0.571    0.732
##    .X5C_i             0.826    0.115    7.163    0.000    0.826    0.807
##    .X5C_ii            0.307    0.057    5.361    0.000    0.307    0.433
##    .X5C_iii           0.519    0.096    5.387    0.000    0.519    0.584
##    .X5C_iv            0.450    0.078    5.804    0.000    0.450    0.544
##    .X5D_i             0.247    0.066    3.771    0.000    0.247    0.272
##    .X5D_ii            0.936    0.141    6.644    0.000    0.936    0.958
##    .X5D_iii           0.268    0.076    3.504    0.000    0.268    0.284
##     Economic_Fredm    1.000                               1.000    1.000
##    .Area1             1.000                               0.486    0.486
##    .Area2a            1.000                               0.060    0.060
##    .Area2b            1.000                               0.096    0.096
##    .Area3             1.000                               0.769    0.769
##    .Area4             1.000                               0.307    0.307
##    .Area5             1.000                               0.181    0.181
# --- Compare key fit indices side by side ------------------------------------
fits <- list(Four_Areas = fit_4, Five_Areas = fit_5, Six_Areas = fit_6)

fit_table <- sapply(fits, function(f) fitMeasures(f,
  c("cfi","tli","rmsea","srmr","aic","bic")))

print(round(fit_table, 3))
##       Four_Areas Five_Areas Six_Areas
## cfi        0.568      0.569     0.554
## tli        0.545      0.546     0.530
## rmsea      0.128      0.128     0.130
## srmr       0.128      0.127     0.131
## aic    11115.117  11111.180 11167.699
## bic    11367.237  11365.983 11425.184
# --- Optional visualization --------------------------------------------------
semPaths(fit_4, "std", layout="tree",
         residuals=FALSE, nCharNodes=0,
         edge.label.cex=0.7, sizeMan=4, sizeLat=6,
         title=TRUE)

semPaths(fit_5, "std", layout="tree",
         residuals=FALSE, nCharNodes=0,
         edge.label.cex=0.7, sizeMan=4, sizeLat=6,
         title=TRUE)

semPaths(fit_6, "std", layout="tree",
         residuals=FALSE, nCharNodes=0,
         edge.label.cex=0.7, sizeMan=4, sizeLat=6,
         title=TRUE)

anova(fit_5, fit_4, fit_6 )
## Warning: lavaan->lavTestLRT():  
##    Some restricted models fit better than less restricted models; either 
##    these models are not nested, or the less restricted model failed to reach 
##    a global optimum.Smallest difference = -54.5193445436962.
## 
## Scaled Chi-Squared Difference Test (method = "satorra.bentler.2001")
## 
## lavaan->lavTestLRT():  
##    lavaan NOTE: The "Chisq" column contains standard test statistics, not the 
##    robust test that should be reported per model. A robust difference test is 
##    a function of two standard (not robust) statistics.
##        Df   AIC   BIC  Chisq Chisq diff Df diff Pr(>Chisq)
## fit_6 939 11168 11425 2656.6                              
## fit_5 940 11111 11366 2602.1   -14.6731       1     1.0000
## fit_4 941 11115 11367 2608.0     1.8091       1     0.1786

EFA

set.seed(42)  # reproducibility

# --- 1) Collect indicators ---------------------------------------------------
efa_cols <- c(
  "X1A","X1B","X1C","X1D_i","X1D_ii","X1E",
  "X2A_scaled","X2B_scaled","X2C_scaled","X2D_scaled",
  "X2E_scaled","X2F_scaled","X2G_scaled","X2H_scaled",
  "X3A","X3B","X3C","X3D",
  "X4A_i","X4A_ii","X4A_iii","X4B_i","X4B_ii","X4C",
  "X4D_i","X4D_ii","X4D_iii","X4D_iv",
  "X5A_i","X5A_ii","X5A_iii",
  "X5B_i","X5B_ii","X5B_iii","X5B_iv","X5B_v","X5B_vi","X5B_vii",
  "X5C_i","X5C_ii","X5C_iii","X5C_iv",
  "X5D_i","X5D_ii","X5D_iii"
)

efa_vars <- df_2022_std %>%
  select(any_of(efa_cols)) %>%
  select(where(is.numeric))

# --- 2) Pretty labels --------------------------------------------------------
pretty_names <- function(df, vars) {
  sapply(vars, function(v) {
    lb <- attr(df[[v]], "label", exact=TRUE)
    if (is.null(lb) || is.na(lb) || lb=="") v else lb
  }, USE.NAMES=FALSE)
}
var_labels <- pretty_names(df_2022_std, colnames(efa_vars))

# --- 3) Factorability checks -------------------------------------------------
cat("KMO:\n"); print(KMO(efa_vars))
## KMO:
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = efa_vars)
## Overall MSA =  0.84
## MSA for each item = 
##        X1A        X1B        X1C      X1D_i     X1D_ii        X1E X2A_scaled 
##       0.84       0.88       0.80       0.67       0.59       0.82       0.88 
## X2B_scaled X2C_scaled X2D_scaled X2E_scaled X2F_scaled X2G_scaled X2H_scaled 
##       0.89       0.91       0.89       0.88       0.94       0.54       0.90 
##        X3A        X3B        X3C        X3D      X4A_i     X4A_ii    X4A_iii 
##       0.70       0.68       0.71       0.87       0.83       0.84       0.47 
##      X4B_i     X4B_ii        X4C      X4D_i     X4D_ii    X4D_iii     X4D_iv 
##       0.92       0.91       0.80       0.92       0.77       0.83       0.93 
##      X5A_i     X5A_ii    X5A_iii      X5B_i     X5B_ii    X5B_iii     X5B_iv 
##       0.70       0.78       0.59       0.68       0.72       0.76       0.38 
##      X5B_v     X5B_vi    X5B_vii      X5C_i     X5C_ii    X5C_iii     X5C_iv 
##       0.56       0.42       0.88       0.82       0.93       0.91       0.94 
##      X5D_i     X5D_ii    X5D_iii 
##       0.92       0.66       0.90
R <- cor(efa_vars, use="pairwise.complete.obs")
cat("\nBartlett:\n")
## 
## Bartlett:
print(cortest.bartlett(R, n=nrow(efa_vars)))
## $chisq
## [1] 5631.827
## 
## $p.value
## [1] 0
## 
## $df
## [1] 990
# --- 4) EFA (5 factors, ML, oblimin) ----------------------------------------
efa_result <- fa(efa_vars, nfactors=5, fm="ml", rotate="oblimin", use="pairwise")
print(efa_result$loadings, cutoff=.30)
## 
## Loadings:
##            ML2    ML5    ML3    ML1    ML4   
## X1A        -0.562 -0.301  0.500              
## X1B               -0.419                0.492
## X1C                                          
## X1D_i      -0.415                       0.442
## X1D_ii                                  0.591
## X1E                       0.659              
## X2A_scaled  0.904                            
## X2B_scaled  0.898                            
## X2C_scaled  0.685                            
## X2D_scaled  0.640                            
## X2E_scaled  0.890                            
## X2F_scaled  0.601                            
## X2G_scaled                                   
## X2H_scaled  0.705                            
## X3A                                     0.309
## X3B                       0.517              
## X3C         0.375                            
## X3D                0.670                     
## X4A_i              0.733                     
## X4A_ii             0.695                     
## X4A_iii            0.396                     
## X4B_i              0.640                     
## X4B_ii             0.414                     
## X4C                       0.302              
## X4D_i              0.630                     
## X4D_ii             0.486                     
## X4D_iii                                      
## X4D_iv      0.308  0.416  0.459              
## X5A_i                     0.337              
## X5A_ii                                       
## X5A_iii                   0.320              
## X5B_i                                   0.458
## X5B_ii                           0.981       
## X5B_iii                                 0.477
## X5B_iv                                       
## X5B_v                            0.914       
## X5B_vi                                       
## X5B_vii            0.355  0.429              
## X5C_i       0.474                       0.603
## X5C_ii      0.527                            
## X5C_iii     0.616                      -0.318
## X5C_iv      0.457                       0.305
## X5D_i       0.387         0.426              
## X5D_ii                                  0.411
## X5D_iii                   0.621              
## 
##                  ML2   ML5   ML3   ML1   ML4
## SS loadings    6.775 4.321 3.000 2.294 2.552
## Proportion Var 0.151 0.096 0.067 0.051 0.057
## Cumulative Var 0.151 0.247 0.313 0.364 0.421
# --- 5) Clean loading table --------------------------------------------------
load_tbl <- as.data.frame(unclass(efa_result$loadings))
load_tbl <- tibble::rownames_to_column(load_tbl, "var")
colnames(load_tbl) <- c("var", paste0("F", seq_len(ncol(load_tbl)-1)))
load_tbl$label <- var_labels[match(load_tbl$var, colnames(efa_vars))]

Fcols <- paste0("F", 1:5)
load_tbl$primary <- apply(load_tbl[,Fcols], 1, function(x) paste0("F", which.max(abs(x))))
load_tbl$loading <- apply(load_tbl[,Fcols], 1, function(x) x[which.max(abs(x))])

cat("\n=== Primary loadings (|λ| ≥ .30) ===\n")
## 
## === Primary loadings (|λ| ≥ .30) ===
print(
  load_tbl %>%
    filter(abs(loading) >= .30) %>%
    arrange(primary, desc(abs(loading))) %>%
    select(var, label, primary, loading),
  digits=3, row.names=FALSE
)
##         var      label primary loading
##  X2A_scaled X2A_scaled      F1   0.904
##  X2B_scaled X2B_scaled      F1   0.898
##  X2E_scaled X2E_scaled      F1   0.890
##  X2H_scaled X2H_scaled      F1   0.705
##  X2C_scaled X2C_scaled      F1   0.685
##  X2D_scaled X2D_scaled      F1   0.640
##     X5C_iii    X5C_iii      F1   0.616
##  X2F_scaled X2F_scaled      F1   0.601
##         X1A        X1A      F1  -0.562
##      X5C_ii     X5C_ii      F1   0.527
##      X5C_iv     X5C_iv      F1   0.457
##         X3C        X3C      F1   0.375
##       X4A_i      X4A_i      F2   0.733
##      X4A_ii     X4A_ii      F2   0.695
##         X3D        X3D      F2   0.670
##       X4B_i      X4B_i      F2   0.640
##       X4D_i      X4D_i      F2   0.630
##      X4D_ii     X4D_ii      F2   0.486
##      X4B_ii     X4B_ii      F2   0.414
##     X4A_iii    X4A_iii      F2   0.396
##         X1E        X1E      F3   0.659
##     X5D_iii    X5D_iii      F3   0.621
##         X3B        X3B      F3   0.517
##      X4D_iv     X4D_iv      F3   0.459
##     X5B_vii    X5B_vii      F3   0.429
##       X5D_i      X5D_i      F3   0.426
##       X5A_i      X5A_i      F3   0.337
##     X5A_iii    X5A_iii      F3   0.320
##         X4C        X4C      F3   0.302
##      X5B_ii     X5B_ii      F4   0.981
##       X5B_v      X5B_v      F4   0.914
##       X5C_i      X5C_i      F5   0.603
##      X1D_ii     X1D_ii      F5   0.591
##         X1B        X1B      F5   0.492
##     X5B_iii    X5B_iii      F5   0.477
##       X5B_i      X5B_i      F5   0.458
##       X1D_i      X1D_i      F5   0.442
##      X5D_ii     X5D_ii      F5   0.411
##         X3A        X3A      F5   0.309
# --- 6) Heatmap --------------------------------------------------------------
long_load <- load_tbl %>%
  select(var, label, all_of(Fcols)) %>%
  pivot_longer(all_of(Fcols), names_to="Factor", values_to="Loading")

item_order <- load_tbl %>%
  arrange(primary, desc(abs(loading))) %>%
  pull(label)
long_load$label <- factor(long_load$label, levels=rev(unique(item_order)))

ggplot(long_load, aes(x=Factor, y=label, fill=Loading)) +
  geom_tile() +
  scale_fill_gradient2(limits=c(-1,1)) +
  labs(x=NULL, y=NULL, title="EFA Loadings Heatmap (ML, oblimin)") +
  theme_minimal(base_size=11) +
  theme(panel.grid=element_blank(),
        axis.text.y=element_text(size=8))

# --- 7) Factor scores --------------------------------------------------------
scores <- factor.scores(efa_vars, efa_result, method="tenBerge")$scores
head(scores)
##             ML2        ML5        ML3         ML1         ML4
## [1,] -0.4542841  0.6792904  0.9024044 -0.09729673 -0.04579784
## [2,] -0.3892151 -1.1134279 -1.9015050  0.24645906  0.15825061
## [3,] -1.1995054 -0.8113216 -1.2940769 -0.47999342  0.10047567
## [4,] -0.0824798 -0.8221474 -0.4936583 -1.76199196 -2.37812532
## [5,] -0.3626357  0.4010869  0.1318660  0.67520264  0.65293589
## [6,]  1.7443159  0.7466526  0.5367044  0.83908722 -0.37068569
fa.diagram(efa_result, main = "EFA (5 Factors)")

Citations

citation("lavaan")
## To cite lavaan in publications use:
## 
##   Yves Rosseel (2012). lavaan: An R Package for Structural Equation
##   Modeling. Journal of Statistical Software, 48(2), 1-36.
##   https://doi.org/10.18637/jss.v048.i02
## 
## A BibTeX entry for LaTeX users is
## 
##   @Article{,
##     title = {{lavaan}: An {R} Package for Structural Equation Modeling},
##     author = {Yves Rosseel},
##     journal = {Journal of Statistical Software},
##     year = {2012},
##     volume = {48},
##     number = {2},
##     pages = {1--36},
##     doi = {10.18637/jss.v048.i02},
##   }