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
## Warning: package 'apaTables' was built under R version 4.4.3
library(kableExtra) # to create our correlation table
## Warning: package 'kableExtra' was built under R version 4.4.3

2 Importing Data

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

3 State Your Hypothesis

There will be a significant relationship between depression, anxiety, and self-esteem. Specifically, depression will be positively related to anxiety but negatively related to self-esteem, and anxiety will be negatively related to self-esteem.

4 Check Your Variables

# you only need to check the variables you're using in the current analysis
str(d$phq)
##  num [1:256] 2 1.78 1.11 1.33 1.89 ...
str(d$gad)
##  num [1:256] 4 1.43 1 1 3.43 ...
str(d$rse)
##  num [1:256] 2.4 1.4 3.9 3.2 3.3 3 2.7 1.6 3.2 2.3 ...
# Since we're focusing only on our continuous variables, we're going to subset them into their own dataframe.

d2 <- subset(d, select=c(phq, gad, rse))

# describe all three variables

describe(d2)
##     vars   n mean   sd median trimmed  mad min max range  skew kurtosis   se
## phq    1 256 2.69 0.85   2.78    2.70 0.99   1   4     3 -0.09    -1.06 0.05
## gad    2 256 2.65 0.92   2.71    2.67 1.06   1   4     3 -0.18    -1.15 0.06
## rse    3 256 2.15 0.65   2.00    2.11 0.59   1   4     3  0.51    -0.27 0.04
# also use histograms to examine your continuous variables

hist(d2$phq,
     main = "Histogram of Patient Health Questionnaire-9",
     xlab = "Patient Health Questionnaire-9")

hist(d2$gad,
     main = "Histogram of Generalized Anxiety Disorder-7",
     xlab = "Generalized Anxiety Disorder-7")

hist(d2$rse,
     main = "Histogram of Rosenberg Self-Esteem Inventory",
     xlab = "Rosenberg Self-Esteem Inventory")

# last, use scatterplots to examine your continuous variables together, for each pairing

plot(d2$phq, d2$gad,
     main = "Scatterplot of Depression and Anxiety",
     xlab = "Patient Health Questionnaire-9",
     ylab = "Generalized Anxiety Disorder-7")

plot(d2$phq, d2$rse,
     main = "Scatterplot of Depression and Self-Esteem",
     xlab = "Patient Health Questionnaire-9",
     ylab = "Rosenberg Self-Esteem Inventory")

plot(d2$gad, d2$rse,
     main = "Scatterplot of Anxiety and Self-Esteem",
     xlab = "Generalized Anxiety Disorder-7",
     ylab = "Rosenberg Self-Esteem Inventory")

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have one observation 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 are going to standardize (z-score) all of our 3 variables, and check them for outliers.

d2$phq_z <- scale(d2$phq, center=TRUE, scale=TRUE)
hist(d2$phq_z)

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

sum(d2$gad_z < -3 | d2$gad_z > 3)
## [1] 0
d2$rse_z <- scale(d2$rse, center=TRUE, scale=TRUE)
hist(d2$rse_z)

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

5.2 Issues with My Data

[Fill in after running the code. Use the template below and replace the bracketed values with your actual output:]

All three of my variables (depression, anxiety, and self-esteem) meet the assumptions of Pearson’s correlation coefficient. All variables had skew and kurtosis within the accepted range, and none of the three variables contained any outliers (depression: 0 outliers, anxiety: 0 outliers, self-esteem: 0 outliers).

6 Run a Single Correlation

# Running a single correlation between depression (phq) and anxiety (gad) as an example
corr_output <- corr.test(d2$phq, d2$gad)

7 View Single Correlation

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

8 Create a Correlation Matrix

# Running the full matrix across all three variables
corr_output_m <- corr.test(subset(d2, select=c(phq, gad, rse)))

9 View Test Output

corr_output_m
## Call:corr.test(x = subset(d2, select = c(phq, gad, rse)))
## Correlation matrix 
##       phq   gad   rse
## phq  1.00  0.77 -0.73
## gad  0.77  1.00 -0.62
## rse -0.73 -0.62  1.00
## Sample Size 
## [1] 256
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##     phq gad rse
## phq   0   0   0
## gad   0   0   0
## rse   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 depression, anxiety, and self-esteem would be correlated, we calculated a matrix of Pearson’s correlation coefficients. All three variables (depression, anxiety, and self-esteem) met the required assumptions of the test, with all meeting the standards of normality and containing no outliers.

As predicted, we found that depression and anxiety were significantly positively correlated (r = .77, p < .001), depression and self-esteem were significantly negatively correlated (r = -.73, p < .001), and anxiety and self-esteem were significantly negatively correlated (r = -.62, p < .001). The effect sizes were Strong for all three relationships (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
  1. Depression
2.69 0.85
  1. Anxiety
2.65 0.92 .77**
[.72, .82]
  1. Self-Esteem
2.15 0.65 -.73** -.62**
[-.78, -.67] [-.69, -.53]
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.