Packages
library(lavaan)
## This is lavaan 0.6-16
## lavaan is FREE software! Please report any bugs.
library(semPlot)
## Warning: package 'semPlot' was built under R version 4.3.2
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(psych)
##
## Attaching package: 'psych'
##
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
##
## The following object is masked from 'package:lavaan':
##
## cor2cov
library(jtools)
## Warning: package 'jtools' was built under R version 4.3.2
library(interactions)
## Warning: package 'interactions' was built under R version 4.3.2
library(ggplot2)
library(tidySEM)
## Warning: package 'tidySEM' was built under R version 4.3.2
## Loading required package: OpenMx
##
## Attaching package: 'OpenMx'
##
## The following object is masked from 'package:psych':
##
## tr
##
## Registered S3 method overwritten by 'tidySEM':
## method from
## predict.MxModel OpenMx
##
## Attaching package: 'tidySEM'
##
## The following object is masked from 'package:jtools':
##
## get_data
library(dplyr)
library(report)
## Warning: package 'report' was built under R version 4.3.2
##
## Attaching package: 'report'
##
## The following object is masked from 'package:tidySEM':
##
## report
library(magrittr)
##
## Attaching package: 'magrittr'
##
## The following object is masked from 'package:purrr':
##
## set_names
##
## The following object is masked from 'package:tidyr':
##
## extract
library(readr)
AAFD <- read_csv("AsianData_FINAL_Dataset.csv")
## New names:
## Rows: 160 Columns: 34
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (3): ETH_22_TEXT, BORN_1, AHELP dbl (28): ...1, AGE, GEN, EDU, EMP, INS_1,
## INS_2, ETH, INC, BORN, BORN_2, PR... lgl (3): GEN_8_TEXT, EDU_11_TEXT,
## ETH_26_TEXT
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
head(AAFD)
## # A tibble: 6 × 34
## ...1 AGE GEN GEN_8_TEXT EDU EDU_11_TEXT EMP INS_1 INS_2 ETH
## <dbl> <dbl> <dbl> <lgl> <dbl> <lgl> <dbl> <dbl> <dbl> <dbl>
## 1 1 39 2 NA 5 NA 1 1 1 3
## 2 2 30 2 NA 6 NA 1 1 1 7
## 3 3 37 2 NA 4 NA 2 1 3 16
## 4 4 34 2 NA 6 NA 1 1 1 NA
## 5 5 28 2 NA 5 NA 2 1 3 1
## 6 6 64 2 NA 3 NA 1 1 1 2
## # ℹ 24 more variables: ETH_22_TEXT <chr>, ETH_26_TEXT <lgl>, INC <dbl>,
## # BORN <dbl>, BORN_1 <chr>, BORN_2 <dbl>, AHELP <chr>, PRE_HELP <dbl>,
## # SSRPH <dbl>, SSOSH <dbl>, MHSAS <dbl>, PR_PF <dbl>, PR_A <dbl>, PR_D <dbl>,
## # PR_SR <dbl>, PR_PI <dbl>, PR_INT <dbl>, ANG <dbl>, CSA <dbl>, IEQ <dbl>,
## # SLESQ <dbl>, OD <dbl>, PCL5 <dbl>, ESC <dbl>
#check Structure code
#str(AAFD)
#data set with only variables of interest
d <- data.frame(AAFD$SLESQ, AAFD$CSA, AAFD$ESC, AAFD$PCL5)
d <- rename(d, stressful_life_events = AAFD.SLESQ, central_sensitization = AAFD.CSA, emotional_self_control = AAFD.ESC, trauma_symptoms = AAFD.PCL5)
d <- na.omit(d)
psych::describe(d)
## vars n mean sd median trimmed mad min max range
## stressful_life_events 1 160 1.22 0.19 1.15 1.19 0.12 1.00 1.85 0.85
## central_sensitization 2 160 1.56 0.72 1.54 1.55 0.74 0.04 3.44 3.40
## emotional_self_control 3 160 3.52 1.08 3.50 3.49 1.11 1.12 7.00 5.88
## trauma_symptoms 4 160 1.50 1.07 1.50 1.44 1.11 0.00 4.00 4.00
## skew kurtosis se
## stressful_life_events 0.97 0.47 0.01
## central_sensitization 0.07 -0.53 0.06
## emotional_self_control 0.25 -0.05 0.09
## trauma_symptoms 0.39 -0.80 0.08
apaTables::apa.cor.table(d)
## Registered S3 methods overwritten by 'broom':
## method from
## tidy.glht jtools
## tidy.summary.glht jtools
##
##
## Means, standard deviations, and correlations with confidence intervals
##
##
## Variable M SD 1 2 3
## 1. stressful_life_events 1.22 0.19
##
## 2. central_sensitization 1.56 0.72 .39**
## [.25, .52]
##
## 3. emotional_self_control 3.52 1.08 -.05 -.02
## [-.20, .11] [-.18, .13]
##
## 4. trauma_symptoms 1.50 1.07 .35** .65** .10
## [.20, .48] [.55, .73] [-.06, .25]
##
##
## Note. M and SD are used to represent mean and standard deviation, respectively.
## Values in square brackets indicate the 95% confidence interval.
## The confidence interval is a plausible range of population correlations
## that could have caused the sample correlation (Cumming, 2014).
## * indicates p < .05. ** indicates p < .01.
##
# Pearson's Correlation Coefficent:
results.r <- d %$%
cor.test(x = stressful_life_events, y = trauma_symptoms)
report(results.r)
## Effect sizes were labelled following Funder's (2019) recommendations.
##
## The Pearson's product-moment correlation between stressful_life_events and
## trauma_symptoms is positive, statistically significant, and large (r = 0.35,
## 95% CI [0.20, 0.48], t(158) = 4.65, p < .001)
#Pairs Panels
psych::pairs.panels(d)
model1 <- lm(stressful_life_events ~ central_sensitization * emotional_self_control, d)
summary(model1)
##
## Call:
## lm(formula = stressful_life_events ~ central_sensitization *
## emotional_self_control, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.29732 -0.12314 -0.04028 0.10320 0.57090
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) 1.118128 0.113215 9.876
## central_sensitization 0.079054 0.065780 1.202
## emotional_self_control -0.016786 0.030535 -0.550
## central_sensitization:emotional_self_control 0.006377 0.017821 0.358
## Pr(>|t|)
## (Intercept) <2e-16 ***
## central_sensitization 0.231
## emotional_self_control 0.583
## central_sensitization:emotional_self_control 0.721
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1738 on 156 degrees of freedom
## Multiple R-squared: 0.1566, Adjusted R-squared: 0.1404
## F-statistic: 9.655 on 3 and 156 DF, p-value: 6.966e-06
#graph interaction
interactions::interact_plot(model1, pred = central_sensitization, modx = emotional_self_control, main.title = "Figure 2") +
ylim(1, 10)
>> This is the same moderation as above but switched so that graph
has stressful_life_events as x axis
model1a <- lm(stressful_life_events ~ central_sensitization * emotional_self_control, d)
summary(model1a)
##
## Call:
## lm(formula = stressful_life_events ~ central_sensitization *
## emotional_self_control, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.29732 -0.12314 -0.04028 0.10320 0.57090
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) 1.118128 0.113215 9.876
## central_sensitization 0.079054 0.065780 1.202
## emotional_self_control -0.016786 0.030535 -0.550
## central_sensitization:emotional_self_control 0.006377 0.017821 0.358
## Pr(>|t|)
## (Intercept) <2e-16 ***
## central_sensitization 0.231
## emotional_self_control 0.583
## central_sensitization:emotional_self_control 0.721
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1738 on 156 degrees of freedom
## Multiple R-squared: 0.1566, Adjusted R-squared: 0.1404
## F-statistic: 9.655 on 3 and 156 DF, p-value: 6.966e-06
interactions::interact_plot(model1a, pred = stressful_life_events, modx = emotional_self_control, main.title = "Figure 2") +
ylim(1, 10)
## Warning: stressful_life_events and emotional_self_control are not included in an
## interaction with one another in the model.
## `geom_path()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
model2 <- lm(stressful_life_events ~ trauma_symptoms * emotional_self_control, d)
summary(model2)
##
## Call:
## lm(formula = stressful_life_events ~ trauma_symptoms * emotional_self_control,
## data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.35589 -0.12119 -0.04134 0.09645 0.61521
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.226630 0.082650 14.841 <2e-16
## trauma_symptoms 0.027079 0.046323 0.585 0.560
## emotional_self_control -0.029332 0.022817 -1.286 0.201
## trauma_symptoms:emotional_self_control 0.009863 0.012395 0.796 0.427
##
## (Intercept) ***
## trauma_symptoms
## emotional_self_control
## trauma_symptoms:emotional_self_control
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1764 on 156 degrees of freedom
## Multiple R-squared: 0.1309, Adjusted R-squared: 0.1142
## F-statistic: 7.832 on 3 and 156 DF, p-value: 6.667e-05
interactions::interact_plot(model2, pred = trauma_symptoms, modx = emotional_self_control, main.title = "Figure 3") +
ylim(1, 10)
>> This is the same moderation as above but switched so that graph
has stressful_life_events as x axis
model2a <- lm(stressful_life_events ~ trauma_symptoms * emotional_self_control, d)
summary(model2a)
##
## Call:
## lm(formula = stressful_life_events ~ trauma_symptoms * emotional_self_control,
## data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.35589 -0.12119 -0.04134 0.09645 0.61521
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.226630 0.082650 14.841 <2e-16
## trauma_symptoms 0.027079 0.046323 0.585 0.560
## emotional_self_control -0.029332 0.022817 -1.286 0.201
## trauma_symptoms:emotional_self_control 0.009863 0.012395 0.796 0.427
##
## (Intercept) ***
## trauma_symptoms
## emotional_self_control
## trauma_symptoms:emotional_self_control
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1764 on 156 degrees of freedom
## Multiple R-squared: 0.1309, Adjusted R-squared: 0.1142
## F-statistic: 7.832 on 3 and 156 DF, p-value: 6.667e-05
interactions::interact_plot(model2a, pred = stressful_life_events, modx = emotional_self_control, main.title = "Figure 2") +
ylim(1, 10)
## Warning: stressful_life_events and emotional_self_control are not included in an
## interaction with one another in the model.
## `geom_path()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
# Y = central_sensitization; X = stressful_life_events; M = trauma_symptoms
LMedModel <- "
central_sensitization ~ b*trauma_symptoms + c_p*stressful_life_events
trauma_symptoms ~a*stressful_life_events
#intercepts
stressful_life_events ~ stressful_life_events.mean*1
central_sensitization ~ central_sensitization.mean*1
indirect := a*b
direct := c_p
total_c := c_p + (a*b)
"
set.seed(230925) #required for reproducible results because lavaan introduces randomness into the calculations
LMed_fit <- lavaan::sem(LMedModel, data = d, se = "bootstrap", missing = "fiml")
LMed_Sum <- lavaan::summary(LMed_fit, standardized = T, rsq = T, ci = TRUE)
LMed_ParEsts <- lavaan::parameterEstimates(LMed_fit, boot.ci.type = "bca.simple",
standardized = TRUE)
LMed_Sum
## lavaan 0.6.16 ended normally after 9 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 9
##
## Number of observations 160
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 0.000
## Degrees of freedom 0
##
## Parameter Estimates:
##
## Standard errors Bootstrap
## Number of requested bootstrap draws 1000
## Number of successful bootstrap draws 1000
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) ci.lower ci.upper
## central_sensitization ~
## trm_symp (b) 0.395 0.049 8.040 0.000 0.302 0.493
## strssf__ (c_p) 0.736 0.242 3.038 0.002 0.266 1.220
## trauma_symptoms ~
## strssf__ (a) 1.976 0.408 4.848 0.000 1.183 2.781
## Std.lv Std.all
##
## 0.395 0.582
## 0.736 0.191
##
## 1.976 0.347
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) ci.lower ci.upper
## strss__ (s__.) 1.217 0.015 82.286 0.000 1.189 1.246
## .cntrl_s (cn_.) 0.072 0.271 0.265 0.791 -0.467 0.600
## .trm_sym -0.903 0.499 -1.809 0.070 -1.830 0.096
## Std.lv Std.all
## 1.217 6.515
## 0.072 0.100
## -0.903 -0.849
##
## Variances:
## Estimate Std.Err z-value P(>|z|) ci.lower ci.upper
## .centrl_snstztn 0.285 0.029 9.701 0.000 0.221 0.336
## .trauma_symptms 0.995 0.101 9.809 0.000 0.792 1.187
## strssfl_lf_vnt 0.035 0.004 8.165 0.000 0.027 0.043
## Std.lv Std.all
## 0.285 0.548
## 0.995 0.879
## 0.035 1.000
##
## R-Square:
## Estimate
## centrl_snstztn 0.452
## trauma_symptms 0.121
##
## Defined Parameters:
## Estimate Std.Err z-value P(>|z|) ci.lower ci.upper
## indirect 0.780 0.207 3.776 0.000 0.433 1.241
## direct 0.736 0.242 3.036 0.002 0.266 1.220
## total_c 1.516 0.249 6.079 0.000 1.046 2.041
## Std.lv Std.all
## 0.780 0.202
## 0.736 0.191
## 1.516 0.393
Mel’s variables: (public stigma =IV, self stigma = Mediator, help-seeking attitudes = DV, familism = Moderator)
Combined <- '
#equations
trauma_symptoms ~ a1*stressful_life_events + a2*emotional_self_control + a3*stressful_life_events:emotional_self_control
central_sensitization ~ c_p1*stressful_life_events + c_p2*emotional_self_control + c_p3*stressful_life_events:emotional_self_control + b*trauma_symptoms
#intercepts
trauma_symptoms ~ trauma_symptoms.mean*1
central_sensitization ~ central_sensitization.mean*1
#means, variances of W for simple slopes
emotional_self_control ~ emotional_self_control.mean*1
emotional_self_control ~~ emotional_self_control.var*emotional_self_control
#index of moderated mediation, there will be an a and b path in the product
#if the a and/or b path is moderated, select the label that represents the moderation
imm := a3*b
#Note that we first create the indirect product, then add to it the product of the imm and the W level
indirect.SDbelow := a1*b + imm*(emotional_self_control.mean - sqrt(emotional_self_control.var))
indirect.mean := a1*b + imm*(emotional_self_control.mean)
indirect.SDabove := a1*b + imm*(emotional_self_control.mean + sqrt(emotional_self_control.var))
#direct effect is also moderated so calculate with c_p1 + c_p3
direct.SDbelow := c_p1 + c_p3*(emotional_self_control.mean - sqrt(emotional_self_control.var))
direct.Smean := c_p1 + c_p3*(emotional_self_control.mean)
direct.SDabove := c_p1 + c_p3*(emotional_self_control.mean + sqrt(emotional_self_control.var))
'
set.seed(230925) #required for reproducible results because lavaan introduces randomness into the calculations
Combined_fit <- lavaan::sem(Combined, data = d, se = "bootstrap", missing = 'fiml', fixed.x = FALSE, bootstrap = 1000)
cFITsum <- lavaan::summary(Combined_fit, standardized = TRUE, rsq=T, ci=TRUE)
cParamEsts <- lavaan::parameterEstimates(Combined_fit, boot.ci.type = "bca.simple", standardized=TRUE)
cFITsum
## lavaan 0.6.16 ended normally after 21 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of model parameters 18
##
## Number of observations 160
## Number of missing patterns 1
##
## Model Test User Model:
##
## Test statistic 596.947
## Degrees of freedom 2
## P-value (Chi-square) 0.000
##
## Parameter Estimates:
##
## Standard errors Bootstrap
## Number of requested bootstrap draws 1000
## Number of successful bootstrap draws 1000
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) ci.lower ci.upper
## trauma_symptoms ~
## strss__ (a1) 1.183 1.398 0.846 0.398 -2.237 3.423
## emtnl__ (a2) -0.170 0.471 -0.362 0.718 -1.321 0.580
## st__:__ (a3) 0.230 0.376 0.611 0.541 -0.358 1.162
## central_sensitization ~
## strss__ (c_p1) 0.946 0.739 1.280 0.200 -0.373 2.523
## emtnl__ (c_p2) 0.034 0.241 0.139 0.889 -0.399 0.548
## st__:__ (c_p3) -0.066 0.192 -0.343 0.731 -0.515 0.268
## trm_sym (b) 0.402 0.051 7.945 0.000 0.305 0.503
## Std.lv Std.all
##
## 1.183 0.199
## -0.170 -0.165
## 0.230 0.305
##
## 0.946 0.245
## 0.034 0.050
## -0.066 -0.135
## 0.402 0.619
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) ci.lower
## stressful_life_events ~~
## strssfl_lf_:__ 0.113 0.030 3.758 0.000 0.060
## ci.upper Std.lv Std.all
##
## 0.181 0.113 0.411
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) ci.lower ci.upper
## .trm_sym (tr_.) -0.320 1.740 -0.184 0.854 -3.190 3.866
## .cntrl_s (cn_.) -0.030 0.930 -0.032 0.974 -1.959 1.702
## emtnl__ (e__.) 3.520 0.087 40.458 0.000 3.348 3.691
## strss__ 1.217 0.015 82.286 0.000 1.189 1.246
## st__:__ 4.275 0.117 36.636 0.000 4.052 4.510
## Std.lv Std.all
## -0.320 -0.288
## -0.030 -0.042
## 3.520 3.269
## 1.217 6.515
## 4.275 2.899
##
## Variances:
## Estimate Std.Err z-value P(>|z|) ci.lower ci.upper
## emtnl__ (e__.) 1.159 0.128 9.029 0.000 0.924 1.417
## .trm_sym 0.978 0.099 9.885 0.000 0.773 1.153
## .cntrl_s 0.282 0.030 9.551 0.000 0.216 0.332
## strss__ 0.035 0.004 8.165 0.000 0.027 0.043
## st__:__ 2.175 0.397 5.472 0.000 1.552 3.085
## Std.lv Std.all
## 1.159 1.000
## 0.978 0.791
## 0.282 0.541
## 0.035 1.000
## 2.175 1.000
##
## R-Square:
## Estimate
## trauma_symptms 0.209
## centrl_snstztn 0.459
##
## Defined Parameters:
## Estimate Std.Err z-value P(>|z|) ci.lower ci.upper
## imm 0.092 0.154 0.598 0.550 -0.141 0.499
## indirect.SDblw 0.701 0.264 2.654 0.008 0.201 1.228
## indirect.mean 0.800 0.213 3.762 0.000 0.447 1.279
## indirect.SDabv 0.899 0.270 3.329 0.001 0.487 1.531
## direct.SDbelow 0.785 0.336 2.338 0.019 0.160 1.469
## direct.Smean 0.713 0.252 2.833 0.005 0.215 1.212
## direct.SDabove 0.642 0.311 2.069 0.039 -0.068 1.196
## Std.lv Std.all
## 0.092 0.189
## 0.701 0.551
## 0.800 0.739
## 0.899 0.928
## 0.785 -0.061
## 0.713 -0.196
## 0.642 -0.331