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 there will be a significant relationship between anxiety during the pandemic, neuroticism, and perceived mental flexibility. Specifically, all three variables will be positively related.

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':    668 obs. of  7 variables:
##  $ X          : int  321 520 1422 1849 2247 2526 2609 2814 3053 3108 ...
##  $ age        : chr  "1 under 18" "1 under 18" "1 under 18" "1 under 18" ...
##  $ mhealth    : chr  "none or NA" "none or NA" "none or NA" "anxiety disorder" ...
##  $ big5_neu   : num  3.67 5.33 3.67 6 3.33 ...
##  $ pas_covid  : num  2.33 3 2.67 2.56 3 ...
##  $ isolation_c: num  1.25 1 3.5 3.5 2 2.5 1.75 1 2 1.25 ...
##  $ mfq_26     : num  4.3 2.7 2.95 2.4 4.7 4.35 4.25 4.55 4.95 4.95 ...
# 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(big5_neu,pas_covid,mfq_26))

# 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
## big5_neu     1 668 4.64 1.46   5.00    4.73 1.48 1.0   7   6.0 -0.52    -0.41
## pas_covid    2 668 3.25 0.68   3.33    3.27 0.66 1.0   5   4.0 -0.30     0.17
## mfq_26       3 668 4.23 0.66   4.25    4.24 0.67 1.8   6   4.2 -0.24     0.08
##             se
## big5_neu  0.06
## pas_covid 0.03
## mfq_26    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(d$big5_neu)

hist(d$pas_covid)

hist(d$mfq_26)

# 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(d$big5_neu,d$pas_covid)

plot(d$big5_neu,d$mfq_26)

plot(d$pas_covid,d$mfq_26)

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

sum(d2$big5_neu < -3 | d2$big5_neu > 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] 1
d2$mfq_26 <- scale(d2$mfq_26, center=T, scale=T)
hist(d2$mfq_26)

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

5.2 Issues with My Data

One of my variables meet all of the assumptions of Pearson’s correlation coefficient. Two variables, anxiety during the pandemic and mental flexibility, each had outliers (1 for pandemic anxiety and 2 for mental flexibility). Outliers can distort the relationship between two variables and sway the correlation in their direction. These variables, anxiety during the pandemic and mental flexibilty, also appears to have a non-linear relationship between each other. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction. Any correlations with fakeness should be evaluated carefully due to these risks.

6 Run a Single Correlation

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

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$big5_neu, y = d2$pas_covid)
## Correlation matrix 
##      [,1]
## [1,] 0.34
## Sample Size 
## [1] 668
## 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 
##           big5_neu pas_covid mfq_26
## big5_neu      1.00      0.34  -0.51
## pas_covid     0.34      1.00  -0.20
## mfq_26       -0.51     -0.20   1.00
## Sample Size 
## [1] 668
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           big5_neu pas_covid mfq_26
## big5_neu         0         0      0
## pas_covid        0         0      0
## mfq_26           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 neuroticism, anxiety during the pandemic, and mental flexibility would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. One of the variables (neuroticism) met the required assumptions of the test, meeting the standards of normality and containing no outliers. Two variables, anxiety during the pandemic and mental flexibility, had 1 and 2 outliers respectively, as well as non-linear relationships with the other variables; so any significant results involving anxiety during the pandemic and mental flexibility should be evaluated carefully.

As predicted, we found that all three variables were significantly correlated (all ps <.001). The effect sizes of neuroticism was strong (r > 0.51), moderate for anxiety during the pandemic (r = 0.34), and weak for mental flexibility (r = 0.2) (Cohen, 1988). Additionally, neuroticism was found to be positively related to anxiety during the pandemic, as well as anxiety during the pandemic and mental flexibility, as predicted. Conversely, neuroticism and mental flexibilty was found to be negatively related. 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
Neuroticism 4.64 1.46
Anxiety During the Pandemic 3.25 0.68 .34**
[.27, .40]
Mental Flexibility 4.23 0.66 -.51** -.20**
[-.56, -.45] [-.27, -.12]
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.