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

# For HW, import the your project dataset you cleaned previously; this will be the dataset you'll use throughout the rest of the semester

3 State Your Hypothesis

There will be a significant relationship between perceived stress (pss), anxiety symptoms (gad), and social support (support). Specifically, perceived stress will be positively related to anxiety symptoms, and negatively related to social support, and anxiety symptoms will be negatively related to social support.

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':    612 obs. of  7 variables:
##  $ X                  : int  520 2814 3146 3295 717 6056 4753 5365 2044 1965 ...
##  $ education          : chr  "1 equivalent to not completing high school" "prefer not to say" "2 equivalent to high school completion" "prefer not to say" ...
##  $ relationship_status: chr  "Single, never married" "Single, never married" "Prefer not to say" "Single, never married" ...
##  $ exercise           : chr  "1 less than 1 hour" "1 less than 1 hour" "1 less than 1 hour" "1 less than 1 hour" ...
##  $ pss                : num  2.75 2.25 3 2 1.75 2 1 1.25 3 1.25 ...
##  $ support            : num  2.83 3 4 4 3.67 ...
##  $ gad                : num  1.14 1.29 1 1 1.14 ...
# 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, support))

# 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
## pss        1 612 3.13 0.95   3.25    3.14 1.11   1   5     4 -0.15    -0.78
## gad        2 612 2.17 0.93   2.00    2.11 1.06   1   4     3  0.47    -1.00
## support    3 612 3.47 0.95   3.50    3.51 0.99   1   5     4 -0.30    -0.64
##           se
## pss     0.04
## gad     0.04
## support 0.04
# also use histograms to examine your continuous variables
# Because we are looking at 3 variables, we will have 3 histograms.

hist(d2$pss)

hist(d2$gad)

hist(d2$support)

# 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(d2$pss, d2$gad)

plot(d2$pss, d2$support)

plot(d2$gad, d2$support)

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: 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 removed outliers in later analyses.

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

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

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

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

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

5.2 Issues with My Data

All 3 of my variables met all of the assumptions of Pearson’s correlation coefficient. All variables met the standards of normality and contained no outliers. The relationships between all variables appeared linear based on scatterplot inspection.

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] 612
## 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 support
## pss      1.00  0.74   -0.49
## gad      0.74  1.00   -0.43
## support -0.49 -0.43    1.00
## Sample Size 
## [1] 612
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##         pss gad support
## pss       0   0       0
## gad       0   0       0
## support   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 social support would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. All three variables met the required assumptions of the test, with all meeting the standards of normality, containing no outliers, and displaying linear relationships.

As predicted, we found that all three variables were significantly correlated (all ps < .001). The effect size of the correlation between perceived stress and anxiety symptoms was strong (r = .74; Cohen, 1988), while the correlations between perceived stress and social support (r = .49) and anxiety symptoms and social support (r = .43) were moderate. Additionally, perceived stress was found to be positively related to anxiety symptoms, and negatively related to social support, and anxiety symptoms were negatively related to social support, as predicted. 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.13 0.95
Anxiety Symptoms 2.17 0.93 .74**
[.70, .77]
Social Support 3.47 0.95 -.49** -.43**
[-.55, -.42] [-.49, -.36]
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.