# import data
library(readr)
d <- read_csv("/Users/melissalagunas/Desktop/Lab/Contextualizing\ Stigma\ and\ Trauma/LatineData_Subscales.csv")
## New names:
## Rows: 259 Columns: 16
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," dbl
## (16): ...1, SSRPH, SSOSH, MHSAS, PR_PF, PR_A, PR_D, PR_SR, PR_PI, ANG, C...
## ℹ 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`
View(d)
# import data
library(readr)
dat <- read_csv("/Users/melissalagunas/Desktop/Lab/Contextualizing\ Stigma\ and\ Trauma/LatineData2.csv")
## New names:
## Rows: 259 Columns: 151
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (4): AHELP, GEN_8_TEXT, ETH_7_TEXT, BORN_1 dbl (146): ...1, Progress,
## Duration..in.seconds., Consent, SSRPH_1, SSRPH_2,... lgl (1): EDU_11_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`
View(dat)
# Extract variables of interest
dat <- dat[, 88:100]
# Recode
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ purrr 1.0.2
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ── 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
# Recode the scale with dichotomous items
dat$scale <- rowSums(dat[, c("SLESQ_1", "SLESQ_2", "SLESQ_3", "SLESQ_4", "SLESQ_5", "SLESQ_6", "SLESQ_7", "SLESQ_8", "SLESQ_9", "SLESQ_10", "SLESQ_11","SLESQ_12", "SLESQ_13")])
#data set with only familismo (PHFS), stressful life events (SLESQ), and central sensitization (CSA)
library(dplyr)
d <- data.frame(d$PHFS, dat$scale, d$CSA)
d <- rename(d, familism = d.PHFS, trauma = dat.scale, central_sensitization = d.CSA)
# remove NA variables
d <- na.omit(d)
Preliminary Analyses
# Load necessary libraries
library(psych)
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(ggplot2)
library(corrplot)
## corrplot 0.92 loaded
library(reshape2)
##
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
##
## smiths
library(FactoMineR)
library(apaTables)
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:psych':
##
## logit
## The following object is masked from 'package:dplyr':
##
## recode
## The following object is masked from 'package:purrr':
##
## some
options(scipen = 999)
## Descriptive Statistics
summary(d)
## familism trauma central_sensitization
## Min. :1.000 Min. :13.00 Min. :0.000
## 1st Qu.:3.200 1st Qu.:14.00 1st Qu.:1.160
## Median :3.800 Median :16.00 Median :1.640
## Mean :3.673 Mean :16.72 Mean :1.629
## 3rd Qu.:4.400 3rd Qu.:19.00 3rd Qu.:2.160
## Max. :5.000 Max. :26.00 Max. :3.800
# Calculate means
means <- apply(d, 2, mean)
# Calculate standard deviations
sds <- apply(d, 2, sd)
# Combine means and standard deviations into a data frame
descriptive_stats <- data.frame(variable = names(means), mean = means, sd = sds)
print(descriptive_stats)
## variable mean sd
## familism familism 3.672510 0.9633282
## trauma trauma 16.717131 2.8488007
## central_sensitization central_sensitization 1.629442 0.7221477
# Correlation Analysis
table <- apaTables::apa.cor.table(d, table.number = 1, show.sig.stars = TRUE,
landscape = TRUE, filename = "table.doc")
print(table)
##
##
## Table 1
##
## Means, standard deviations, and correlations with confidence intervals
##
##
## Variable M SD 1 2
## 1. familism 3.67 0.96
##
## 2. trauma 16.72 2.85 -.21**
## [-.32, -.09]
##
## 3. central_sensitization 1.63 0.72 -.34** .33**
## [-.45, -.23] [.21, .43]
##
##
## 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.
##
psych::pairs.panels(d)

# Normality Checks
hist(d$trauma)

qqnorm(d$trauma)
qqline(d$trauma)

# Repeat for moderator and dependent_variable
# 4. Visual Inspection
# Scatterplot for independent variable vs. dependent variable
ggplot(d, aes(x = trauma, y = central_sensitization)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(title = "Scatterplot of Independent vs. Dependent Variable")
## `geom_smooth()` using formula = 'y ~ x'

# Scatterplot for moderator vs. dependent variable
ggplot(d, aes(x = familism, y = central_sensitization)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
labs(title = "Scatterplot of Moderator vs. Dependent Variable")
## `geom_smooth()` using formula = 'y ~ x'

# Multicolinearity
## Variance Inflation Factor
library(car)
vif_model <- lm(central_sensitization ~ trauma + familism, data = d)
vif_results <- vif(vif_model)
print(vif_results)
## trauma familism
## 1.045318 1.045318
Primary Analyses
# Run the moderation analysis
moderation_model <- lm(central_sensitization ~ trauma * familism, data = d)
summary(moderation_model)
##
## Call:
## lm(formula = central_sensitization ~ trauma * familism, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.49169 -0.48942 -0.03866 0.41748 2.02833
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.120089 1.102073 1.016 0.310
## trauma 0.077110 0.062446 1.235 0.218
## familism -0.168898 0.284024 -0.595 0.553
## trauma:familism -0.002621 0.016304 -0.161 0.872
##
## Residual standard error: 0.6564 on 247 degrees of freedom
## Multiple R-squared: 0.1838, Adjusted R-squared: 0.1739
## F-statistic: 18.54 on 3 and 247 DF, p-value: 0.00000000007032
# table
moderation_model_summ <- jtools::summ(moderation_model, digits = 3)
moderation_model_summ
## MODEL INFO:
## Observations: 251
## Dependent Variable: central_sensitization
## Type: OLS linear regression
##
## MODEL FIT:
## F(3,247) = 18.539, p = 0.000
## R² = 0.184
## Adj. R² = 0.174
##
## Standard errors: OLS
## -------------------------------------------------------
## Est. S.E. t val. p
## --------------------- -------- ------- -------- -------
## (Intercept) 1.120 1.102 1.016 0.310
## trauma 0.077 0.062 1.235 0.218
## familism -0.169 0.284 -0.595 0.553
## trauma:familism -0.003 0.016 -0.161 0.872
## -------------------------------------------------------
# visualization
interactions::interact_plot(moderation_model, pred = trauma, modx = familism) +
ylim(1, 6)

# Homoscedasticity
# Assuming 'moderation_model' is your moderation analysis model
plot(moderation_model)




# Load necessary libraries
library(sandwich)
# Johnson-Neyman (Floodlight Approach): Think of this like turning on a floodlight in a dark room. The Johnson-Neyman method helps us see across the entire room (or the entire range of W) to find out where X has a significant impact on Y, meaning it makes a real difference.
# Simple Slopes (Spotlight Approach): Now, imagine you have a spotlight that you can shine on specific spots in the room. The analysis of simple slopes is like shining that spotlight at particular values of W, often at the average value (M) or one standard deviation above and below the average. This helps us focus on specific points to understand how X affects Y in those particular situations.
# In simpler terms, Johnson-Neyman is like looking at the big picture, telling us where X matters across the entire range of W. On the other hand, simple slopes are like zooming in on specific points to see how X and Y connect in those specific situations, giving us a more detailed view.
interactions::sim_slopes(moderation_model, pred = trauma, modx = familism)
## JOHNSON-NEYMAN INTERVAL
##
## When familism is INSIDE the interval [1.64, 5.45], the slope of trauma is p
## < .05.
##
## Note: The range of observed values of familism is [1.00, 5.00]
##
## SIMPLE SLOPES ANALYSIS
##
## Slope of trauma when familism = 2.709182 (- 1 SD):
##
## Est. S.E. t val. p
## ------ ------ -------- ------
## 0.07 0.02 3.15 0.00
##
## Slope of trauma when familism = 3.672510 (Mean):
##
## Est. S.E. t val. p
## ------ ------ -------- ------
## 0.07 0.01 4.52 0.00
##
## Slope of trauma when familism = 4.635838 (+ 1 SD):
##
## Est. S.E. t val. p
## ------ ------ -------- ------
## 0.06 0.02 3.08 0.00