Structural equation modeling and application in psychology (WIP)

Structural Equation Modeling
Psychology
This study was made during the Supervised Study Project in Mathematics (SSPM) of the first year of master
Author

Clément Poupelin

Published

October 14, 2025

Modified

November 1, 2025

Setup

Show the code
library(dplyr)    ## Data manipulation
library(tidyr)    ## Data manipulation
library(ggplot2)  ## Plots
library(viridis)  ## Colorblind palet

library(lavaan)   ## Structural equation modeling

# devtools::install_github('SachaEpskamp/semPlot')
# library(semPlot)
Show the code
create_barplot <- function(data, title, palette = "viridis") {
  data_long <- data %>%
    pivot_longer(cols = everything(), names_to = "Item", values_to = "Response")

  ggplot(data_long, aes(x = factor(Response), fill = factor(Response))) +
    geom_bar() +
    facet_wrap(~ Item, ncol = 2) +  # 2 colonnes pour le facet
    labs(title = title, x = "Response", y = "Frequency") +
    scale_fill_viridis_d(option = palette, direction = -1) +
    theme_minimal() +
    theme(
      plot.title = element_text(size = 32, face = "bold"),
      axis.title.y = element_text(size = 22),
      axis.title.x = element_text(size = 22),
      axis.text.y = element_text(size = 20),
      axis.text.x = element_text(size = 20, angle = 45, hjust = 1),
      strip.text = element_text(size = 24, face = "bold"),  # Personnalisation des titres des facets
      legend.position = "none"  # Pas besoin de légende redondante
    )
}
Show the code
set.seed(140400)

Abstract

This tutorial provides a simple application of Structural Equation Modeling (SEM) to introduce the concept using a modified and simplified version of the dataset from the article “Explicit spirituality, self-esteem and the mechanisms of social and temporal comparison” by Justine Ollivaud, Jean-Michel Galharret, and Nicolas Roussiau.
It is inspired by the Supervised Study Project in Mathematics (SSPM) of the first year of master Structural equation modeling and application in psychology by Clément Poupelin and Aëla Jogot.

The analysis focuses on the psychological research domain, specifically examining the impact of spirituality on self-esteem, mediated by social and temporal comparison mechanisms. The goal is to offer a practical, accessible introduction to SEM for researchers and students interested in psychological data analysis.

Import Data

The dataset used in this study is imported in .csv format and we remove all missing values with the na.omit() function.

Show the code
# Load the dataset
SSPM_data <- read.csv("~/Documents/1_Projet/Perso/SSPM_data.csv")

# remove missing values
SSPM_data <- SSPM_data[,1:47] %>% na.omit()

It includes 331 individuals characterized by the 47 following variables :

  • Identifiant : integer assigned to the individual

  • spirit1, \(\cdots\) , spirit16 : answers of the individual for the 16 questions which relate to spirituality

  • Score_Spirit : total score of the individual for the questions which relate to spirituality

  • CompSoc1, \(\cdots\) , CompSoc8 : answers of the individual for the 8 questions which relate to social comparison

  • Score_CompS : total score of the individual for the questions which relate to social comparison

  • CompTemp1, \(\cdots\) , CompTemp8 : answers of the individual for the 8 questions which relate to temporal comparison

  • Score_CompT : total score of the individual for the questions which relate to temporal comparison

  • es1, \(\cdots\) , es10 : answers of the individual for the 10 questions which relate to self esteem

  • Score_ES : total score of the individual for the questions which relate to self esteem

Show the code
SSPM_data %>% DT::datatable()

For this analysis, only positively worded items are retained:

Show the code
# Select positively worded items
es_selected <- subset(SSPM_data,
                      select = c(es3, es5, es8, es9, es10)) 
compSoc_selected <- subset(SSPM_data,
                           select = c(compSoc1, compSoc3, compSoc4, compSoc6))
compTemp_selected <- subset(SSPM_data,
                            select = c(compTemp1, compTemp3, compTemp4, compTemp6))
spirit_selected <- subset(SSPM_data,
                          select = c(spirit1, spirit2, spirit3, spirit4, spirit5, spirit6, spirit7, spirit8, spirit9, spirit10, spirit11, spirit12, spirit13, spirit14, spirit15, spirit16))

es_selected %>% 
  colnames() %>% 
  print()
[1] "es3"  "es5"  "es8"  "es9"  "es10"
Show the code
compSoc_selected %>% 
  colnames() %>% 
  print()
[1] "compSoc1" "compSoc3" "compSoc4" "compSoc6"
Show the code
compTemp_selected %>% 
  colnames() %>% 
  print()
[1] "compTemp1" "compTemp3" "compTemp4" "compTemp6"
Show the code
spirit_selected %>% 
  colnames() %>% 
  print()
 [1] "spirit1"  "spirit2"  "spirit3"  "spirit4"  "spirit5"  "spirit6" 
 [7] "spirit7"  "spirit8"  "spirit9"  "spirit10" "spirit11" "spirit12"
[13] "spirit13" "spirit14" "spirit15" "spirit16"

Preliminary analysis

Descriptive analysis

To represent the distribution of responses to each questionnaire item, we use barplots. This approach is more intuitive for categorical questionnaire data. We also use facet grids to separate items by construct (e.g., self-esteem, social comparison).
Note that colors can be chosen to be accessible to colorblind individuals.

Show the code
create_barplot(es_selected, "Selected Self-Esteem Items", palette = "D")

Show the code
create_barplot(spirit_selected, "Spirituality Items", palette = "A")

Show the code
create_barplot(compSoc_selected, "Selected Social Comparison Items", palette = "E")

Show the code
create_barplot(compTemp_selected, "Selected Temporal Comparison Items", palette = "F")

Linear Model

We fit two linear models to explore the relationships between spirituality, social/temporal comparison, and self-esteem:

  • Model 1 (M1): Social comparison as a function of spirituality

  • Model 2 (M2): Self-esteem as a function of social comparison and spirituality

Show the code
# Fit linear models
M1 <- lm(Score_CompS ~ Score_Spirit, data = SSPM_data)

# Summarize results
summary(M1)

Call:
lm(formula = Score_CompS ~ Score_Spirit, data = SSPM_data)

Residuals:
     Min       1Q   Median       3Q      Max 
-1.60826 -0.49391  0.02527  0.49259  2.16091 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)   3.75886    0.31178  12.056  < 2e-16 ***
Score_Spirit -0.30683    0.06996  -4.386 1.56e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.6836 on 329 degrees of freedom
Multiple R-squared:  0.05524,   Adjusted R-squared:  0.05236 
F-statistic: 19.24 on 1 and 329 DF,  p-value: 1.558e-05
Show the code
# Visualize M1 with added-variable plots
car::avPlots(M1)

Show the code
# Fit linear models
M2 <- lm(Score_ES ~ Score_CompS + Score_Spirit, data = SSPM_data)

# Summarize results
summary(M2)

Call:
lm(formula = Score_ES ~ Score_CompS + Score_Spirit, data = SSPM_data)

Residuals:
    Min      1Q  Median      3Q     Max 
-2.1939 -0.3667  0.0061  0.3898  1.4025 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)   4.59609    0.29881  15.381   <2e-16 ***
Score_CompS  -0.46000    0.04401 -10.453   <2e-16 ***
Score_Spirit  0.10314    0.05745   1.795   0.0735 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.5456 on 328 degrees of freedom
Multiple R-squared:  0.2813,    Adjusted R-squared:  0.277 
F-statistic:  64.2 on 2 and 328 DF,  p-value: < 2.2e-16
Show the code
# Visualize M2 with added-variable plots
car::avPlots(M2)

M1 tests the direct effect of spirituality on social comparison and M2 tests the combined effect of social comparison and spirituality on self-esteem.

Then, the avPlots function helps visualize the contribution of each predictor, adjusting for the others.

From Linear Models to Structural Equation Modeling: Why SEM Matters

In the preliminary analysis, we used linear regression models (lm) to explore the relationships between spirituality, social/temporal comparison, and self-esteem. These models rely on composite scores—that is, the total or average scores derived from summing or averaging responses to multiple questionnaire items (e.g., Score_Spirit, Score_CompS, Score_ES). While this approach is straightforward and easy to interpret, it has several limitations:

  • Loss of Nuance: By aggregating individual items into a single score, we assume that all items contribute equally to the underlying construct (e.g., spirituality or self-esteem). This ignores the possibility that some items may be more relevant or reliable than others, or that the construct itself is multidimensional.

  • Measurement Error: Composite scores are treated as perfectly measured variables, which is rarely true in practice. Measurement error (e.g., due to poorly worded questions or individual differences in interpretation) can bias the estimated relationships between variables.

  • Limited Theoretical Flexibility: Linear regression cannot explicitly model complex theoretical relationships, such as mediation, moderation, or latent variables (unobserved constructs inferred from observed variables).

Structural Equation Modeling (SEM) addresses these limitations by offering a more sophisticated and theoretically grounded framework for analyzing relationships between variables.

Structural Equation Modeling

Theory

For a quick understanding, we propose an example of SEM (For more details, do not hesitate to see the dedicated publication Structural equation modeling and application in psychology).

This model can be interpreted as a study aiming to explain the direct effect of \(X\) on \(Y\) and the indirect effect of \(X\) on \(Y\) through \(M\). The latter variable is called the mediation variable. In detail, we have:

  • \(Y\) and \(M\) are latent endogenous variables
  • \(X\) is a latent exogenous variable
  • \(m_i\) are observed endogenous variables, for \(i \in \{1, ..., r\}\)
  • \(x_j\) are observed exogenous variables, for \(j \in \{1, ..., s\}\)
  • \(y_k\) are observed endogenous variables, for \(k \in \{1, ..., t\}\)

We can rewrite the model as a system:

\[ \begin{cases} \textbf{Measurement model} \\ m_i = \gamma_i M + \xi_{m_i}, \quad \text{for } i \in \{1, ..., r\} \\ x_j = \alpha_j X + \xi_{x_j}, \quad \text{for } j \in \{1, ..., s\} \\ y_k = \beta_k Y + \xi_{y_k}, \quad \text{for } k \in \{1, ..., t\} \\ \\ \textbf{Structural Model} \\ M = b_0 + b_1 X + \mathcal{E}_{M} \\ Y = a_0 + a_1 X + a_2 M + \mathcal{E}_Y \end{cases} \]

We can also rewrite the structural model in the form of a matrix equation:

\[ \begin{pmatrix} M \\ Y \end{pmatrix} = \begin{pmatrix} b_0 \\ a_0 \end{pmatrix} + \begin{pmatrix} b_1 & 0 \\ a_1 & a_2 \end{pmatrix} \begin{pmatrix} X \\ M \end{pmatrix} + \begin{pmatrix} \mathcal{E}_{M} \\ \mathcal{E}_Y \end{pmatrix} \]

Now, thanks to the way we wrote the model, we can make the different effects explicit. To do this, we take the structural model and substitute the first line into the second line:

\[ \begin{cases} M = b_0 + b_1 X + \mathcal{E}_{M} \\ Y = a_0 + a_1 X + a_2 M + \mathcal{E}_Y \end{cases} \]

\(\Leftrightarrow Y = a_0 + a_1 X + a_2 (b_0 + b_1 X + \mathcal{E}_{M}) + \mathcal{E}_Y\)

\(\Leftrightarrow Y = a_0 + a_2 b_0 + a_1 X + a_2 b_1 X + \mathcal{E}'\)

\(\Leftrightarrow Y = (a_0 + a_2 b_0) + (a_1 + a_2 b_1) X + \mathcal{E}'\)

Here, \(\quad \mathcal{E}' = a_2 \mathcal{E}_{M} + \mathcal{E}_Y\) with \(\mathcal{E}' \in [X]^\bot\) because \(\mathcal{E}_M \in [X]^\bot\) and \(\mathcal{E}_Y \in [X, M]^\bot\)

Therefore, we can write the effects of \(X\) on \(Y\):

\[ \underbrace{\overbrace{a_2 b_1}^{\text{Indirect effect}} + \overbrace{a_1}^{\text{Direct effect}}}_{\text{Total effect}} \]

Application

We build several model which connects the latent variables Spirituality, Social comparison, Temporal comparison and Self esteem.
Each of them being determined by different observed variables.

The library lavaan on R is usually used to estimate a large variety of multivariate statistical models, like structural equation modeling. For information, this package also permit to estimate path analysis, confirmatory factor analysis and growth curve models.
To programm a structural equation modeling on R, we proceed like this :

\[\begin{align*} & \text{Model <- `}\\ & \quad \# \; \text{latent variables} \\ & \quad \quad X =\sim x_1 + x_2 + x_3 \\ & \quad \quad M =\sim m_1 + m_2 + m_3 \\ & \quad \quad Y =\sim y_1 + y_2 + y_3\\ & \quad \# \; \text{regressions} \\ & \quad \quad M \sim X \\ & \quad \quad Y \sim M + X\\ & \quad \# \; \text{residual covariances} \\ & \quad \quad x_1 \sim \sim x_2 \quad \text{`} \end{align*}\]

We can recognize different types of operators :

  • \(=\sim\) : indicate by which observed variables is measured the latent variable
  • \(\sim \;\;\;\) : indicate by which linear regression is estimate the latent variable
  • \(\sim\sim\) : indicate the covariance between residuals

Then, to fit the model we use the following function :

\[\begin{align*} fit <- sem(\text{model} = \text{Model}, \text{ data}) \end{align*}\]

To make a summary on fit permit to obtain some informations like the AIC criterion and the BIC criterion of the model but also an estimation of the differents coefficients.

Furthermore, there is also possible to do a SEM on Python with the package semopy. The method used is similar to the one used with lavaan and the estimations are very closed.

Before to model the data frame, it is necessary to determine the four latent variables that will be used in the different models : Spirituality, Social comparison, Temporal comparison and Self-esteem.
For the variable Spirituality, we preserve all the observed variables of the study. Nevertheless, for Social comparison, Temporal comparison and Self-esteem we only keep the observed variables which have positive coefficients. We can summarize the number of observed variables per latent variables in the following tabular.

Latent Variables Number of Observed Variables
Spirituality 16
Social comparison 4
Temporal comparison 4
Self-esteem 5

Table 2: Number of observed variables per latent variable

We can express the measurement model for the latent variables with their corresponding observed variables in the form of equations:

\[ \begin{cases} \textsf{Spirituality} = \sim \textit{spirit1 + spirit2 + spirit3 + spirit4 + spirit5} \\ \quad \quad \quad \quad \quad \quad \quad + \textit{spirit6 + spirit7 + spirit8 + spirit9 + spirit10} \\ \quad \quad \quad \quad \quad \quad \quad + \textit{spirit11 + spirit12 + spirit13 + spirit14 + spirit15} \\ \quad \quad \quad \quad \quad \quad \quad + \textit{spirit16} \\ \\ \textsf{Social comparison} = \sim \textit{compSoc1 + compSoc3 + compSoc4 + compSoc6} \\ \\ \textsf{Temporal comparison} = \sim \textit{compTemp1 + compTemp3 + compTemp4} \\ \quad \quad \quad \quad \quad \quad \quad \quad \quad + \textit{compTemp6}\\ \\ \textsf{Self-esteem} = \sim \textit{es3 + es5 + es8 + es9 + es10} \end{cases} \]

Disposing of all our latent variables, it is possible to build different models of structural equations.

As seen, before, In R, the most basic way to run a linear regression is to use the lm() function which is available in base R.
If we look again at the M2 model we had :

Show the code
summary(M2)

Call:
lm(formula = Score_ES ~ Score_CompS + Score_Spirit, data = SSPM_data)

Residuals:
    Min      1Q  Median      3Q     Max 
-2.1939 -0.3667  0.0061  0.3898  1.4025 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)   4.59609    0.29881  15.381   <2e-16 ***
Score_CompS  -0.46000    0.04401 -10.453   <2e-16 ***
Score_Spirit  0.10314    0.05745   1.795   0.0735 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.5456 on 328 degrees of freedom
Multiple R-squared:  0.2813,    Adjusted R-squared:  0.277 
F-statistic:  64.2 on 2 and 328 DF,  p-value: < 2.2e-16

The predicted mean of read is 0 for a student with motiv=0 and for a one unit increase in motivation, the reading score improves 0.530 points. Make special note of the residual standard error which is . The square of that is the residual variance, which we will see later in lavaan(). We can run the equivalent code in lavaan. The syntax is very similar to lm() in that read ~ motiv specifies the predictor motiv on the outcome read. However, by default the intercept is not included in the output but is implied. If we want to add an intercept, we need to include read ~ 1 + motiv. Optionally, you can request the variance of motiv using motiv ~~ motiv. If this syntax is not provided, the parameter is still estimated but just implied.

Show the code
#simple regression using lavaan 
m1b <-   '
  # regressions
    Score_ES ~ 1 + Score_CompS + Score_Spirit
 # covariance
    Score_CompS ~~ Score_Spirit
'
fit1b <- sem(m1b, data = SSPM_data)
summary(fit1b)
lavaan 0.6-20 ended normally after 20 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         9

  Number of observations                           331

Model Test User Model:
                                                      
  Test statistic                                 0.000
  Degrees of freedom                                 0

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  Score_ES ~                                          
    Score_CompS      -0.460    0.044  -10.501    0.000
    Score_Spirit      0.103    0.057    1.803    0.071

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)
  Score_CompS ~~                                      
    Score_Spirit     -0.089    0.021   -4.162    0.000

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .Score_ES          4.596    0.297   15.451    0.000
    Score_CompS       2.401    0.039   62.310    0.000
    Score_Spirit      4.424    0.030  149.861    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .Score_ES          0.295    0.023   12.865    0.000
    Score_CompS       0.492    0.038   12.865    0.000
    Score_Spirit      0.288    0.022   12.865    0.000
Show the code
#simple regression using lavaan 
m1b <-   '
  # regressions
    Score_ES ~ 1 + Score_CompS + Score_Spirit
'
fit1b <- sem(m1b, data = SSPM_data)
summary(fit1b)
lavaan 0.6-20 ended normally after 1 iteration

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                         4

  Number of observations                           331

Model Test User Model:
                                                      
  Test statistic                                 0.000
  Degrees of freedom                                 0

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  Score_ES ~                                          
    Score_CompS      -0.460    0.044  -10.501    0.000
    Score_Spirit      0.103    0.057    1.803    0.071

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .Score_ES          4.596    0.297   15.451    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .Score_ES          0.295    0.023   12.865    0.000

The intercept of .read (-0.000) and the regression coefficient of read ~ motiv (0.530) matches the output of lm() with small rounding errors. Note that the . in front of the parameter denotes an endogenous variable under Intercepts and a residual variance if under Variances or Covariances. The intercept for motiv (0.000) does not have a . nor does its variance (99.800) signifying that it is an exogenous mean and variance. The exogenous mean and variance should closely match the univariate mean (0) and variance (100) as shown below:

Show the code
model1 <- '
# Measurement model
CompSoc =~ compSoc1 + compSoc3 + compSoc4 + compSoc6
ES =~ es3 + es5 + es8 + es9 + es10
Spirit =~ spirit1 + spirit2 + spirit3 + spirit4 + spirit5 + spirit6 + spirit7 + spirit8 + spirit9 + spirit10 + spirit11 + spirit12 + spirit13 + spirit14 + spirit15 + spirit16

# Structural model
CompSoc ~ 1 + b1 * Spirit
ES ~ 1 + a1 * Spirit + a2 * CompSoc

Direct := a1 
Indirect := b1 * a2
Total := Direct + Indirect
'

fit1 <- sem(
  model1,
  # The structural equation model
  data = SSPM_data,
  # The dataset containing the variables to be analyzed
  std.lv = T,
  # Standardization of latent variables
  # T (TRUE): Latent variables will be standardized (mean=0, standard deviation=1)
  # F (FALSE): Latent variables will not be standardized (default)
  # Useful for comparing coefficients across different models or studies
  se = "boot",
  # Method for estimating standard errors
  # "boot": Uses bootstrapping to estimate standard errors
  # Other possible options: "standard" (default), "robust", etc.
  # Bootstrapping is useful for small sample sizes or when normality assumptions are not met
  bootstrap = 100  # Number of bootstrap resamples
  # 100: Number of bootstrap replications to perform
  # Higher numbers provide more precise estimates but increase computation time
  # A minimum of 100 is often recommended, but 1000 or more is ideal for stable results
  # This parameter is only considered if se="boot"
)
summary(fit1)
Show the code
summary(fit1, fit = T, rsquare = T)
lavaan 0.6-20 ended normally after 37 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        80

  Number of observations                           331

Model Test User Model:
                                                      
  Test statistic                               789.406
  Degrees of freedom                               270
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              4059.958
  Degrees of freedom                               300
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.862
  Tucker-Lewis Index (TLI)                       0.847

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -9203.847
  Loglikelihood unrestricted model (H1)      -8809.144
                                                      
  Akaike (AIC)                               18567.694
  Bayesian (BIC)                             18871.863
  Sample-size adjusted Bayesian (SABIC)      18618.101

Root Mean Square Error of Approximation:

  RMSEA                                          0.076
  90 Percent confidence interval - lower         0.070
  90 Percent confidence interval - upper         0.082
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    0.161

Standardized Root Mean Square Residual:

  SRMR                                           0.060

Parameter Estimates:

  Standard errors                            Bootstrap
  Number of requested bootstrap draws              100
  Number of successful bootstrap draws             100

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  CompSoc =~                                          
    compSoc1          0.322    0.084    3.840    0.000
    compSoc3          0.916    0.074   12.364    0.000
    compSoc4          0.865    0.069   12.619    0.000
    compSoc6          0.388    0.074    5.255    0.000
  ES =~                                               
    es3               0.601    0.063    9.523    0.000
    es5               0.712    0.067   10.663    0.000
    es8               0.585    0.066    8.835    0.000
    es9               1.032    0.057   18.210    0.000
    es10              1.024    0.063   16.332    0.000
  Spirit =~                                           
    spirit1           0.334    0.039    8.556    0.000
    spirit2           0.579    0.047   12.388    0.000
    spirit3           0.462    0.041   11.400    0.000
    spirit4           0.425    0.060    7.025    0.000
    spirit5           0.491    0.033   14.766    0.000
    spirit6           0.490    0.041   11.982    0.000
    spirit7           0.598    0.048   12.570    0.000
    spirit8           0.445    0.053    8.463    0.000
    spirit9           0.529    0.045   11.684    0.000
    spirit10          0.563    0.050   11.267    0.000
    spirit11          0.626    0.039   16.083    0.000
    spirit12          0.547    0.045   12.119    0.000
    spirit13          0.519    0.053    9.748    0.000
    spirit14          0.555    0.052   10.608    0.000
    spirit15          0.574    0.052   11.097    0.000
    spirit16          0.508    0.050   10.105    0.000

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  CompSoc ~                                           
    Spirit    (b1)    0.363    0.082    4.444    0.000
  ES ~                                                
    Spirit    (a1)   -0.034    0.061   -0.550    0.582
    CompSoc   (a2)   -0.258    0.086   -3.017    0.003

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .CompSoc           0.000    0.010    0.000    1.000
   .ES                0.000    0.021    0.000    1.000
   .compSoc1          3.341    0.065   51.535    0.000
   .compSoc3          3.677    0.057   64.719    0.000
   .compSoc4          3.677    0.058   63.081    0.000
   .compSoc6          3.782    0.066   56.955    0.000
   .es3               1.755    0.038   45.635    0.000
   .es5               2.006    0.044   45.206    0.000
   .es8               3.369    0.071   47.648    0.000
   .es9               2.438    0.049   49.468    0.000
   .es10              2.178    0.047   46.431    0.000
   .spirit1           4.740    0.031  151.550    0.000
   .spirit2           4.248    0.048   87.605    0.000
   .spirit3           4.607    0.035  131.830    0.000
   .spirit4           4.674    0.037  125.548    0.000
   .spirit5           4.356    0.043  101.477    0.000
   .spirit6           4.438    0.045   99.448    0.000
   .spirit7           4.459    0.044  101.948    0.000
   .spirit8           4.698    0.035  135.047    0.000
   .spirit9           4.447    0.046   96.231    0.000
   .spirit10          4.474    0.039  113.651    0.000
   .spirit11          4.054    0.053   76.776    0.000
   .spirit12          4.495    0.044  102.862    0.000
   .spirit13          4.009    0.050   80.829    0.000
   .spirit14          4.411    0.046   96.643    0.000
   .spirit15          4.260    0.045   94.111    0.000
   .spirit16          4.414    0.044   99.457    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .compSoc1          1.352    0.093   14.569    0.000
   .compSoc3          0.526    0.123    4.262    0.000
   .compSoc4          0.574    0.110    5.242    0.000
   .compSoc6          1.371    0.118   11.654    0.000
   .es3               0.567    0.081    7.023    0.000
   .es5               0.593    0.104    5.688    0.000
   .es8               1.415    0.085   16.654    0.000
   .es9               0.463    0.094    4.944    0.000
   .es10              0.401    0.087    4.623    0.000
   .spirit1           0.189    0.030    6.261    0.000
   .spirit2           0.479    0.068    7.019    0.000
   .spirit3           0.158    0.019    8.355    0.000
   .spirit4           0.245    0.031    7.873    0.000
   .spirit5           0.381    0.054    7.045    0.000
   .spirit6           0.369    0.056    6.621    0.000
   .spirit7           0.283    0.043    6.524    0.000
   .spirit8           0.140    0.018    7.640    0.000
   .spirit9           0.372    0.047    7.858    0.000
   .spirit10          0.253    0.029    8.871    0.000
   .spirit11          0.458    0.042   10.940    0.000
   .spirit12          0.229    0.030    7.637    0.000
   .spirit13          0.803    0.083    9.665    0.000
   .spirit14          0.315    0.036    8.743    0.000
   .spirit15          0.497    0.067    7.476    0.000
   .spirit16          0.378    0.042    9.084    0.000
   .CompSoc           1.000                           
   .ES                1.000                           
    Spirit            1.000                           

R-Square:
                   Estimate
    compSoc1          0.080
    compSoc3          0.644
    compSoc4          0.596
    compSoc6          0.111
    es3               0.408
    es5               0.481
    es8               0.208
    es9               0.714
    es10              0.739
    spirit1           0.371
    spirit2           0.412
    spirit3           0.575
    spirit4           0.425
    spirit5           0.388
    spirit6           0.394
    spirit7           0.559
    spirit8           0.586
    spirit9           0.429
    spirit10          0.556
    spirit11          0.461
    spirit12          0.566
    spirit13          0.251
    spirit14          0.494
    spirit15          0.398
    spirit16          0.405
    CompSoc           0.117
    ES                0.077

Defined Parameters:
                   Estimate  Std.Err  z-value  P(>|z|)
    Direct           -0.034    0.061   -0.550    0.582
    Indirect         -0.094    0.038   -2.495    0.013
    Total            -0.128    0.060   -2.133    0.033

The aim is to analyze direct and indirect effects on Self-esteem for the model fit1. To reference the first part, we rename our latent variables:

\[ \begin{cases} X := \textsf{Spirituality} \\ M_1 := \textsf{Social comparison} \\ Y := \textsf{Self-esteem} \end{cases} \]

This is a mediation model. It is possible to analyze the direct and indirect effects on \(Y\).

First, we make explicit the structural model and substitute in the expression of \(Y\):

\[ \begin{cases} M_1 = b_0 + b_1 X + \mathcal{E}_{M_1} \\ Y = a_0 + a_1 X + a_2 M_1 + \mathcal{E}_Y \end{cases} \]

\(\Leftrightarrow Y = (a_0 + a_2 b_0) + (a_1 + a_2 b_1) X + \mathcal{E}'\)

We can verify that the model is identifiable by looking if the degree of freedom is greater than 0 :

Show the code
cat("Degree of fredom for fit1 :", semPower::semPower.getDf(fit1))
Degree of fredom for fit1 : 270

Finally, with the summary of the fit of the model fit1 in R, we can build the following table:

Effect Expression Estimate Std.Err P-value
Direct \(a_1\) -0.034 0.061 0.582
Indirect \(a_2 b_1\) -0.094 0.038 0.013
Total \(a_1 + a_2 b_1\) -0.128 0.060 0.033

Table 3: Effects on \(Y\) for the model fit1

We can conclude that in the model fit1, the indirect effect is significant for the variable Self-esteem.

Show the code
model2 <- '
# Measurement model
CompTemp =~ compTemp1 + compTemp3 + compTemp4 + compTemp6 
ES =~ es3 + es5 + es8 + es9 + es10
Spirit =~ spirit1 + spirit2 + spirit3 + spirit4 + spirit5 + spirit6 + spirit7 + spirit8 + spirit9 + spirit10 + spirit11 + spirit12 + spirit13 + spirit14 + spirit15 + spirit16

# Structural model
CompTemp ~ 1 + b1 * Spirit
ES ~ 1 + a1 * Spirit + a2 * CompTemp

Direct := a1 
Indirect := b1 * a2
Total := Direct + Indirect
'

fit2 <- sem(
  model2,
  data = SSPM_data,
  std.lv = T,
  se = "boot",
  bootstrap = 100
)
summary(fit2)
Show the code
summary(fit2, fit = T, rsquare = T)
lavaan 0.6-20 ended normally after 38 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        80

  Number of observations                           331

Model Test User Model:
                                                      
  Test statistic                               798.679
  Degrees of freedom                               270
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              4261.841
  Degrees of freedom                               300
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.867
  Tucker-Lewis Index (TLI)                       0.852

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -9124.922
  Loglikelihood unrestricted model (H1)      -8725.582
                                                      
  Akaike (AIC)                               18409.843
  Bayesian (BIC)                             18714.013
  Sample-size adjusted Bayesian (SABIC)      18460.251

Root Mean Square Error of Approximation:

  RMSEA                                          0.077
  90 Percent confidence interval - lower         0.071
  90 Percent confidence interval - upper         0.083
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    0.209

Standardized Root Mean Square Residual:

  SRMR                                           0.058

Parameter Estimates:

  Standard errors                            Bootstrap
  Number of requested bootstrap draws              100
  Number of successful bootstrap draws             100

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  CompTemp =~                                         
    compTemp1         0.790    0.064   12.366    0.000
    compTemp3         0.886    0.062   14.260    0.000
    compTemp4         1.042    0.048   21.574    0.000
    compTemp6         0.740    0.078    9.536    0.000
  ES =~                                               
    es3               0.622    0.066    9.424    0.000
    es5               0.737    0.068   10.845    0.000
    es8               0.599    0.069    8.680    0.000
    es9               1.066    0.058   18.327    0.000
    es10              1.055    0.063   16.635    0.000
  Spirit =~                                           
    spirit1           0.335    0.039    8.569    0.000
    spirit2           0.580    0.047   12.450    0.000
    spirit3           0.462    0.041   11.354    0.000
    spirit4           0.425    0.061    7.031    0.000
    spirit5           0.492    0.033   14.767    0.000
    spirit6           0.491    0.041   11.992    0.000
    spirit7           0.599    0.047   12.613    0.000
    spirit8           0.445    0.053    8.459    0.000
    spirit9           0.529    0.045   11.636    0.000
    spirit10          0.562    0.050   11.195    0.000
    spirit11          0.626    0.039   16.080    0.000
    spirit12          0.547    0.045   12.091    0.000
    spirit13          0.519    0.053    9.731    0.000
    spirit14          0.553    0.052   10.546    0.000
    spirit15          0.573    0.052   11.002    0.000
    spirit16          0.505    0.050   10.047    0.000

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  CompTemp ~                                          
    Spirit    (b1)    0.153    0.063    2.437    0.015
  ES ~                                                
    Spirit    (a1)   -0.128    0.058   -2.221    0.026
    CompTemp  (a2)    0.029    0.070    0.413    0.679

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .CompTemp          0.000    0.015    0.000    1.000
   .ES                0.000    0.022    0.000    1.000
   .compTemp1         2.725    0.063   43.112    0.000
   .compTemp3         3.036    0.047   64.128    0.000
   .compTemp4         2.897    0.053   54.381    0.000
   .compTemp6         3.088    0.062   50.146    0.000
   .es3               1.755    0.039   45.502    0.000
   .es5               2.006    0.044   45.126    0.000
   .es8               3.369    0.071   47.553    0.000
   .es9               2.438    0.049   49.278    0.000
   .es10              2.178    0.047   46.288    0.000
   .spirit1           4.740    0.031  151.549    0.000
   .spirit2           4.248    0.048   87.605    0.000
   .spirit3           4.607    0.035  131.831    0.000
   .spirit4           4.674    0.037  125.548    0.000
   .spirit5           4.356    0.043  101.478    0.000
   .spirit6           4.438    0.045   99.448    0.000
   .spirit7           4.459    0.044  101.948    0.000
   .spirit8           4.698    0.035  135.046    0.000
   .spirit9           4.447    0.046   96.231    0.000
   .spirit10          4.474    0.039  113.651    0.000
   .spirit11          4.054    0.053   76.776    0.000
   .spirit12          4.495    0.044  102.863    0.000
   .spirit13          4.009    0.050   80.829    0.000
   .spirit14          4.411    0.046   96.643    0.000
   .spirit15          4.260    0.045   94.111    0.000
   .spirit16          4.414    0.044   99.457    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .compTemp1         1.005    0.115    8.749    0.000
   .compTemp3         0.573    0.092    6.252    0.000
   .compTemp4         0.330    0.071    4.653    0.000
   .compTemp6         1.060    0.121    8.794    0.000
   .es3               0.565    0.083    6.789    0.000
   .es5               0.589    0.108    5.470    0.000
   .es8               1.421    0.085   16.653    0.000
   .es9               0.462    0.099    4.653    0.000
   .es10              0.405    0.093    4.344    0.000
   .spirit1           0.189    0.030    6.216    0.000
   .spirit2           0.479    0.068    7.044    0.000
   .spirit3           0.158    0.019    8.368    0.000
   .spirit4           0.244    0.031    7.819    0.000
   .spirit5           0.380    0.054    7.064    0.000
   .spirit6           0.368    0.056    6.621    0.000
   .spirit7           0.282    0.043    6.567    0.000
   .spirit8           0.139    0.018    7.639    0.000
   .spirit9           0.373    0.047    7.910    0.000
   .spirit10          0.254    0.029    8.878    0.000
   .spirit11          0.457    0.042   10.965    0.000
   .spirit12          0.229    0.030    7.645    0.000
   .spirit13          0.803    0.083    9.649    0.000
   .spirit14          0.317    0.036    8.711    0.000
   .spirit15          0.499    0.067    7.461    0.000
   .spirit16          0.380    0.042    9.126    0.000
   .CompTemp          1.000                           
   .ES                1.000                           
    Spirit            1.000                           

R-Square:
                   Estimate
    compTemp1         0.388
    compTemp3         0.584
    compTemp4         0.771
    compTemp6         0.346
    es3               0.411
    es5               0.484
    es8               0.204
    es9               0.714
    es10              0.736
    spirit1           0.374
    spirit2           0.412
    spirit3           0.575
    spirit4           0.425
    spirit5           0.389
    spirit6           0.396
    spirit7           0.559
    spirit8           0.588
    spirit9           0.428
    spirit10          0.554
    spirit11          0.462
    spirit12          0.566
    spirit13          0.251
    spirit14          0.491
    spirit15          0.396
    spirit16          0.402
    CompTemp          0.023
    ES                0.016

Defined Parameters:
                   Estimate  Std.Err  z-value  P(>|z|)
    Direct           -0.128    0.058   -2.221    0.026
    Indirect          0.004    0.012    0.354    0.723
    Total            -0.124    0.057   -2.164    0.030

The aim is to analyze direct and indirect effects on Self-esteem for the model fit2. To reference the first part, we rename our latent variables:

\[ \begin{cases} X := \textsf{Spirituality} \\ M_2 := \textsf{Temporal comparison} \\ Y := \textsf{Self-esteem} \end{cases} \]

This is still a mediation model. It is possible to analyze the direct and indirect effects on \(Y\).

First, we make explicit the structural model and substitute in the expression of \(Y\):

\[ \begin{cases} M_2 = b_0 + b_1 X + \mathcal{E}_{M_2} \\ Y = a_0 + a_1 X + a_2 M_2 + \mathcal{E}_Y \end{cases} \]

\(\Leftrightarrow Y = (a_0 + a_2 b_0) + (a_1 + a_2 b_1) X + \mathcal{E}'\)

We can verify that the model is identifiable by looking if the degree of freedom is greater than 0 :

Show the code
cat("Degree of fredom for fit2 :", semPower::semPower.getDf(fit2))
Degree of fredom for fit2 : 245

Finally, with the summary of the fit of the model fit2 in R, we can build the following table:

Effect Expression Estimate Std.Err P-value
Direct \(a_1\) -0.128 0.058 0.026
Indirect \(a_2 b_1\) 0.004 0.012 0.723
Total \(a_1 + a_2 b_1\) -0.124 0.057 0.030

Table ?????,: Effects on \(Y\) for the model fit2

We can conclude that in the model fit2, the direct effect is significant for the variable Self-esteem.

Show the code
model3 <- '
# Measurement model
CompSoc =~ compSoc1 + compSoc3 + compSoc4 + compSoc6
CompTemp =~ compTemp1 + compTemp3 + compTemp4 + compTemp6
ES =~ es3 + es5 + es8 + es9 + es10
Spirit =~ spirit1 + spirit2 + spirit3 + spirit4 + spirit5 + spirit6 + spirit7 + spirit8 + spirit9 + spirit10 + spirit11 + spirit12 + spirit13 + spirit14 + spirit15 + spirit16

# Structural model
CompSoc ~ 1 + c1 * Spirit
CompTemp ~ 1 + b1 * Spirit
ES ~ 1 + a1 * Spirit + a2 * CompSoc + a3 * CompTemp

Direct := a1
Indirect1 := (c1 * a2) 
Indirect2 := (b1 * a3)
Indirect := (c1 * a2) + (b1 * a3)
Total := Direct + Indirect
'

fit3 <- sem(
  model3,
  data = SSPM_data,
  std.lv = T,
  se = "boot",
  bootstrap = 100
)
summary(fit3)
Show the code
summary(fit3, fit = T, rsquare = T)
lavaan 0.6-20 ended normally after 39 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        95

  Number of observations                           331

Model Test User Model:
                                                      
  Test statistic                              1006.804
  Degrees of freedom                               369
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              4728.539
  Degrees of freedom                               406
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.852
  Tucker-Lewis Index (TLI)                       0.838

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)             -11132.232
  Loglikelihood unrestricted model (H1)     -10628.830
                                                      
  Akaike (AIC)                               22454.464
  Bayesian (BIC)                             22815.665
  Sample-size adjusted Bayesian (SABIC)      22514.322

Root Mean Square Error of Approximation:

  RMSEA                                          0.072
  90 Percent confidence interval - lower         0.067
  90 Percent confidence interval - upper         0.078
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    0.009

Standardized Root Mean Square Residual:

  SRMR                                           0.070

Parameter Estimates:

  Standard errors                            Bootstrap
  Number of requested bootstrap draws              100
  Number of successful bootstrap draws             100

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  CompSoc =~                                          
    compSoc1          0.322    0.084    3.853    0.000
    compSoc3          0.917    0.074   12.426    0.000
    compSoc4          0.861    0.069   12.482    0.000
    compSoc6          0.388    0.074    5.241    0.000
  CompTemp =~                                         
    compTemp1         0.794    0.064   12.418    0.000
    compTemp3         0.887    0.061   14.516    0.000
    compTemp4         1.034    0.049   21.260    0.000
    compTemp6         0.740    0.077    9.613    0.000
  ES =~                                               
    es3               0.597    0.062    9.663    0.000
    es5               0.706    0.065   10.824    0.000
    es8               0.580    0.065    8.975    0.000
    es9               1.018    0.063   16.116    0.000
    es10              1.008    0.069   14.658    0.000
  Spirit =~                                           
    spirit1           0.334    0.039    8.556    0.000
    spirit2           0.579    0.047   12.384    0.000
    spirit3           0.462    0.041   11.384    0.000
    spirit4           0.425    0.060    7.021    0.000
    spirit5           0.492    0.033   14.777    0.000
    spirit6           0.490    0.041   12.006    0.000
    spirit7           0.598    0.048   12.511    0.000
    spirit8           0.444    0.053    8.442    0.000
    spirit9           0.530    0.045   11.695    0.000
    spirit10          0.563    0.050   11.270    0.000
    spirit11          0.626    0.039   16.087    0.000
    spirit12          0.546    0.045   12.107    0.000
    spirit13          0.519    0.053    9.748    0.000
    spirit14          0.554    0.052   10.584    0.000
    spirit15          0.575    0.052   11.123    0.000
    spirit16          0.507    0.050   10.089    0.000

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  CompSoc ~                                           
    Spirit    (c1)    0.369    0.083    4.427    0.000
  CompTemp ~                                          
    Spirit    (b1)    0.164    0.064    2.543    0.011
  ES ~                                                
    Spirit    (a1)   -0.036    0.062   -0.582    0.561
    CompSoc   (a2)   -0.315    0.102   -3.101    0.002
    CompTemp  (a3)    0.141    0.083    1.685    0.092

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .CompSoc           0.000    0.011    0.000    1.000
   .CompTemp          0.000    0.015    0.000    1.000
   .ES                0.000    0.021    0.000    1.000
   .compSoc1          3.341    0.065   51.567    0.000
   .compSoc3          3.677    0.057   64.948    0.000
   .compSoc4          3.677    0.058   63.252    0.000
   .compSoc6          3.782    0.066   56.981    0.000
   .compTemp1         2.725    0.063   43.184    0.000
   .compTemp3         3.036    0.048   63.882    0.000
   .compTemp4         2.897    0.054   53.961    0.000
   .compTemp6         3.088    0.062   50.090    0.000
   .es3               1.755    0.038   45.855    0.000
   .es5               2.006    0.044   45.476    0.000
   .es8               3.369    0.071   47.662    0.000
   .es9               2.438    0.049   49.382    0.000
   .es10              2.178    0.047   46.383    0.000
   .spirit1           4.740    0.031  151.549    0.000
   .spirit2           4.248    0.048   87.605    0.000
   .spirit3           4.607    0.035  131.830    0.000
   .spirit4           4.674    0.037  125.549    0.000
   .spirit5           4.356    0.043  101.478    0.000
   .spirit6           4.438    0.045   99.449    0.000
   .spirit7           4.459    0.044  101.948    0.000
   .spirit8           4.698    0.035  135.047    0.000
   .spirit9           4.447    0.046   96.231    0.000
   .spirit10          4.474    0.039  113.651    0.000
   .spirit11          4.054    0.053   76.776    0.000
   .spirit12          4.495    0.044  102.863    0.000
   .spirit13          4.009    0.050   80.829    0.000
   .spirit14          4.411    0.046   96.643    0.000
   .spirit15          4.260    0.045   94.111    0.000
   .spirit16          4.414    0.044   99.458    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .compSoc1          1.352    0.093   14.570    0.000
   .compSoc3          0.521    0.123    4.243    0.000
   .compSoc4          0.579    0.110    5.274    0.000
   .compSoc6          1.371    0.118   11.646    0.000
   .compTemp1         0.996    0.116    8.624    0.000
   .compTemp3         0.568    0.090    6.342    0.000
   .compTemp4         0.342    0.070    4.857    0.000
   .compTemp6         1.058    0.120    8.796    0.000
   .es3               0.562    0.082    6.825    0.000
   .es5               0.588    0.106    5.565    0.000
   .es8               1.412    0.084   16.731    0.000
   .es9               0.467    0.098    4.783    0.000
   .es10              0.408    0.091    4.498    0.000
   .spirit1           0.189    0.030    6.273    0.000
   .spirit2           0.479    0.068    7.016    0.000
   .spirit3           0.158    0.019    8.332    0.000
   .spirit4           0.245    0.031    7.892    0.000
   .spirit5           0.380    0.054    7.051    0.000
   .spirit6           0.369    0.056    6.619    0.000
   .spirit7           0.284    0.043    6.523    0.000
   .spirit8           0.140    0.018    7.651    0.000
   .spirit9           0.371    0.047    7.900    0.000
   .spirit10          0.253    0.028    8.882    0.000
   .spirit11          0.457    0.042   10.963    0.000
   .spirit12          0.229    0.030    7.638    0.000
   .spirit13          0.803    0.083    9.658    0.000
   .spirit14          0.316    0.036    8.755    0.000
   .spirit15          0.497    0.067    7.462    0.000
   .spirit16          0.378    0.042    9.097    0.000
   .CompSoc           1.000                           
   .CompTemp          1.000                           
   .ES                1.000                           
    Spirit            1.000                           

R-Square:
                   Estimate
    compSoc1          0.080
    compSoc3          0.647
    compSoc4          0.592
    compSoc6          0.111
    compTemp1         0.394
    compTemp3         0.587
    compTemp4         0.763
    compTemp6         0.347
    es3               0.419
    es5               0.491
    es8               0.213
    es9               0.716
    es10              0.739
    spirit1           0.371
    spirit2           0.412
    spirit3           0.574
    spirit4           0.424
    spirit5           0.389
    spirit6           0.394
    spirit7           0.558
    spirit8           0.584
    spirit9           0.431
    spirit10          0.556
    spirit11          0.461
    spirit12          0.565
    spirit13          0.251
    spirit14          0.493
    spirit15          0.399
    spirit16          0.405
    CompSoc           0.120
    CompTemp          0.026
    ES                0.120

Defined Parameters:
                   Estimate  Std.Err  z-value  P(>|z|)
    Direct           -0.036    0.062   -0.582    0.561
    Indirect1        -0.116    0.047   -2.478    0.013
    Indirect2         0.023    0.019    1.188    0.235
    Indirect         -0.093    0.038   -2.462    0.014
    Total            -0.129    0.061   -2.124    0.034

The aim is to analyse direct and indirect effects on Self-esteem for the model fit3. To reference to the first part, we rename our latent variables as we already have done for fit1 and fit2 :

\[ \begin{cases} X := \textsf{Spirituality} \\ M_1 := \textsf{Social comparison} \\ M_2 := \textsf{Temporal comparison} \\ Y := \textsf{Self-esteem} \end{cases} \]

This is a parallel mediation model. It is possible to analyse the direct and indirect effects on \(Y\). Before that, we explicit the structural model and we substitute in the expression of \(Y\).

\[ \begin{cases} M_1 = c_0 + c_1X + \mathcal{E}_{M_1}\\ M_2 = b_0 + b_1 X + \mathcal{E}_{M_2} \\ Y = a_0 + a_1 X + a_2 M_1 + a_3M_2 + \mathcal{E}_Y \end{cases} \] \[\Leftrightarrow Y = (a_0 + a_2c_0 + a_3b_0) + (a_1 + a_2c_1 + a_3b_1)X + \mathcal{E}'\] We can verify that the model is identifiable by looking if the degree of freedom is greater than 0 :

Show the code
cat("Degree of fredom for fit3 :", semPower::semPower.getDf(fit3))
Degree of fredom for fit3 : 369

Finally, with the summary of the fit of the model fit3 in R, we can build the following table:

Effect Expression Estimate Std.Err P-value
Direct \(a_1\) -0.036 0.062 0.561
Indirect1 \(a_2 c_1\) -0.116 0.047 0.013
Indirect2 \(a_3 b_1\) 0.023 0.019 0.235
Indirect \(a_2 c_1 + a_3 b_1\) -0.093 0.038 0.014
Total \(a_1 + a_2 c_1 + a_3 b_1\) -0.129 0.061 0.034

Table ?????,: Effects on \(Y\) for the model fit3

We can conclude that in the model fit3, the indirect effect is significant for the variable Self-esteem.
Especially, the most significant effect is given by the path :
Spirituality \(\rightarrow\) Social comparison \(\rightarrow\) Self-esteem.

Show the code
model4 <- '
# Measurement model
CompSoc =~ compSoc1 + compSoc3 + compSoc4 + compSoc6
CompTemp =~ compTemp1 + compTemp3 + compTemp4 + compTemp6
ES =~ es3 + es5 + es8 + es9 + es10
Spirit =~ spirit1 + spirit2 + spirit3 + spirit4 + spirit5 + spirit6 + spirit7 + spirit8 + spirit9 + spirit10 + spirit11 + spirit12 + spirit13 + spirit14 + spirit15 + spirit16

# Structural model
CompSoc ~ 1 + c1 * Spirit
CompTemp ~ 1 + b1 * Spirit + b2 * CompSoc
ES ~ 1 + a1 * Spirit + a2 * CompSoc + a3 * CompTemp

Direct := a1
Indirect1 := (c1 * a2) 
Indirect2 := (b1 * a3)
Indirect3 := (c1 * b2 * a3)
Indirect := (c1 * a2) + (b1 * a3) + (c1 * b2 * a3)
Total := Direct + Indirect
'

fit4 <- sem(
  model4,
  data = SSPM_data,
  std.lv = T,
  se = "boot",
  bootstrap = 100
)
summary(fit4)
Show the code
summary(fit4, fit = T, rsquare = T)
lavaan 0.6-20 ended normally after 36 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of model parameters                        96

  Number of observations                           331

Model Test User Model:
                                                      
  Test statistic                               958.542
  Degrees of freedom                               368
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                              4728.539
  Degrees of freedom                               406
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.863
  Tucker-Lewis Index (TLI)                       0.849

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)             -11108.101
  Loglikelihood unrestricted model (H1)     -10628.830
                                                      
  Akaike (AIC)                               22408.201
  Bayesian (BIC)                             22773.205
  Sample-size adjusted Bayesian (SABIC)      22468.690

Root Mean Square Error of Approximation:

  RMSEA                                          0.070
  90 Percent confidence interval - lower         0.064
  90 Percent confidence interval - upper         0.075
  P-value H_0: RMSEA <= 0.050                    0.000
  P-value H_0: RMSEA >= 0.080                    0.001

Standardized Root Mean Square Residual:

  SRMR                                           0.059

Parameter Estimates:

  Standard errors                            Bootstrap
  Number of requested bootstrap draws              100
  Number of successful bootstrap draws             100

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)
  CompSoc =~                                          
    compSoc1          0.339    0.084    4.021    0.000
    compSoc3          0.933    0.073   12.859    0.000
    compSoc4          0.844    0.065   12.933    0.000
    compSoc6          0.383    0.074    5.180    0.000
  CompTemp =~                                         
    compTemp1         0.711    0.065   11.000    0.000
    compTemp3         0.802    0.060   13.370    0.000
    compTemp4         0.891    0.057   15.662    0.000
    compTemp6         0.657    0.066   10.009    0.000
  ES =~                                               
    es3               0.595    0.061    9.685    0.000
    es5               0.704    0.065   10.812    0.000
    es8               0.578    0.064    8.964    0.000
    es9               1.015    0.064   15.832    0.000
    es10              1.005    0.070   14.429    0.000
  Spirit =~                                           
    spirit1           0.334    0.039    8.555    0.000
    spirit2           0.579    0.047   12.392    0.000
    spirit3           0.462    0.041   11.389    0.000
    spirit4           0.425    0.060    7.024    0.000
    spirit5           0.492    0.033   14.769    0.000
    spirit6           0.490    0.041   11.992    0.000
    spirit7           0.598    0.048   12.552    0.000
    spirit8           0.445    0.053    8.456    0.000
    spirit9           0.529    0.045   11.677    0.000
    spirit10          0.563    0.050   11.262    0.000
    spirit11          0.626    0.039   16.087    0.000
    spirit12          0.547    0.045   12.119    0.000
    spirit13          0.519    0.053    9.749    0.000
    spirit14          0.554    0.052   10.593    0.000
    spirit15          0.574    0.052   11.097    0.000
    spirit16          0.507    0.050   10.094    0.000

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)
  CompSoc ~                                           
    Spirit    (c1)    0.364    0.082    4.450    0.000
  CompTemp ~                                          
    Spirit    (b1)   -0.011    0.062   -0.173    0.862
    CompSoc   (b2)    0.529    0.102    5.163    0.000
  ES ~                                                
    Spirit    (a1)   -0.033    0.063   -0.518    0.604
    CompSoc   (a2)   -0.356    0.118   -3.024    0.002
    CompTemp  (a3)    0.177    0.087    2.030    0.042

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)
   .CompSoc           0.000    0.014    0.000    1.000
   .CompTemp          0.000    0.014    0.000    1.000
   .ES                0.000    0.021    0.000    1.000
   .compSoc1          3.341    0.064   52.388    0.000
   .compSoc3          3.677    0.055   67.427    0.000
   .compSoc4          3.677    0.058   63.882    0.000
   .compSoc6          3.782    0.066   56.999    0.000
   .compTemp1         2.725    0.062   43.710    0.000
   .compTemp3         3.036    0.047   65.250    0.000
   .compTemp4         2.897    0.054   53.876    0.000
   .compTemp6         3.088    0.061   50.578    0.000
   .es3               1.755    0.038   45.765    0.000
   .es5               2.006    0.044   45.281    0.000
   .es8               3.369    0.071   47.635    0.000
   .es9               2.438    0.049   49.278    0.000
   .es10              2.178    0.047   46.226    0.000
   .spirit1           4.740    0.031  151.550    0.000
   .spirit2           4.248    0.048   87.605    0.000
   .spirit3           4.607    0.035  131.830    0.000
   .spirit4           4.674    0.037  125.547    0.000
   .spirit5           4.356    0.043  101.477    0.000
   .spirit6           4.438    0.045   99.448    0.000
   .spirit7           4.459    0.044  101.948    0.000
   .spirit8           4.698    0.035  135.047    0.000
   .spirit9           4.447    0.046   96.231    0.000
   .spirit10          4.474    0.039  113.651    0.000
   .spirit11          4.054    0.053   76.776    0.000
   .spirit12          4.495    0.044  102.863    0.000
   .spirit13          4.009    0.050   80.829    0.000
   .spirit14          4.411    0.046   96.643    0.000
   .spirit15          4.260    0.045   94.111    0.000
   .spirit16          4.414    0.044   99.457    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)
   .compSoc1          1.340    0.094   14.194    0.000
   .compSoc3          0.490    0.118    4.168    0.000
   .compSoc4          0.614    0.101    6.062    0.000
   .compSoc6          1.376    0.116   11.884    0.000
   .compTemp1         0.981    0.113    8.643    0.000
   .compTemp3         0.532    0.085    6.275    0.000
   .compTemp4         0.397    0.069    5.785    0.000
   .compTemp6         1.054    0.120    8.803    0.000
   .es3               0.562    0.082    6.823    0.000
   .es5               0.588    0.106    5.560    0.000
   .es8               1.412    0.084   16.729    0.000
   .es9               0.467    0.098    4.783    0.000
   .es10              0.408    0.091    4.499    0.000
   .spirit1           0.189    0.030    6.260    0.000
   .spirit2           0.479    0.068    7.022    0.000
   .spirit3           0.158    0.019    8.340    0.000
   .spirit4           0.245    0.031    7.875    0.000
   .spirit5           0.380    0.054    7.054    0.000
   .spirit6           0.369    0.056    6.621    0.000
   .spirit7           0.283    0.043    6.522    0.000
   .spirit8           0.140    0.018    7.641    0.000
   .spirit9           0.372    0.047    7.881    0.000
   .spirit10          0.253    0.028    8.876    0.000
   .spirit11          0.457    0.042   10.954    0.000
   .spirit12          0.229    0.030    7.640    0.000
   .spirit13          0.803    0.083    9.663    0.000
   .spirit14          0.315    0.036    8.738    0.000
   .spirit15          0.497    0.067    7.470    0.000
   .spirit16          0.378    0.042    9.093    0.000
   .CompSoc           1.000                           
   .CompTemp          1.000                           
   .ES                1.000                           
    Spirit            1.000                           

R-Square:
                   Estimate
    compSoc1          0.088
    compSoc3          0.668
    compSoc4          0.568
    compSoc6          0.108
    compTemp1         0.403
    compTemp3         0.614
    compTemp4         0.724
    compTemp6         0.350
    es3               0.413
    es5               0.485
    es8               0.209
    es9               0.711
    es10              0.734
    spirit1           0.371
    spirit2           0.412
    spirit3           0.575
    spirit4           0.425
    spirit5           0.388
    spirit6           0.394
    spirit7           0.559
    spirit8           0.585
    spirit9           0.429
    spirit10          0.556
    spirit11          0.461
    spirit12          0.566
    spirit13          0.251
    spirit14          0.494
    spirit15          0.398
    spirit16          0.405
    CompSoc           0.117
    CompTemp          0.238
    ES                0.105

Defined Parameters:
                   Estimate  Std.Err  z-value  P(>|z|)
    Direct           -0.033    0.063   -0.518    0.604
    Indirect1        -0.129    0.053   -2.458    0.014
    Indirect2        -0.002    0.013   -0.150    0.880
    Indirect3         0.034    0.021    1.606    0.108
    Indirect         -0.097    0.039   -2.461    0.014
    Total            -0.130    0.061   -2.125    0.034

The aim is to analyse direct and indirect effects on Self-esteem for the model fit4. To reference to the first part, we rename our latent variables as we already have done for fit1 and fit2 :

\[ \begin{cases} X := \textsf{Spirituality} \\ M_1 := \textsf{Social comparison} \\ M_2 := \textsf{Temporal comparison} \\ Y := \textsf{Self-esteem} \end{cases} \]

This is a serial mediation model. It is possible to analyse the direct and indirect effects on \(Y\). Before that, we explicit the structural model and we substitute in the expression of \(Y\).

\[ \begin{cases} M_1 = c_0 + c_1X + \mathcal{E}_{M_1}\\ M_2 = b_0 + b_1 X + b_2 M_2 + \mathcal{E}_{M_2} \\ Y = a_0 + a_1 X + a_2 M_1 + a_3M_2 + \mathcal{E}_Y \end{cases} \] \[\Leftrightarrow Y = (a_0 + a_2c_0 + a_3b_0 + a_3b_2c_0) + (a_1 + a_2c_1 + a_3b_1 + a_3b_2c_1)X + \mathcal{E}'\] We can verify that the model is identifiable by looking if the degree of freedom is greater than 0 :

Show the code
cat("Degree of fredom for fit4 :", semPower::semPower.getDf(fit4))
Degree of fredom for fit4 : 368

Finally, with the summary of the fit of the model fi43 in R, we can build the following table:

Effect Expression Estimate Std.Err P-value
Direct \(a_1\) -0.033 0.063 0.604
Indirect1 \(a_2 c_1\) -0.129 0.053 0.014
Indirect2 \(a_3 b_1\) -0.002 0.013 0.880
Indirect3 \(a_3b_2c_1\) 0.034 0.021 0.108
Indirect \(a_2 c_1 + a_3 b_1 + a_3b_2c_1\) -0.097 0.039 0.014
Total \(a_1 + a_2c_1 + a_3b_1 + a_3b_2c_1\) -0.130 0.061 0.034

Table ?????,: Effects on \(Y\) for the model fit4

We can conclude that in the model fit4, the indirect effect is significant for the variable Self-esteem.
Especially, the most significant effect is given by the path :
Spirituality \(\rightarrow\) Social comparison \(\rightarrow\) Self-esteem (same as fit3).

Model selection

In this part, the objective will be to compare all the models we built to determine which one is the best for the study.

At first, the aim will be to compare models with the same size, that means with and with . To do that we use the criteria of AIC and BIC. All the values are given in the summaries of the different .

Model AIC BIC SABIC
Model 1 18567.694 18871.863 18618.101
Model 2 18409.843 18714.013 18460.251

Table ?????,: Criteria AIC and BIC for the different models

Model AIC BIC SABIC
Model 3 22454.464 22815.665 22514.322
Model 4 22408.201 22773.205 22468.690

Table ?????,: Criteria AIC and BIC for the different models

In both cases, the best model is the model which minimize the criterion AIC and the criterion BIC. We retain the models mod2 and mod4.

Now stay available two models which are mod2 and mod4. To decide between them, we realize a test of nested models using the function anova on R.

Show the code
anova_test <- anova(fit2, fit4)
anova_test

Chi-Squared Difference Test

      Df   AIC   BIC  Chisq Chisq diff   RMSEA Df diff Pr(>Chisq)    
fit2 270 18410 18714 798.68                                          
fit4 368 22408 22773 958.54     159.86 0.04367      98  8.011e-05 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The Chi-Squared Difference Test give a p-value < 0.05 .
The test indicates that it is preferable to keep the additional variable of the model mod4.

We can conclude that the model mod4 is the best model for the study.

Results

The aim of the study was to understand the connections between spirituality, social comparison, temporal comparison and self-esteem for individuals. Especially, we wanted to analyze the effects of spirituality on self-esteem and determine if they pass through social comparison and/or temporal comparison.

Thanks to criteria and tests we used, we were able to define the best model for this study : fit4.
It gather all the notions and take into account an influence of social comparison on temporal comparison. According to this model which highlights the significance of the indirect effect Indirect1, the main effect on self-esteem of individuals is social comparison due to spirituality.

To put it in a nutshell, we can conclude in favor of connection between the different notions. Especially, the effect of spirituality on self-esteem transits by social comparison.

Computational informations

Session informations
Show the code
devtools::session_info()
─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.4.2 (2024-10-31)
 os       Ubuntu 24.04.1 LTS
 system   x86_64, linux-gnu
 ui       X11
 language (EN)
 collate  fr_FR.UTF-8
 ctype    fr_FR.UTF-8
 tz       Europe/Paris
 date     2025-11-01
 pandoc   3.2 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/x86_64/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────
 package      * version    date (UTC) lib source
 abind          1.4-8      2024-09-12 [1] CRAN (R 4.4.2)
 askpass        1.2.1      2024-10-04 [2] CRAN (R 4.3.3)
 bslib          0.9.0      2025-01-30 [1] CRAN (R 4.4.2)
 cachem         1.1.0      2024-05-16 [2] CRAN (R 4.3.3)
 car            3.1-3      2024-09-27 [1] CRAN (R 4.4.2)
 carData        3.0-5      2022-01-06 [1] CRAN (R 4.4.2)
 cli            3.6.5      2025-04-23 [1] CRAN (R 4.4.2)
 crosstalk      1.2.1      2023-11-23 [1] CRAN (R 4.4.2)
 devtools       2.4.5      2022-10-11 [1] CRAN (R 4.4.2)
 digest         0.6.37     2024-08-19 [1] CRAN (R 4.4.2)
 dplyr        * 1.1.4      2023-11-17 [1] CRAN (R 4.4.2)
 DT             0.33       2024-04-04 [1] CRAN (R 4.4.2)
 ellipsis       0.3.2      2021-04-29 [2] CRAN (R 4.3.3)
 evaluate       1.0.5      2025-08-27 [1] CRAN (R 4.4.2)
 farver         2.1.2      2024-05-13 [1] CRAN (R 4.4.2)
 fastmap        1.2.0      2024-05-15 [2] CRAN (R 4.3.3)
 Formula        1.2-5      2023-02-24 [1] CRAN (R 4.4.2)
 fs             1.6.6      2025-04-12 [1] CRAN (R 4.4.2)
 generics       0.1.3      2022-07-05 [1] CRAN (R 4.4.2)
 ggplot2      * 4.0.0      2025-09-11 [1] CRAN (R 4.4.2)
 glue           1.8.0      2024-09-30 [2] CRAN (R 4.3.3)
 gridExtra      2.3        2017-09-09 [1] CRAN (R 4.4.2)
 gtable         0.3.6      2024-10-25 [1] CRAN (R 4.4.2)
 htmltools      0.5.8.1    2024-04-04 [2] CRAN (R 4.3.3)
 htmlwidgets    1.6.4      2023-12-06 [2] CRAN (R 4.3.3)
 httpuv         1.6.15     2024-03-26 [2] CRAN (R 4.3.3)
 jquerylib      0.1.4      2021-04-26 [2] CRAN (R 4.3.3)
 jsonlite       2.0.0      2025-03-27 [1] CRAN (R 4.4.2)
 knitr          1.50       2025-03-16 [1] CRAN (R 4.4.2)
 labeling       0.4.3      2023-08-29 [1] CRAN (R 4.4.2)
 later          1.4.1      2024-11-27 [2] CRAN (R 4.3.3)
 lavaan       * 0.6-20     2025-09-21 [1] CRAN (R 4.4.2)
 lifecycle      1.0.4      2023-11-07 [2] CRAN (R 4.3.3)
 magick         2.9.0      2025-09-08 [1] CRAN (R 4.4.2)
 magrittr       2.0.4      2025-09-12 [1] CRAN (R 4.4.2)
 MASS           7.3-60.0.1 2024-01-13 [4] CRAN (R 4.3.2)
 memoise        2.0.1      2021-11-26 [2] CRAN (R 4.3.3)
 mime           0.13       2025-03-17 [1] CRAN (R 4.4.2)
 miniUI         0.1.1.1    2018-05-18 [2] CRAN (R 4.3.3)
 mnormt         2.1.1      2022-09-26 [1] CRAN (R 4.4.2)
 pbivnorm       0.6.0      2015-01-23 [1] CRAN (R 4.4.2)
 pdftools       3.6.0      2025-09-10 [1] CRAN (R 4.4.2)
 pillar         1.10.1     2025-01-07 [2] CRAN (R 4.3.3)
 pkgbuild       1.4.6      2025-01-16 [2] CRAN (R 4.3.3)
 pkgconfig      2.0.3      2019-09-22 [2] CRAN (R 4.3.3)
 pkgload        1.4.0      2024-06-28 [2] CRAN (R 4.3.3)
 profvis        0.4.0      2024-09-20 [2] CRAN (R 4.3.3)
 promises       1.3.2      2024-11-28 [2] CRAN (R 4.3.3)
 purrr          1.0.4      2025-02-05 [1] CRAN (R 4.4.2)
 qpdf           1.4.1      2025-07-02 [1] CRAN (R 4.4.2)
 quadprog       1.5-8      2019-11-20 [1] CRAN (R 4.4.2)
 R6             2.6.1      2025-02-15 [1] CRAN (R 4.4.2)
 RColorBrewer   1.1-3      2022-04-03 [1] CRAN (R 4.4.2)
 Rcpp           1.1.0      2025-07-02 [1] CRAN (R 4.4.2)
 remotes        2.5.0      2024-03-17 [2] CRAN (R 4.3.3)
 rlang          1.1.6      2025-04-11 [1] CRAN (R 4.4.2)
 rmarkdown      2.30       2025-09-28 [1] CRAN (R 4.4.2)
 rstudioapi     0.17.1     2024-10-22 [2] CRAN (R 4.3.3)
 S7             0.2.0      2024-11-07 [1] CRAN (R 4.4.2)
 sass           0.4.10     2025-04-11 [1] CRAN (R 4.4.2)
 scales         1.4.0      2025-04-24 [1] CRAN (R 4.4.2)
 semPower       2.1.3      2025-08-22 [1] CRAN (R 4.4.2)
 sessioninfo    1.2.2      2021-12-06 [2] CRAN (R 4.3.3)
 shiny          1.10.0     2024-12-14 [2] CRAN (R 4.3.3)
 tibble         3.2.1      2023-03-20 [2] CRAN (R 4.3.3)
 tidyr        * 1.3.1      2024-01-24 [1] CRAN (R 4.4.2)
 tidyselect     1.2.1      2024-03-11 [1] CRAN (R 4.4.2)
 tinytex        0.57       2025-04-15 [1] CRAN (R 4.4.2)
 urlchecker     1.0.1      2021-11-30 [1] CRAN (R 4.4.2)
 usethis        3.1.0      2024-11-26 [2] CRAN (R 4.3.3)
 vctrs          0.6.5      2023-12-01 [2] CRAN (R 4.3.3)
 viridis      * 0.6.5      2024-01-29 [1] CRAN (R 4.4.2)
 viridisLite  * 0.4.2      2023-05-02 [1] CRAN (R 4.4.2)
 withr          3.0.2      2024-10-28 [2] CRAN (R 4.3.3)
 xfun           0.53       2025-08-19 [1] CRAN (R 4.4.2)
 xtable         1.8-4      2019-04-21 [2] CRAN (R 4.3.3)
 yaml           2.3.10     2024-07-26 [1] CRAN (R 4.4.2)

 [1] /home/clement/R/x86_64-pc-linux-gnu-library/4.4
 [2] /usr/local/lib/R/site-library
 [3] /usr/lib/R/site-library
 [4] /usr/lib/R/library

──────────────────────────────────────────────────────────────────────────────