attach(Coping_and_cognition_data) #To calculate means and standard deviations of variables, shown here for age: mean(age) sd(age) To calculate variable normality, shown here for age: shapiro.test(age) hist(age) #To calculate the Cronbach’s alpha of a scale, each of the items of that scale were entered into a separate data frame, which was then analysed using the “alpha” function. Shown here for facet positive emotion: library(psych) alpha(NEO_pos) # #Attention biases were calculated, and outliers removed, using a separate dataset, extracted from Gorilla Experiment Builder. Biases calculated separately for each individual, show here for participant number 3869149: attach(Attention) #removing outliers Ind <- subset(Attention, Participant_Private_ID == 3869149) Q1 <- quantile(Reaction_Time, 0.25) Q3 <- quantile(Reaction_Time, 0.75) low_bench <- Q1 - 1.5*IQR(Reaction_Time) high_bench <- Q3 + 1.5*IQR(Reaction_Time) Ind <- subset(Ind, Reaction_Time < high_bench & Reaction_Time > low_bench) #creating subsets for conditions Sad <- subset(Ind, Target == "Sad") Happy <- subset(Ind, Target == "Happy") Afraid <- subset(Ind, Target == "Afraid") Neutral_sad <- subset(Ind, randomise_blocks == "Female, sad vs neutral" | randomise_blocks == "Male, sad vs neutral") Neutral_sad <- subset(Neutral_sad, Target == "Neutral") Neutral_happy <- subset(Ind, randomise_blocks == "Female, happy vs neutral" | randomise_blocks == "Male, happy vs neutral") Neutral_happy <- subset(Neutral_happy, Target == "Neutral") Neutral_afraid <- subset(Ind, randomise_blocks == "Female, afraid vs neutral" | randomise_blocks == "Male, afraid vs neutral") Neutral_afraid <- subset(Neutral_afraid, Target == "Neutral") #calculating means of RTs over trials sad_RT <- mean(Sad$Reaction_Time) happy_RT <- mean(Happy$Reaction_Time) afraid_RT <- mean(Afraid$Reaction_Time) Neutral_sad_RT <- mean(Neutral_sad$Reaction_Time) Neutral_happy_RT <- mean(Neutral_happy$Reaction_Time) Neutral_afraid_RT <- mean(Neutral_afraid$Reaction_Time) #bias scores: #sad bias: Neutral_sad_RT - sad_RT #happy bias Neutral_happy_RT - happy_RT #afraid bias Neutral_afraid_RT - afraid_RT # #Factor analysis, shown here for COPE scales attach(Data_276) #scaling data scale.data <- as.data.frame(scale(Data_276), centre = TRUE, scale = TRUE) #To create a subset, only including emotion regulation variables ER <- scale.data[c(6:11, 13:16, 18:20)] #Principal components analysis ER.pca <- princomp(ER, cor = TRUE, score = TRUE) summary(ER.pca) loadings(ER.pca) #To view the scree plot plot(ER.pca) #in princomp, the eigenvalues are denoted as "standard deviation" #Factor analysis, using 3 factors (based on the results of the principal components analysis above) ER.fa <- factanal(ER, factors = 3, rotation = "varimax", scores = "regression") ER.fa head(ER.fa$scores) #Factor scores are computer for each individual, and are written to a csv file write.csv(ER.fa$scores, "ER_fa_scores.csv") # #To calculate the correlation matrix: corr.test(Coping_and_cognition_data, method = "pearson") cormatrix <- corr.test(Coping_and_cognition_data, method = "pearson") print(cormatrix, short=FALSE) write.csv(cormatrix$r, "r_matrix.csv") write.csv(cormatrix$p, "p_matrix.csv") # #Multipe regression, shown here for BFAS traits explaining variance in BDI-2: reg <- lm(BDI ~ BFAS_N + BFAS_E + BFAS_C + BFAS_A + BFAS_O) summary(reg) # #Structural equation modelling, shown here for BFAS traits, AST_D, COPE, and interpretation of emotional images factors explaining variance in BDI-2: scale.data <- as.data.frame(scale(Data_276_fa)) attach(scale.data) #SEM: scale.data <- as.data.frame(scale(Data_276)) attach(scale.data) library(lavaan) path <- 'AST_D ~ BFAS_N + BFAS_E + BFAS_C + BFAS_O Negative ~ BFAS_N + BFAS_A Neutral_and_positive ~ BFAS_N + BFAS_E + BFAS_C + BFAS_A + BFAS_O Adaptive_ER ~ BFAS_N + BFAS_E + BFAS_C + BFAS_O + AST_D + Neutral_and_positive Maladaptive_ER ~ BFAS_N + BFAS_E + BFAS_C + BFAS_A + BFAS_O + AST_D + Negative_social + Neutral_and_positive BDI ~ BFAS_N + BFAS_E + BFAS_C + BFAS_A + BFAS_O + Adaptive_ER + Maladaptive_ER + AST_D + Negative + Neutral_and_positive' fit <- sem(path, data = scale.data) summary(fit, fit.measures = T) fitMeasures(fit, c("cfi", "rmsea", "srmr")) modindices(fit, minimum.value = 3.84) #Statically and theoretically plausible regressions paths are added, based on the modification indices, and the model is tested again, to improve statistical fit