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/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 pandemic anxiety, social suppport, mental flexibility, and isolation will all be correlated with each other. Additionally, we predict that social support will be negatively correlated with pandemic anxiety, such that participants who report higher levels of social support will report lower levels of pandemic anxiety.

4 Check Your Variables

# We're going to create a fake variable for this lab, so that we have four variables. 

# NOTE: YOU WILL SKIP THIS STEP FOR THE HOMEWORK!


# 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':    280 obs. of  7 variables:
##  $ X          : int  401 1390 2689 2752 2835 3935 4050 4058 4160 4612 ...
##  $ gender     : chr  "female" "male" "female" "female" ...
##  $ age        : chr  "4 between 36 and 45" "5 over 45" "4 between 36 and 45" "5 over 45" ...
##  $ pas_covid  : num  4 2.89 5 3.56 3.56 ...
##  $ support    : num  3.83 2.83 2 3.17 1.5 ...
##  $ mfq_state  : num  5 3.5 3.12 3.88 5 ...
##  $ isolation_a: num  2.5 2.25 3.25 3.25 3.25 3 1 1 2 1.5 ...
# 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(pas_covid, support, mfq_state, isolation_a))

# 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
## pas_covid      1 280 3.19 0.70   3.22    3.20 0.66 1.33 5.0  3.67  0.01
## support        2 280 3.87 0.88   4.00    3.95 0.74 1.17 5.0  3.83 -0.78
## mfq_state      3 280 4.57 0.78   4.75    4.61 0.74 1.38 6.0  4.62 -0.72
## isolation_a    4 280 1.70 0.72   1.50    1.60 0.74 1.00 3.5  2.50  0.85
##             kurtosis   se
## pas_covid      -0.07 0.04
## support        -0.09 0.05
## mfq_state       1.08 0.05
## isolation_a    -0.40 0.04
# 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$pas_covid)

hist(d2$support)

hist(d2$mfq_state)

hist(d2$isolation_a)

# 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$pas_covid, d2$support)

plot(d2$pas_covid, d2$mfq_state)

plot(d2$pas_covid, d2$isolation_a)

plot(d2$support, d2$mfq_state)

plot(d2$support, d2$isolation_a)

plot(d2$mfq_state, d2$isolation_a)

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$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$support <- scale(d2$support, center=T, scale=T)
hist(d2$support)

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

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

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

5.2 Issues with My Data

None of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, mental flexibility, had two outliers.Another variable, social support, had 1 outlier. Outliers can distort the relationship between two variables and sway the correlation in their direction. All variables also appear to have non-linear relationships with each other. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction. Any correlations with my fake measure of these variables should be evaluated carefully due to these risks.

[Make sure to revise the above paragraph for your HW.]

6 Run a Single Correlation

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

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$support, y = d2$pas_covid)
## Correlation matrix 
##       [,1]
## [1,] -0.18
## Sample Size 
## [1] 280
## 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 
##             pas_covid support mfq_state isolation_a
## pas_covid        1.00   -0.18     -0.36        0.25
## support         -0.18    1.00      0.43       -0.61
## mfq_state       -0.36    0.43      1.00       -0.34
## isolation_a      0.25   -0.61     -0.34        1.00
## Sample Size 
## [1] 280
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##             pas_covid support mfq_state isolation_a
## pas_covid           0       0         0           0
## support             0       0         0           0
## mfq_state           0       0         0           0
## isolation_a         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 pandemic anxiety, social support, mental flexibility, and isolation would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. None of the variables met the required assumptions of the test. One variable, mental flexibility, had two outliers. Another variable, social support, had 1 outlier. As well as this, all variables had non-linear relationships with the other variables; so any significant results should be evaluated carefully.

As predicted, we found that all four variables were significantly correlated (all ps < .001). The effect size of one correlation was large (rs > .5; Cohen, 1988). The effect size of 3 correlations were medium (rs between .3 and .49; Cohen, 1988). The effect size of 2 correlations were small (rs between .1 and .29; Cohen, 1988). Our second hypothesis was also supported, that social support will be negatively correlated with pandemic anxiety, such that participants who report higher levels of social support will report lower levels of pandemic anxiety as can be seen by the correlation coefficients reported in Table 1.

[In your HW, revise the above two paragraphs to fit your results. Make sure to discuss ALL predicted correlations and whether supported or not. Always report the Pearson’s r and p-value for any prediction.]

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Pandemic Anxiety 3.19 0.70
Social Support 3.87 0.88 -.18**
[-.29, -.06]
Mental Flexbility 4.57 0.78 -.36** .43**
[-.46, -.26] [.32, .52]
Isolation 1.70 0.72 .25** -.61** -.34**
[.13, .35] [-.68, -.53] [-.44, -.23]
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.