setwd("~/okara004@ucr.edu - Google Drive/My Drive/classes/fall 2022 quarter/PSYC 211 -- introduction to quantitative methods in psychology/problem sets/problem set #3")
i’ll be using a data file given to me by my advisor (same one i used for problem sets #1 & 2).
patience_data <- read.csv("patience22ucr_copy.csv")
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 scale items will be removed. additionally, anyone who did not report being either male or female 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), ]
# now take a look at the different reported genders.
table(SWLSandERQ_2$sex)
##
## 1 2 3 4
## 91 115 3 4
# remove anyone who reported a gender other than male/female.
gender_TABLE <- table(SWLSandERQ_2$sex <= 2, SWLSandERQ_2$sn)
gender_TABLE
##
## 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
## FALSE 0 0 0 0 0 0 1 0 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 0 1 1 1 1 1 1 1
##
## 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
## FALSE 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##
## 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
## FALSE 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##
## 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
## FALSE 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##
## 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
## FALSE 0 0 0 0 0 0 0 1 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 1 0 1 1 1 1 1 1
##
## 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
## FALSE 0 0 0 0 0 0 0 0 0 0 0 0 1 0
## TRUE 1 1 1 1 1 1 1 1 1 1 1 1 0 1
##
## 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
## FALSE 0 0 0 0 0 0 1 0 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 0 1 1 1 1 1 1 1
##
## 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
## FALSE 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##
## 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
## FALSE 0 0 0 0 0 0 0 1 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 1 0 1 1 1 1 1 1
##
## 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
## FALSE 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##
## 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
## FALSE 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##
## 1154 1155 1156 1157 1158 1159 1161 1162 1163 1164 1165 1166 1167 1168
## FALSE 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##
## 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
## FALSE 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 1 1 1 1 1 1 1 1
##
## 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
## FALSE 0 0 0 0 0 0 0 0 0 0 0 1 0 0
## TRUE 1 1 1 1 1 1 1 1 1 1 1 0 1 1
##
## 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1208 1209 1210 1211
## FALSE 0 0 0 0 0 0 1 0 0 0 0 0 0 0
## TRUE 1 1 1 1 1 1 0 1 1 1 1 1 1 1
##
## 1212 1213 1214
## FALSE 0 0 0
## TRUE 1 1 1
genderMF_LIST <- which(gender_TABLE[2 , ] == 1)
length(genderMF_LIST) ### we're left with 206 subjects, which is the total of male + female found above in the table
## [1] 206
SWLSandERQ_3 <- SWLSandERQ_2[SWLSandERQ_2$sn %in% names(genderMF_LIST), ]
# first look at the information on participant sex.
table(SWLSandERQ_3$sex) # 1 is male, 2 is female
##
## 1 2
## 91 115
115/206 # 55.83% women
## [1] 0.5582524
# then look at the descriptive stats on participant age.
library(psych)
describe(SWLSandERQ_3$age)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 206 20.51 2.2 20 20.23 1.48 18 34 16 2.73 12.68 0.15
# lastly look at the information on participant race/ethnicity.
table(SWLSandERQ_3$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
## 18 5 1 88 73 9 12
18/206 # 8.74% white
## [1] 0.08737864
5/206 # 2.43% black
## [1] 0.02427184
1/206 # 0.49% native american
## [1] 0.004854369
88/206 # 42.72% asian
## [1] 0.4271845
73/206 # 35.44% latinx
## [1] 0.3543689
(9+12)/206 # 10.19% other
## [1] 0.1019417
# first analysis is a correlation between satisfaction with life & reappraisal.
correlation <- cor.test(SWLSandERQ_3$reappraisal_avg, SWLSandERQ_3$SWLS_avg)
correlation
##
## Pearson's product-moment correlation
##
## data: SWLSandERQ_3$reappraisal_avg and SWLSandERQ_3$SWLS_avg
## t = 2.4831, df = 204, p-value = 0.01383
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.03540764 0.30093506
## sample estimates:
## cor
## 0.1712799
report::report(correlation)
## Effect sizes were labelled following Funder's (2019) recommendations.
##
## The Pearson's product-moment correlation between SWLSandERQ_3$reappraisal_avg
## and SWLSandERQ_3$SWLS_avg is positive, statistically significant, and small (r
## = 0.17, 95% CI [0.04, 0.30], t(204) = 2.48, p = 0.014)
# create a scatterplot for the results.
plot(SWLSandERQ_3$reappraisal_avg, SWLSandERQ_3$SWLS_avg,
main = "Relationship Between Satisfaction with Life & Reappraisal",
xlab = "Average Reappraisal Score",
xlim = range(1:7),
ylab = "Average Satisfaction with Life Score",
ylim = range(1:7))
# mean center your reappraisal data for a regression analysis.
SWLSandERQ_3$reappraisal_avg_MC <- scale(SWLSandERQ_3$reappraisal_avg,
center = TRUE,
scale = FALSE)
# run a regression that predicts SWL from reappraisal.
SWLS_ERQ_reg <- lm(SWLS_avg ~ reappraisal_avg_MC, data = SWLSandERQ_3)
summary(SWLS_ERQ_reg)
##
## Call:
## lm(formula = SWLS_avg ~ reappraisal_avg_MC, data = SWLSandERQ_3)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.4040 -0.8468 0.0996 0.9050 2.8032
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.16214 0.09141 45.533 <2e-16 ***
## reappraisal_avg_MC 0.31082 0.12517 2.483 0.0138 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.312 on 204 degrees of freedom
## Multiple R-squared: 0.02934, Adjusted R-squared: 0.02458
## F-statistic: 6.166 on 1 and 204 DF, p-value: 0.01383
report::report(SWLS_ERQ_reg)
## We fitted a linear model (estimated using OLS) to predict SWLS_avg with
## reappraisal_avg_MC (formula: SWLS_avg ~ reappraisal_avg_MC). The model explains
## a statistically significant and weak proportion of variance (R2 = 0.03, F(1,
## 204) = 6.17, p = 0.014, adj. R2 = 0.02). The model's intercept, corresponding
## to reappraisal_avg_MC = 0, is at 4.16 (95% CI [3.98, 4.34], t(204) = 45.53, p <
## .001). Within this model:
##
## - The effect of reappraisal avg MC is statistically significant and positive
## (beta = 0.31, 95% CI [0.06, 0.56], t(204) = 2.48, p = 0.014; Std. beta = 0.17,
## 95% CI [0.04, 0.31])
##
## Standardized parameters were obtained by fitting the model on a standardized
## version of the dataset. 95% Confidence Intervals (CIs) and p-values were
## computed using a Wald t-distribution approximation.
# run a one-sample t-test comparing the sample mean to the population mean (i am using 4.61 as the population mean based on the Gross & John, 2003 paper).
oneS_tTest <- t.test(SWLSandERQ_3$reappraisal_avg, mu = 4.61)
oneS_tTest
##
## One Sample t-test
##
## data: SWLSandERQ_3$reappraisal_avg
## t = -20.682, df = 205, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 4.61
## 95 percent confidence interval:
## 3.454621 3.655735
## sample estimates:
## mean of x
## 3.555178
report::report(oneS_tTest)
## 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 One Sample t-test testing the difference between
## SWLSandERQ_3$reappraisal_avg (mean = 3.56) and mu = 4.61 suggests that the
## effect is negative, statistically significant, and large (difference = -1.05,
## 95% CI [3.45, 3.66], t(205) = -20.68, p < .001; Cohen's d = -1.44, 95% CI
## [-1.64, -1.25])
describe(SWLSandERQ_3$reappraisal_avg)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 206 3.56 0.73 3.67 3.57 0.74 1.5 6.67 5.17 0.02 1.14 0.05
# check for homoscedasticity in preparation for running a paired-samples t-test on reappraisal and suppression scores.
var.test(SWLSandERQ_3$reappraisal_avg, SWLSandERQ_3$suppression_avg)
##
## F test to compare two variances
##
## data: SWLSandERQ_3$reappraisal_avg and SWLSandERQ_3$suppression_avg
## F = 0.78186, num df = 205, denom df = 205, p-value = 0.07887
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.5941528 1.0288753
## sample estimates:
## ratio of variances
## 0.7818626
# then run the paired-samples t-test.
paired_tTest <- t.test(SWLSandERQ_3$reappraisal_avg, SWLSandERQ_3$suppression_avg,
var.equal = TRUE,
paired = TRUE)
paired_tTest
##
## Paired t-test
##
## data: SWLSandERQ_3$reappraisal_avg and SWLSandERQ_3$suppression_avg
## t = 4.6484, df = 205, p-value = 5.983e-06
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## 0.1757385 0.4346174
## sample estimates:
## mean difference
## 0.305178
report::report(paired_tTest)
## 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 Paired t-test testing the difference between SWLSandERQ_3$reappraisal_avg
## and SWLSandERQ_3$suppression_avg (mean difference = 0.31) suggests that the
## effect is positive, statistically significant, and small (difference = 0.31,
## 95% CI [0.18, 0.43], t(205) = 4.65, p < .001; Cohen's d = 0.32, 95% CI [0.18,
## 0.46])
describe(SWLSandERQ_3$reappraisal_avg)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 206 3.56 0.73 3.67 3.57 0.74 1.5 6.67 5.17 0.02 1.14 0.05
describe(SWLSandERQ_3$suppression_avg)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 206 3.25 0.83 3.25 3.25 0.74 1.25 5 3.75 0.04 -0.51 0.06
# prepare your data to run an independent samples t-test on differences between men & women in reappraisal use.
SWLSandERQ_3$sex <- as.factor(SWLSandERQ_3$sex)
levels(SWLSandERQ_3$sex) <- list('Male' = "1", 'Female' = "2")
female_reapp <- SWLSandERQ_3$reappraisal_avg[SWLSandERQ_3$sex == "Female"]
male_reapp <- SWLSandERQ_3$reappraisal_avg[SWLSandERQ_3$sex == "Male"]
var.test(female_reapp, male_reapp)
##
## F test to compare two variances
##
## data: female_reapp and male_reapp
## F = 1.2448, num df = 114, denom df = 90, p-value = 0.2793
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.8363606 1.8358121
## sample estimates:
## ratio of variances
## 1.244825
# run the independent-samples t-test.
ind_tTest <- t.test(female_reapp, male_reapp, var.equal=T)
ind_tTest
##
## Two Sample t-test
##
## data: female_reapp and male_reapp
## t = 1.1485, df = 204, p-value = 0.2521
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.08447237 0.32021055
## sample estimates:
## mean of x mean of y
## 3.607246 3.489377
report::report(ind_tTest)
## Warning: Missing values detected. NAs dropped.
## Effect sizes were labelled following Cohen's (1988) recommendations.
##
## The Two Sample t-test testing the difference between female_reapp and
## male_reapp (mean of x = 3.61, mean of y = 3.49) suggests that the effect is
## positive, statistically not significant, and very small (difference = 0.12, 95%
## CI [-0.08, 0.32], t(204) = 1.15, p = 0.252; Cohen's d = 0.16, 95% CI [-0.11,
## 0.44])
describe(male_reapp)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 91 3.49 0.69 3.5 3.53 0.74 1.5 5 3.5 -0.51 0.17 0.07
describe(female_reapp)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 115 3.61 0.77 3.67 3.6 0.74 1.67 6.67 5 0.28 1.35 0.07
# lastly, run the power analysis for part 3 of the problem set.
library(pwr)
pwr.t.test(d = .7,
sig.level = .05,
power = .8,
type = "two.sample",
alternative = "two.sided")
##
## Two-sample t test power calculation
##
## n = 33.02457
## d = 0.7
## sig.level = 0.05
## power = 0.8
## alternative = two.sided
##
## NOTE: n is number in *each* group