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/arc_data_final_SP26.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 levels of depression, levels of anxiety, and levels of worry. Specifically, levels of depression will be positively related to levels of anxiety and levels of worry.

In your HW, paste in your correlation hypothesis from your Hypothesis Activity assignment – make any necessary revisions based on grader feedback. Delete this reminder in your HW.]

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':    996 obs. of  40 variables:
##  $ X                   : int  520 2814 3146 3295 717 6056 4753 5365 2044 1965 ...
##  $ gender              : chr  "female" "male" "female" "male" ...
##  $ trans               : chr  "no" "no" "no" "no" ...
##  $ sexual_orientation  : chr  "Prefer not to say" "Heterosexual/Straight" "Heterosexual/Straight" "Heterosexual/Straight" ...
##  $ ethnicity           : chr  "Prefer not to say" "White - British, Irish, other" "Asian/Asian British - Indian, Pakistani, Bangladeshi, other" "Asian/Asian British - Indian, Pakistani, Bangladeshi, other" ...
##  $ relationship_status : chr  "Single, never married" "Single, never married" "Prefer not to say" "Single, never married" ...
##  $ age                 : chr  "1 under 18" "1 under 18" "1 under 18" "1 under 18" ...
##  $ urban_rural         : chr  "town" "town" "town" "town" ...
##  $ income              : chr  NA NA NA NA ...
##  $ education           : chr  "1 equivalent to not completing high school" "prefer not to say" "2 equivalent to high school completion" "prefer not to say" ...
##  $ employment          : chr  "1 high school equivalent" "1 high school equivalent" "1 high school equivalent" "1 high school equivalent" ...
##  $ treatment           : chr  NA "not in treatment" NA "no psychological disorders" ...
##  $ health              : chr  "something else or not applicable" "something else or not applicable" "prefer not to say" "lung disease" ...
##  $ mhealth             : chr  "none or NA" "none or NA" "none or NA" "none or NA" ...
##  $ sleep_hours         : chr  "2 5-6 hours" "3 7-8 hours" "2 5-6 hours" "4 8-10 hours" ...
##  $ exercise            : chr  "1 less than 1 hour" "1 less than 1 hour" "1 less than 1 hour" "1 less than 1 hour" ...
##  $ pet                 : chr  "cat" "other" "no pets" "no pets" ...
##  $ covid_pos           : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ covid_neg           : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ big5_open           : num  3.67 4.33 5.67 6 5.67 ...
##  $ big5_con            : num  3 4 6 4 3.33 ...
##  $ big5_agr            : num  4.33 2.67 5.67 5.67 5 ...
##  $ big5_neu            : num  5.33 2.67 1 3.67 4.33 ...
##  $ big5_ext            : num  2 2.67 4.67 4.33 1.67 ...
##  $ pswq                : num  2.71 1.43 1.86 1.79 2.36 ...
##  $ iou                 : num  2.22 1.52 1.78 1.85 2.22 ...
##  $ mfq_26              : num  2.7 4.55 4.8 3.8 4.5 4 5.8 4.2 4.5 5.25 ...
##  $ mfq_state           : num  3 4.38 4.88 4.88 4.88 ...
##  $ rse                 : num  2.6 3.1 3.7 3 3 3 4 3.8 2.5 4 ...
##  $ school_covid_support: num  NA NA NA NA NA NA NA NA NA NA ...
##  $ school_att          : num  NA NA NA NA NA NA NA NA NA NA ...
##  $ pas_covid           : num  3 3.44 4.67 2.44 1.56 ...
##  $ pss                 : num  2.75 2.25 3 2 1.75 2 1 1.25 3 1.25 ...
##  $ phq                 : num  1.56 1.44 1.11 1.33 1.44 ...
##  $ gad                 : num  1.14 1.29 1 1 1.14 ...
##  $ edeq12              : num  1.33 1.08 1 1 1.17 ...
##  $ brs                 : num  NA NA NA NA NA NA NA NA NA NA ...
##  $ swemws              : num  3 2.86 4 3.57 3.86 ...
##  $ isolation_c         : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ support             : num  2.83 3 4 4 3.67 ...
# 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(phq, gad, pswq))

# 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
## phq     1 727 2.28 0.86   2.22    2.23 0.99   1   4     3  0.37    -0.90 0.03
## gad     2 735 2.20 0.93   2.00    2.14 1.06   1   4     3  0.43    -1.03 0.03
## pswq    3 916 2.69 0.76   2.79    2.70 0.85   1   5     4 -0.15    -0.89 0.03
# NOTE: Our fake variable has high kurtosis, which we'll ignore for the lab because we created it to be problematic. If you have high skew or kurtosis for any of your project variables, you will need to discuss it below in the Issues with My Data and Write up Results sections, as well as in your final project manuscript if your data does not meet the normality assumption.


# also use histograms to examine your continuous variables
# Because we are looking at 3 variables, we will have 3 histograms.

hist(d2$phq)

hist(d2$gad)

hist(d2$pswq)

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

plot(d2$phq, d2$pswq)

plot(d2$gad, d2$pswq)

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.

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

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

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

sum(d2$pswq < -3 | d2$pswq > 3)
## [1] NA

5.2 Issues with My Data

All three of my variables meet all of the assumptions of Pearson’s correlation coefficient.

6 Run a Single Correlation

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

7 View Single Correlation

corr_output
## Call:corr.test(x = d$phq, y = d2$gad)
## Correlation matrix 
##      [,1]
## [1,] 0.82
## Sample Size 
## [1] 717
## 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 
##       phq  gad pswq
## phq  1.00 0.82 0.60
## gad  0.82 1.00 0.75
## pswq 0.60 0.75 1.00
## Sample Size 
##      [,1] [,2] [,3]
## [1,]  727  717  711
## [2,]  717  735  718
## [3,]  711  718  916
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##      phq gad pswq
## phq    0   0    0
## gad    0   0    0
## pswq   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 levels of depression, levels of anxiety, and levels of worry 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, meeting the standards of normality and containing no outliers.

As predicted, we found that all three variables were significantly correlated (all ps <.001). The effect sizes of all correlations were large (rs > .50; Cohen, 1988). Additionally, levels of depression were found to be positively correlated with levels of anxiety and levels of worry, 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
phq 2.28 0.86
gad
phq 2.20 0.93 .82**
gad [.80, .85]
pswq
phq 2.69 0.76 .60** .75**
gad [.55, .65] [.71, .78]
pswq
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.