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/mydata.csv", header=T)

3 State Your Hypothesis

We predict that resiliency to stress (measured by the BRS), depression symptoms (measured by the PHQ-9), anxiety (measured by the GAD), and recent feelings/emotions (measured by the mfq 26) will all be correlated with each other. Furthermore, we predict that resiliency to stress will be lower in participants who are higher in anxiety or who report more symptoms of depression.

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':    350 obs. of  6 variables:
##  $ sleep_hours: chr  "3 7-8 hours" "3 7-8 hours" "4 8-10 hours" "2 5-6 hours" ...
##  $ exercise   : num  3.5 2 1 6 1.5 1.5 4 4 1 0 ...
##  $ brs        : num  4 2.5 1.17 2.33 2 ...
##  $ phq        : num  2.22 2.56 2.56 2.78 3.11 ...
##  $ gad        : num  2 2 4 3.14 3.14 ...
##  $ mfq_26     : num  4.4 4.7 4.05 3.65 4.2 4.2 3.75 3.3 4.35 4.5 ...
# 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(brs,phq,gad,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
## brs       1 350 2.74 0.88   2.83    2.73 0.99 1.0 5.00  4.00  0.07    -0.67
## phq       2 350 2.53 0.89   2.56    2.53 0.99 1.0 4.00  3.00  0.02    -1.09
## gad       3 350 2.51 0.93   2.57    2.50 1.27 1.0 4.00  3.00  0.02    -1.17
## mfq_26    4 350 4.13 0.70   4.15    4.14 0.67 1.8 5.75  3.95 -0.17     0.16
##          se
## brs    0.05
## phq    0.05
## gad    0.05
## mfq_26 0.04
# 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$brs)

hist(d2$phq)

hist(d2$gad)

hist(d2$mfq_26)

# last, use scatterplots to examine your continuous variables together
plot(d$brs, d$phq)

plot(d$brs, d$gad)

plot(d$brs, d$mfq_26)

plot(d$phq, d$gad)

plot(d$phq, d$mfq_26)

plot(d$gad, d$mfq_26)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have two measurements for each participant
  • Variables should be continuous and normally distributed
  • Outliers should be identified and removed
  • Relationship between the variables should be linear

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.

d2$brs <- scale(d2$brs, center=T, scale=T)
hist(d2$brs)

sum(d2$brs < -3 | d2$brs > 3)
## [1] 0
d2$phq <- scale(d2$phq, center=T, scale=T)
hist(d2$phq)

sum(d2$phq < -3 | d2$phq > 3)
## [1] 0
d2$gad <- scale(d2$gad, center=T, scale=T)
hist(d2$gad)

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

sum(d2$mfq_26 < -3 | d2$mfq_26 > 3)
## [1] 2

5.2 Issues with My Data

All but one of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, the measure of recent feelings and emotions (mfq_26) had low kurtosis (0.16) but had 2 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. # Run a Single Correlation

corr_output <- corr.test(d2$brs, d2$phq)

6 View Single Correlation

corr_output
## Call:corr.test(x = d2$brs, y = d2$phq)
## Correlation matrix 
##       [,1]
## [1,] -0.59
## Sample Size 
## [1] 350
## These are the unadjusted probability values.
##   The probability values  adjusted for multiple tests are in the p.adj object. 
##      [,1]
## [1,]    0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

7 Create a Correlation Matrix

Strong: Between |0.50| and |1| Moderate: Between |0.30| and |0.49| Weak: Between |0.10| and |0.29| Trivial: Less than |0.09|

corr_output_m <- corr.test(d2)

8 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##          brs   phq   gad mfq_26
## brs     1.00 -0.59 -0.58   0.64
## phq    -0.59  1.00  0.80  -0.44
## gad    -0.58  0.80  1.00  -0.42
## mfq_26  0.64 -0.44 -0.42   1.00
## Sample Size 
## [1] 350
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##        brs phq gad mfq_26
## brs      0   0   0      0
## phq      0   0   0      0
## gad      0   0   0      0
## mfq_26   0   0   0      0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

9 Write Up Results

To test our hypothesis that resiliancy to stress (measured by the BRS), depression symptoms (measured by the PHQ-9), anxiety (measured by the GAD), and recent feelings/emotions (measured by the mfq_26) would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Most of our data met the assumptions of the test, with all variables meeting the standards of normality and no outliers. One variable, recent feelings and emotions, did have 2 outliers and so any significant results involving that variable should be evaluated carefully.

As predicted, we found that all four variables were significantly correlated (all ps < .001). The effect sizes of all correlations were large (rs > .5; Cohen, 1988). This test also supported our second hypothesis, that resiliency to stress would be lower in participants who are higher in anxiety or who report more symptoms of depression, as can be seen by the correlation coefficients reported in Table 1.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Resiliancy to stress (BRS) -0.00 1.00
Depression symptoms (PHQ-9) 0.00 1.00 -.59**
[-.65, -.51]
Anxiety (GAD) -0.00 1.00 -.58** .80**
[-.65, -.51] [.76, .84]
Recent feelings and emotions (mfq_26) -0.00 1.00 .64** -.44** -.42**
[.57, .70] [-.53, -.36] [-.50, -.33]
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.