setwd("~/My Drive (okara004@ucr.edu)/classes/fall 2022 quarter/PSYC 211 -- stats/problem sets/problem set #4")
i’ll be using a data file given to me by my advisor (same one i used for problem sets #1, 2, & 3).
patience_data <- read.csv("patience22ucr_copy.csv")
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.2 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(report)
library(psych)
##
## Attaching package: 'psych'
##
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(ggpubr)
i am interested in data from the satisfaction with life scale (SWLS) and the emotion regulation questionnaire (ERQ). i will also be selecting the participant demographic information.
SWLSandERQ <- subset(patience_data, select = c("sn", "swls1", "swls2", "swls3", "swls4", "swls5",
"erq1", "erq2", "erq3", "erq4", "erq5", "erq6",
"erq7", "erq8", "erq9", "erq10", "sex", "age",
"eth", "eth_7_TEXT"))
i will be averaging all the SWLS items to get an average SWLS score and all of the ERQ reappraisal & suppression items to get average reappraisal and suppression scores.
## start by averaging all of the SWLS items.
SWLSandERQ$SWLS_avg <- rowMeans(SWLSandERQ[ , c("swls1", "swls2", "swls3", "swls4", "swls5")],
na.rm = TRUE)
## now average all of the ERQ reappraisal items.
SWLSandERQ$reappraisal_avg <- rowMeans(SWLSandERQ[ , c("erq1", "erq3", "erq5", "erq7", "erq8",
"erq10")], na.rm = TRUE)
## lastly average the ERQ suppression items.
SWLSandERQ$suppression_avg <- rowMeans(SWLSandERQ[ , c("erq2", "erq4", "erq6", "erq9")],
na.rm = TRUE)
anyone who has missing data for all items in any scale will be removed.
## these 3 participants did not have any data for the SWLS so i am removing them.
SWLSandERQ_2 <- SWLSandERQ[ -c(161, 208, 216), ]
## first look at the information on participant sex.
table(SWLSandERQ_2$sex) # 1 is male, 2 is female, 3 is non-binary, 4 is other
##
## 1 2 3 4
## 91 115 3 4
115/213 # 53.99% women
## [1] 0.5399061
## then look at the descriptive stats on participant age.
library(psych)
describe(SWLSandERQ_2$age)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 212 20.55 2.32 20 20.24 1.48 18 34 16 2.79 12.07 0.16
## lastly look at the information on participant race/ethnicity.
table(SWLSandERQ_2$eth) # 1 is white, 2 is black/african diaspora, 3 is native american/other native person, 4 is asian, 5 is native hawaiian/pacific islander, 6 is latino/a/x, 7 and 8 are other
##
## 1 2 3 4 6 7 8
## 20 6 1 89 75 10 12
20/213 # 9.39% white
## [1] 0.09389671
6/213 # 2.82% black
## [1] 0.02816901
1/213 # 0.47% native american
## [1] 0.004694836
89/213 # 41.78% asian
## [1] 0.4178404
75/213 # 35.21% latinx
## [1] 0.3521127
(10+12)/213 # 10.33% other
## [1] 0.1032864
both the scores for the reappraisal & suppression subscales of the ERQ are quantitative. to make them qualitative, i will find the median score for each and then sort all scores below the median into a “low” category and all the scores containing the median and above into a “high” category for each scale.
## get the median for the reappraisal & suppression scores.
describe(SWLSandERQ_2$reappraisal_avg) # median is 3.67
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 213 3.56 0.74 3.67 3.57 0.74 1.5 6.67 5.17 0.15 1.33 0.05
describe(SWLSandERQ_2$suppression_avg) # median is 3
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 213 3.24 0.82 3 3.24 0.74 1.25 5 3.75 0.06 -0.49 0.06
## sort the scores below the median into "low" and those above the median into "high" categories for both subscales.
SWLSandERQ_2$reapp_qual <- ifelse(SWLSandERQ_2$reappraisal_avg < 3.67, "low", "high")
SWLSandERQ_2$supp_qual <- ifelse(SWLSandERQ_2$suppression_avg < 3, "low", "high")
factANOVA <- aov(SWLS_avg ~ reapp_qual * supp_qual, data = SWLSandERQ_2)
summary(factANOVA)
## Df Sum Sq Mean Sq F value Pr(>F)
## reapp_qual 1 0.3 0.3078 0.173 0.678
## supp_qual 1 0.0 0.0248 0.014 0.906
## reapp_qual:supp_qual 1 0.3 0.2696 0.151 0.698
## Residuals 209 372.0 1.7798
report::report(factANOVA)
## Warning: Could not find Sum-of-Squares for the (Intercept) in the ANOVA table.
## The ANOVA (formula: SWLS_avg ~ reapp_qual * supp_qual) suggests that:
##
## - The main effect of reapp_qual is statistically not significant and very small
## (F(1, 209) = 0.17, p = 0.678; Eta2 (partial) = 8.27e-04, 95% CI [0.00, 1.00])
## - The main effect of supp_qual is statistically not significant and very small
## (F(1, 209) = 0.01, p = 0.906; Eta2 (partial) = 6.66e-05, 95% CI [0.00, 1.00])
## - The interaction between reapp_qual and supp_qual is statistically not
## significant and very small (F(1, 209) = 0.15, p = 0.698; Eta2 (partial) =
## 7.24e-04, 95% CI [0.00, 1.00])
##
## Effect sizes were labelled following Field's (2013) recommendations.
## descriptives for high reappraisal.
mean(SWLSandERQ_2$SWLS_avg[SWLSandERQ_2$reapp_qual == "high"])
## [1] 4.204494
sd(SWLSandERQ_2$SWLS_avg[SWLSandERQ_2$reapp_qual == "high"])
## [1] 1.349066
## descriptives for low reappraisal.
mean(SWLSandERQ_2$SWLS_avg[SWLSandERQ_2$reapp_qual == "low"])
## [1] 4.127419
sd(SWLSandERQ_2$SWLS_avg[SWLSandERQ_2$reapp_qual == "low"])
## [1] 1.313181
## descriptives for high suppression
mean(SWLSandERQ_2$SWLS_avg[SWLSandERQ_2$supp_qual == "high"])
## [1] 4.168707
sd(SWLSandERQ_2$SWLS_avg[SWLSandERQ_2$supp_qual == "high"])
## [1] 1.397003
## descriptives for high suppression
mean(SWLSandERQ_2$SWLS_avg[SWLSandERQ_2$supp_qual == "low"])
## [1] 4.139394
sd(SWLSandERQ_2$SWLS_avg[SWLSandERQ_2$supp_qual == "low"])
## [1] 1.160885
## descriptives for interaction.
interaction_desc <- with(SWLSandERQ_2, aggregate(x = list(Mean = SWLS_avg, SD = SWLS_avg),
by = list(F1 = reapp_qual, F2 = supp_qual),
FUN = mean_sd))
View(interaction_desc)
## Warning in format.data.frame(x0): corrupt data frame: columns will be truncated
## or padded with NAs
## Warning in system2("/usr/bin/otool", c("-L", shQuote(DSO)), stdout = TRUE):
## running command ''/usr/bin/otool' -L '/Library/Frameworks/R.framework/Resources/
## modules/R_de.so'' had status 1
## look at differences between high and low suppression at high levels of reappraisal (because this was the effect you hypothesized to be significant).
highReapp_supp <- SWLSandERQ_2 %>% filter(reapp_qual == "high") %>%
t.test(SWLS_avg ~ supp_qual, data = .)
report(highReapp_supp)
## Warning: Unable to retrieve data from htest object. Returning an approximate
## effect size using t_to_d().
## Effect sizes were labelled following Cohen's (1988) recommendations.
##
## The Welch Two Sample t-test testing the difference of SWLS_avg by supp_qual
## (mean in group high = 4.18, mean in group low = 4.26) suggests that the effect
## is negative, statistically not significant, and very small (difference = -0.07,
## 95% CI [-0.69, 0.54], t(46.52) = -0.24, p = 0.810; Cohen's d = -0.07, 95% CI
## [-0.65, 0.50])