1 Loading Libraries

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

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

3 State Your Hypothesis

We predict that anxiety (as measured by pas_covid), anxiety symptoms (as measured by gad), depression symptoms (as measured by the phq), and mental well-being (as measured by the swemws) will all be correlated with each other.

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':    912 obs. of  7 variables:
##  $ X        : int  20 30 31 33 57 58 81 104 113 117 ...
##  $ age      : chr  "1 under 18" "1 under 18" "4 between 36 and 45" "4 between 36 and 45" ...
##  $ mhealth  : chr  "anxiety disorder" "none or NA" "none or NA" "none or NA" ...
##  $ pas_covid: num  4.56 3.33 4.22 3.22 4.56 ...
##  $ phq      : num  3.33 1 2.33 1.11 2.33 ...
##  $ gad      : num  3.86 1.14 2 1.43 2.86 ...
##  $ swemws   : num  2.29 4.29 3.29 4 3.29 ...
# 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(delete this chunk for HW)


# 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(pas_covid,gad,phq,swemws))

# you can use the describe() command on an entire dataframe (d) or just on a single variable (d$pas_covid)
describe(d2)
##           vars   n mean   sd median trimmed  mad min max range  skew kurtosis
## pas_covid    1 912 3.22 0.68   3.22    3.24 0.66   1   5     4 -0.19     0.13
## gad          2 912 1.98 0.90   1.71    1.88 0.85   1   4     3  0.75    -0.61
## phq          3 912 2.04 0.86   1.89    1.96 0.99   1   4     3  0.68    -0.59
## swemws       4 912 3.18 0.83   3.29    3.20 0.85   1   5     4 -0.20    -0.36
##             se
## pas_covid 0.02
## gad       0.03
## phq       0.03
## swemws    0.03
# 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$pas_covid)

hist(d2$gad)

hist(d2$phq)

hist(d2$swemws)

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

plot(d2$pas_covid, d2$phq)

plot(d2$pas_covid, d2$swemws)

plot(d2$gad, d2$phq)

plot(d2$gad, d2$swemws)

plot(d2$phq, d2$swemws)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have one measurement for each score for each participant

In our Data Prep and Basic Stats lab, we dropped any participants with missing data. So we’re good for this assumption!

  • Variables should be continuous and normally distributed

Checked in the section above!

  • Relationship between the variables should be linear

This one is a bit tricky! We’ll talk about it in class; feel free to take notes here.

look at the scatterplots for HW and use own assumptions, usually will be linear

  • Outliers should be identified and removed

We’ll do this one below.

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.(beyond +3 or -3)

d$pas_covid_std <- scale(d$pas_covid, center=T, scale=T)
hist(d$pas_covid_std)

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

sum(d$gad_std < -3 | d$gad_std > 3)
## [1] 0
d$phq_std <- scale(d$phq, center=T, scale=T)
hist(d$phq_std)

sum(d$phq_std < -3 | d$phq_std > 3)
## [1] 0
d$swemws_std <- scale(d$swemws, center=T, scale=T)
hist(d$swemws_std)

sum(d$swemws_std < -3 | d$swemws_std > 3)
## [1] 0

5.2 Issues with My Data

All but one of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, a measure of anxiety (pas_covid) had 1 outlier. Outliers can distort the relationship between two variables and sway the correlation in their direction.

6 Create a Correlation Matrix

corr_output_m <- corr.test(d2)

7 View Test Output

effect size (r) cutoffs: <.1 = trivial; <.3 = small; <.5 = medium; >.5 = large

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##           pas_covid   gad   phq swemws
## pas_covid      1.00  0.37  0.32  -0.28
## gad            0.37  1.00  0.84  -0.72
## phq            0.32  0.84  1.00  -0.76
## swemws        -0.28 -0.72 -0.76   1.00
## Sample Size 
## [1] 912
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           pas_covid gad phq swemws
## pas_covid         0   0   0      0
## gad               0   0   0      0
## phq               0   0   0      0
## swemws            0   0   0      0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

8 Write Up Results

To test our hypothesis that anxiety (measured by pas_covid), anxiety symptoms (measured by gad), depression symptoms (measured by the phq), and mental well-being (measured by the swemws) 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. One variable, anxiety (pas_covid), did have an outlier, so any significant results involving that variable should be evaluated carefully.

As predicted, we found that all four variables were significantly correlated (all ps < .001). The effect sizes ranged throughout the results. Pas_covid had a large effect size (rs > .5; Cohen, 1988), but pas_covid and gad, phq had a medium effect size (rs <.5; Cohen, 1988) and pas_covid and swemws had a trivial effect size (rs <.1; Cohen, 1988). gad alone, and gad and phq had a large effect size (rs > .5; Cohen, 1988), but gad and swemws had a trivial effect size (rs <.1; Cohen, 1988). phq had a large effect size alone (rs > .5; Cohen, 1988), but phq and swemws had a trivial effect size (rs <.1; Cohen, 1988). Swemws had a large effect size alone (rs > .5; Cohen, 1988), but swemws and gad, phq, and pas_covid had a trivial effect size (rs <.1; Cohen, 1988).

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
anxiety (pas_covid) 3.22 0.68
anxiety symptoms (gad) 1.98 0.90 .37**
[.32, .43]
depression symptoms (phq) 2.04 0.86 .32** .84**
[.26, .38] [.82, .86]
mental well-being (swemws) 3.18 0.83 -.28** -.72** -.76**
[-.34, -.22] [-.75, -.69] [-.78, -.73]
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.