1 Loading Libraries

library(psych) # for the describe() command and the corr.test() command
library(apaTables) # to create our correlation table
library(kableExtra) # to create our correlation table

2 Importing Data

# import the dataset you cleaned previously
# this will be the dataset you'll use throughout the rest of the semester
# use ARC data downloaded previous for lab
d <- read.csv(file="Data/arcdata_final.csv", header=T)

3 State Your Hypothesis

We predict that self-esteem (measured by the RSE), anxiety (measured by GAD), social support (measured using social support measure), and mental flexibility (measured by the MFQ-26) will all be correlated with each other.

4 Check Your Variables

# you only need to check the variables you're using in the current analysis
# although you checked them previously, it's always a good idea to look them over again and be sure that everything is correct
str(d)
## 'data.frame':    1210 obs. of  7 variables:
##  $ X        : int  1 20 30 31 33 49 57 68 81 86 ...
##  $ trans    : chr  "no" "no" "no" "no" ...
##  $ ethnicity: chr  "White - British, Irish, other" "White - British, Irish, other" "White - British, Irish, other" "White - British, Irish, other" ...
##  $ rse      : num  2.3 1.6 3.9 1.7 3.9 2.4 1.8 1.3 3.5 2.6 ...
##  $ gad      : num  1.86 3.86 1.14 2 1.43 ...
##  $ support  : num  2.5 2.17 5 2.5 3.67 ...
##  $ mfq_26   : num  4.2 3.35 4.65 4.65 4.5 4.3 5.25 5 4.7 4.05 ...
# since we're focusing on our continuous variables, we're going to subset them into their own dataframe. this will make some stuff we're doing later easier.
d2 <- subset(d, select=c(gad,support,rse,mfq_26))

# you can use the describe() command on an entire dataframe (d) or just on a single variable (d$pss)
describe(d2)
##         vars    n mean   sd median trimmed  mad min  max range  skew kurtosis
## gad        1 1210 2.05 0.91   1.71    1.96 0.85 1.0 4.00  3.00  0.67    -0.73
## support    2 1210 3.56 0.94   3.67    3.62 0.99 1.0 5.00  4.00 -0.43    -0.54
## rse        3 1210 2.63 0.72   2.70    2.64 0.74 1.0 4.00  3.00 -0.22    -0.72
## mfq_26     4 1210 4.30 0.67   4.35    4.32 0.67 1.8 5.95  4.15 -0.34     0.13
##           se
## gad     0.03
## support 0.03
## rse     0.02
## mfq_26  0.02
# our fake variable has high kurtosis, which I'll ignore. you don't need to discuss univariate normality in the results write-ups for the labs/homework, but you will need to discuss it in your final manuscript

# also use histograms to examine your continuous variables
hist(d2$gad)

hist(d2$support)

hist(d2$rse)

hist(d2$mfq_26)

# last, use scatterplots to examine your continuous variables together
plot(d2$gad, d2$support)

plot(d2$gad, d2$rse)

plot(d2$gad, d2$mfq_26)

plot(d2$support, d2$rse)

plot(d2$support, d2$mfq_26)

plot(d2$rse, d2$mfq_26)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have one measurement for each score for each participant

In our Data Prep and Basic Stats lab, we dropped any participants with missing data. So we’re good for this assumption!

  • Variables should be continuous and normally distributed

Checked in the section above!

  • Relationship between the variables should be linear

This one is a bit tricky! We’ll talk about it in class; feel free to take notes here.

  • Outliers should be identified and removed

We’ll do this one below.

5.1.1 Checking for Outliers

Note: You are not required to screen out outliers or take any action based on what you see here. This is something you will check and then discuss in your write-up.

d$gad_std <- scale(d$gad, center=T, scale=T)
hist(d$gad_std)

sum(d$gad_std < -3 | d$gad_std > 3)
## [1] 0
d$support_std <- scale(d$support, center=T, scale=T)
hist(d$support_std)

sum(d$support_std < -3 | d$support_std > 3)
## [1] 0
d$rse_std <- scale(d$rse, center=T, scale=T)
hist(d$rse_std)

sum(d$rse_std < -3 | d$rse_std > 3)
## [1] 0
d$mfq_26_std <- scale(d$mfq_26, center=T, scale=T)
hist(d$mfq_26_std)

sum(d$mfq_26_std < -3 | d$mfq_26_std > 3)
## [1] 4

5.2 Issues with My Data

All but one of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, mental flexibility (measured using the MFQ-26) had 4 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction. Any correlations with my mental flexibility measure should be evaluated carefully due to these risks.

6 Create a Correlation Matrix

corr_output_m <- corr.test(d2)

7 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##           gad support   rse mfq_26
## gad      1.00   -0.46 -0.71  -0.47
## support -0.46    1.00  0.52   0.41
## rse     -0.71    0.52  1.00   0.59
## mfq_26  -0.47    0.41  0.59   1.00
## Sample Size 
## [1] 1210
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##         gad support rse mfq_26
## gad       0       0   0      0
## support   0       0   0      0
## rse       0       0   0      0
## mfq_26    0       0   0      0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

8 Write Up Results

To test my hypothesis that self-esteem (measured by the RSE), anxiety (measured by GAD), social support (measured using social support measure), and mental flexibility (measured by the MFQ-26) will all be correlated with each other, I calculated a series of Pearson’s correlation coefficients. Most of my data met the assumptions of the test, with all variables meeting the standards of normality and no outliers. One variable, mental flexibility, did have outliers, so any significant results involving that variable should be evaluated carefully.

As predicted, I found that all four variables were significantly correlated (all ps < .001). The effect sizes of all correlations were large (rs > .5; Cohen, 1988).

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Anxiety (GAD) 2.05 0.91
Social Support (Support) 3.56 0.94 -.46**
[-.50, -.42]
Self-esteem (RSE) 2.63 0.72 -.71** .52**
[-.73, -.68] [.48, .56]
Mental Flexibility (MFQ-26) 4.30 0.67 -.47** .41** .59**
[-.51, -.42] [.36, .45] [.56, .63]
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.
* indicates p < .05
** indicates p < .01.

References

Cohen J. (1988). Statistical Power Analysis for the Behavioral Sciences. New York, NY: Routledge Academic.