1 Loading Libraries

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

library(psych) # for the describe() command and the corr.test() command
## Warning: package 'psych' was built under R version 4.4.3
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)

# 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

We predict that levels of depression, levels of anxiety, negative effects of COVID-19 , and levels of pandemic anxiety will all be correlated with each other. Additionally, we predict that negative effects from COVID-19 will be positively correlated with levels of pandemic anxiety, such that participants who report higher levels of pandemic anxiety will report higher levels of negative effects from COVID-19.

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':    979 obs. of  7 variables:
##  $ X        : int  321 401 520 1390 1422 1849 2247 2526 2609 2689 ...
##  $ age      : chr  "1 under 18" "4 between 36 and 45" "1 under 18" "5 over 45" ...
##  $ education: chr  "1 equivalent to not completing high school" "6 graduate degree or higher" "1 equivalent to not completing high school" "5 undergraduate degree" ...
##  $ phq      : num  1.89 2.44 1.56 1.22 4 ...
##  $ gad      : num  1 2.14 1.14 1 1.57 ...
##  $ covid_neg: int  0 0 0 0 0 0 0 0 0 0 ...
##  $ pas_covid: num  2.33 4 3 2.89 2.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, covid_neg, pas_covid))

# 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
## phq          1 979 2.05 0.86   1.89    1.96 0.99   1   4     3  0.68    -0.58
## gad          2 979 1.99 0.90   1.71    1.90 0.85   1   4     3  0.75    -0.62
## covid_neg    3 979 1.04 1.76   0.00    0.68 0.00   0   8     8  1.50     1.11
## pas_covid    4 979 3.23 0.69   3.22    3.25 0.66   1   5     4 -0.20     0.11
##             se
## phq       0.03
## gad       0.03
## covid_neg 0.06
## pas_covid 0.02
# NOTE: Our fake variable has high kurtosis, which we'll ignore for the lab. 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 project manuscript.

# also use histograms to examine your continuous variables

# because we are looking at 4 variables, we will have 4 histograms. You may not have this many for your HW. Make as many as you need to reflect your hypothesis.

hist(d2$phq)

hist(d2$gad)

hist(d2$covid_neg)

hist(d2$pas_covid)

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

# because we are looking at 4 variables, we will have 6 pairings/plots. You may not have this many for your HW. Make as many as you need to reflect your hypothesis.

plot(d2$phq, d2$gad)

plot(d2$phq, d2$covid_neg)

plot(d2$phq, d2$pas_covid)

plot(d2$gad, d2$covid_neg)

plot(d2$gad, d2$pas_covid)

plot(d2$covid_neg, d2$pas_covid)

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 always check and then discuss in your write-up.

# We are going to standardize (z-score) all of our 4 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] 0
d2$gad <- scale(d2$gad, center=T, scale=T)
hist(d2$gad)

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

sum(d2$covid_neg < -3 | d2$covid_neg > 3)
## [1] 5
d2$pas_covid <- scale(d2$pas_covid, center=T, scale=T)
hist(d2$pas_covid)

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

5.2 Issues with My Data

Two of my variables meet all of the assumptions of Pearson’s correlation coefficient. The variable of negative effects from COVID-19 had 5 outliers. The variable of levels of pandemic anxiety had 1 outlier. Outliers can distort the relationship between two variables and sway the correlation in their direction. Any correlations with the measure of negative effects from COVID-19 should be evaluated carefully due to these risks.

6 Run a Single Correlation

corr_output <- corr.test(d2$pas_covid, d2$covid_neg)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$pas_covid, y = d2$covid_neg)
## Correlation matrix 
##      [,1]
## [1,] 0.19
## Sample Size 
## [1] 979
## 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

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|

Remember, Pearson’s r is also an effect size!

corr_output_m <- corr.test(d2)

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##            phq  gad covid_neg pas_covid
## phq       1.00 0.84      0.39      0.32
## gad       0.84 1.00      0.39      0.38
## covid_neg 0.39 0.39      1.00      0.19
## pas_covid 0.32 0.38      0.19      1.00
## Sample Size 
## [1] 979
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           phq gad covid_neg pas_covid
## phq         0   0         0         0
## gad         0   0         0         0
## covid_neg   0   0         0         0
## pas_covid   0   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

10 Write Up Results

To test our hypothesis that levels of depression, levels of anxiety, negative effects of COVID-19 , and levels of pandemic anxiety would be correlated with with one another, we calculated a series of Pearson’s correlation coefficients. Two of the variables (levels of depression and levels of anxiety) met the required assumptions of the test, with each meeting the standards of normality and containing no outliers. The variable of negative effects from COVID-19 had 5 outliers and the variable of pandemic anxiety had 1 outlier. Any significant results involving each of the two variables, negative effects from COVID-19 or pandemic anxiety, should be evaluated carefully.

As predicted, we found that all four variables were significantly correlated (all ps <.001). The effect sizes of all correlations ranged from small to large (rs > .19 to 1.00; Cohen, 1988). Our second hypothesis was also supported, that that negative effects from COVID-19 will be positively correlated with levels of pandemic anxiety, 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
Levels of Depression 2.05 0.86
Levels of Anxiety 1.99 0.90 .84**
[.82, .86]
Negative Effects from COVID-19 1.04 1.76 .39** .39**
[.34, .44] [.34, .45]
Levels of Pandemic Anxiety 3.23 0.69 .32** .38** .19**
[.27, .38] [.33, .43] [.13, .25]
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.