1 Loading Libraries

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

# import the dataset you cleaned previously
# this will be the dataset you'll use throughout the rest of the semester
# use ARC data downloaded previous for lab
d <- read.csv(file="Data/mydataa.csv", header=T)

3 State Your Hypothesis

We predict that stress (measured by the PSS-4), pandemic anxiety (measured by the pandemic anxiety scale), self esteem (measured by the RSE-10), and general anxiety (measured by the general anxiety scale) will all be correlated with each other. Furthermore, we predict that self-esteem will be lower in participants who are higher in stress or who report more symptoms of anxiety. We predict that self esteem will be negatively correlated with stress and anxiety.

4 Check Your Variables

# you only need to check the variables you're using in the current analysis
# although you checked them previously, it's always a good idea to look them over again and be sure that everything is correct
str(d)
## 'data.frame':    364 obs. of  6 variables:
##  $ pet      : chr  "cat" "no pets" "multiple types of pet" "cat" ...
##  $ income   : chr  "3 high" "2 middle" "2 middle" "2 middle" ...
##  $ pas_covid: num  3.22 4.22 3.22 3.56 4.56 ...
##  $ pss      : num  3.25 3.25 2 2 4 2.5 2 2.25 2.75 2.25 ...
##  $ gad      : num  1.86 2 1.43 1.57 2.86 ...
##  $ rse      : num  2.3 1.7 3.9 2.4 1.8 2.6 3.5 2.6 2.4 4 ...
# we're going to create a fake variable for this lab, so that it has four variables and mirrors the homework assignment. SKIP THIS STEP FOR THE HOMEWORK


# since we're focusing on our continuous variables, we're going to subset them into their own dataframe. this will make some stuff we're doing later easier.
d2 <- subset(d, select=c(pss, gad,rse,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
## pss          1 364 2.39 0.72   2.25    2.37 0.74 1.00 4.5  3.50  0.34    -0.05
## gad          2 364 1.55 0.60   1.43    1.44 0.42 1.00 4.0  3.00  1.55     2.40
## rse          3 364 3.04 0.51   3.05    3.06 0.52 1.40 4.0  2.60 -0.36    -0.02
## pas_covid    4 364 3.21 0.69   3.22    3.21 0.66 1.33 5.0  3.67  0.05     0.03
##             se
## pss       0.04
## gad       0.03
## rse       0.03
## pas_covid 0.04
# our fake variable has high kurtosis, which I'll ignore. 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 manuscript

# also use histograms to examine your continuous variables
hist(d2$pss)

hist(d2$pas_covid)

hist(d2$rse)

hist(d2$gad)

# last, use scatterplots to examine your continuous variables together
plot(d$pss, d$pas_covid)

plot(d$pss, d$rse)

plot(d$pss, d$gad)

plot(d$pas_covid, d$rse)

plot(d$pas_covid, d$gad)

plot(d$rse, d$gad)

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

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

sum(d2$pss < -3 |d2$pss > 3)
## [1] 0
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] 0
d2$rse <- scale(d2$rse, center=T, scale=T)
hist(d2$rse)

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

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

5.2 Issues with My Data

All of my variables meet all of the assumptions of Pearson’s correlation coefficient. Outliers can distort the relationship between two variables and sway the correlation in their direction. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction.

6 Run a Single Correlation

corr_output <- corr.test(d2$pss, d2$pas_covid)
corr_output <- corr.test(d2$pss, d2$rse)
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.64
## Sample Size 
## [1] 364
## 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|

corr_output_m <- corr.test(d2)

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##             pss   gad   rse pas_covid
## pss        1.00  0.64 -0.54      0.43
## gad        0.64  1.00 -0.52      0.45
## rse       -0.54 -0.52  1.00     -0.29
## pas_covid  0.43  0.45 -0.29      1.00
## Sample Size 
## [1] 364
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           pss gad rse pas_covid
## pss         0   0   0         0
## gad         0   0   0         0
## rse         0   0   0         0
## pas_covid   0   0   0         0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

10 Write Up Results

To test our hypothesis that stress (measured by the PSS-4), general anxiety (measured by the general anxiety scale), self-esteem (measured by the RSE-10), and pandemic anxiety (measured by the pandemic anxiety scale) would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Most of our data met the assumptions of the test, with all variables meeting the standards of normality and 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 > .5; Cohen, 1988). This test also supported our second hypothesis, that self-esteem would be lower in participants who are higher in stress or who report high levels of 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
Pandemic Anxiety (Pas_covid-4) -0.00 1.00
Percieved stress scale (pss-9) 0.00 1.00 .64**
[.57, .69]
General Anxiety scale (gad-10) 0.00 1.00 -.54** -.52**
[-.61, -.46] [-.59, -.44]
Self Esteem (rse-3) 0.00 1.00 .43** .45** -.29**
[.35, .51] [.37, .53] [-.38, -.19]
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.