1 Loading Libraries

#install.packages("apaTables")
#install.packages("kableExtra")

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

d <- read.csv(file="Data/projectdata.csv", header=T)

3 State Your Hypothesis

There will be a significant relationship between perceived stress (PSS-4), anxiety symptoms (GAD-7), and resilience (BRS). Specifically, perceived stress will be positively related to anxiety symptoms but negatively related to resilience, and anxiety symptoms will be negatively related to resilience.

4 Check Your Variables

# you only need to check the variables you're using in the current analysis
# it's always a good idea to look them to be sure that everything is correct
str(d)
## 'data.frame':    297 obs. of  7 variables:
##  $ X      : int  7888 7365 8747 7357 8760 8654 8272 8738 7911 8463 ...
##  $ gender : chr  "male" "female" "female" "female" ...
##  $ mhealth: chr  "none or NA" "none or NA" "none or NA" "none or NA" ...
##  $ phq    : num  2 1.78 1 1.11 1.11 ...
##  $ gad    : num  4 1.43 1.14 1 1 ...
##  $ brs    : num  2 3.83 3.83 4 4.67 ...
##  $ pss    : num  3.75 2.25 1.5 1.75 2.5 1.75 3 2.5 2.5 2.25 ...
# Since we're focusing only on our continuous variables, we're going to subset them into their own dataframe. This will make some stuff we're doing later on easier.

d2 <- subset(d, select=c(pss, gad, brs))

# 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   se
## pss    1 297 3.51 0.87   3.75    3.56 0.74   1   5     4 -0.43    -0.51 0.05
## gad    2 297 2.61 0.91   2.71    2.62 1.06   1   4     3 -0.12    -1.14 0.05
## brs    3 297 2.64 0.86   2.50    2.64 0.74   1   5     4  0.15    -0.58 0.05
# also use histograms to examine your continuous variables
# Because we are looking at 3 variables, we will have 3 histograms.

hist(d$pss)

hist(d$gad)

hist(d$brs)

# last, use scatterplots to examine your continuous variables together, for each pairing
# because we are looking at 3 variables, we will have 3 pairings/plots. 

plot(d$pss, d$gad)

plot(d$pss, d$brs)

plot(d$gad, d$brs)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have 2 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: For correlations, you will NOT screen out outliers or take any action based on what you see here. This is something you will simply check and then discuss in your write-up. We will learn how to remove outliers in later analyses.

# We are going to standardize (z-score) all of our 3 variables, and check them for outliers.

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

sum(d2$pss < -3 | d2$pss > 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$brs <- scale(d2$brs, center=T, scale=T)
hist(d2$brs)

sum(d2$brs < -3 | d2$brs > 3)
## [1] 0

5.2 Issues with My Data

All 3 of my variables meet all of the assumptions of Pearson’s correlation coefficient. Perceived stress, anxiety symptoms, and resilience all met the standards of normality and contained no outliers. The relationships between the variables appeared linear based on visual inspection of the scatterplots.

6 Run a Single Correlation

corr_output <- corr.test(d2$pss, d2$gad)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$pss, y = d2$gad)
## Correlation matrix 
##      [,1]
## [1,] 0.74
## Sample Size 
## [1] 297
## 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

8 Create a Correlation Matrix

corr_output_m <- corr.test(d2)

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##       pss   gad   brs
## pss  1.00  0.74 -0.59
## gad  0.74  1.00 -0.57
## brs -0.59 -0.57  1.00
## Sample Size 
## [1] 297
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##     pss gad brs
## pss   0   0   0
## gad   0   0   0
## brs   0   0   0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option
# Remember to report the p-values from the matrix that are ABOVE the diagonal!

Remember, Pearson’s r is also an effect size! We don’t report effect sizes for non-sig correlations.

  • 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|

10 Write Up Results

To test our hypothesis that perceived stress, anxiety symptoms, and resilience would be significantly correlated with one another, we calculated a series of Pearson’s correlation coefficients. All three variables (perceived stress, anxiety symptoms, and resilience) met the required assumptions of the test, with all meeting the standards of normality and containing no outliers.

As predicted, we found that perceived stress and anxiety symptoms were significantly positively correlated (r = .74, p < .001), perceived stress and resilience were significantly negatively correlated (r = -.59, p < .001), and anxiety symptoms and resilience were significantly negatively correlated (r = -.57, p < .001). The effect sizes of all correlations were strong (rs > .50; Cohen, 1988). Please refer to the correlation coefficients reported in Table 1.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2
Perceived Stress 3.51 0.87
Anxiety Symptoms 2.61 0.91 .74**
[.68, .78]
Resilience 2.64 0.86 -.59** -.57**
[-.66, -.52] [-.64, -.49]
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.