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 Extroversion, Pandemic Anxiety Scale, Mental Flexibility Questionnaire (State), and Brief Resilience Scale will all be correlated with each other. Additionally, we predict that Mental Flexibility Scale (State) will be positively correlated with brief resilience scale, such that participants who report higher levels of Mental Flexibility Scale (State) will report higher levels of resilience on the Brief Resilience Scale.

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':    316 obs. of  7 variables:
##  $ X        : int  6291 6294 6312 6326 6331 6335 6348 6350 6357 6359 ...
##  $ mhealth  : chr  "none or NA" "depression" "anxiety disorder" "none or NA" ...
##  $ age      : chr  "1 under 18" "1 under 18" "1 under 18" "2 between 18 and 25" ...
##  $ big5_ext : num  3 5.67 3.33 2.67 2.33 ...
##  $ pas_covid: num  2.33 3.11 3.78 2.56 3.89 ...
##  $ mfq_state: num  4 4 3.12 3.12 3.88 ...
##  $ brs      : num  4 2.5 2.33 2 2.83 ...
# 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!



# 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_ext, pas_covid, mfq_state, brs))

# 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_ext     1 316 3.94 1.44   4.00    3.93 1.48 1.00   7  6.00  0.00    -0.77
## pas_covid    2 316 3.35 0.65   3.44    3.36 0.66 1.00   5  4.00 -0.32     0.58
## mfq_state    3 316 3.74 0.99   3.88    3.77 1.11 1.12   6  4.88 -0.27    -0.40
## brs          4 316 2.70 0.87   2.67    2.70 0.99 1.00   5  4.00  0.10    -0.66
##             se
## big5_ext  0.08
## pas_covid 0.04
## mfq_state 0.06
## brs       0.05
# 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

hist(d$big5_ext)

hist(d$pas_covid)

hist(d$mfq_state)

hist(d$brs)

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

plot(d$big5_ext, d$pas_covid)

plot(d$big5_ext, d$mfq_state)

plot(d$big5_ext, d$brs)

plot(d$pas_covid, d$mfq_state)

plot(d$pas_covid, d$brs)

plot(d$mfq_state, d$brs)

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.

# We are going to standardize (z-score) all of our variables, and check them for outliers.

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

sum(d2$big5_ext < -3 | d2$big5_ext > 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] 2
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] 0
d2$brs <- scale(d2$brs, center=T, scale=T)
hist(d2$brs)

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

5.2 Issues with My Data

Three of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, a measure of mental flexibility questionnaire (state) had normal univariate normality and 2 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. This variable, mental flexibility questionnaire (state), also appears to have non-linear relationships with the other three variables. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction.

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

6 Run a Single Correlation

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

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$big5_ext, y = d2$pas_covid)
## Correlation matrix 
##       [,1]
## [1,] -0.09
## Sample Size 
## [1] 316
## These are the unadjusted probability values.
##   The probability values  adjusted for multiple tests are in the p.adj object. 
##      [,1]
## [1,] 0.11
## 
##  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 
##           big5_ext pas_covid mfq_state   brs
## big5_ext      1.00     -0.09      0.31  0.36
## pas_covid    -0.09      1.00     -0.18 -0.32
## mfq_state     0.31     -0.18      1.00  0.68
## brs           0.36     -0.32      0.68  1.00
## Sample Size 
## [1] 316
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           big5_ext pas_covid mfq_state brs
## big5_ext      0.00      0.11         0   0
## pas_covid     0.11      0.00         0   0
## mfq_state     0.00      0.00         0   0
## brs           0.00      0.00         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 extroversion, pandemic anxiety scale, mental flexibility questionnaire (state), and brief resilience scale would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Three of the variables (extroversion, mental flexibility questionnaire (state), and brief resilience scale) met the required assumptions of the test, with all three meeting the standards of normality and containing no outliers. One variable, pandemic anxiety scale, had 2 outliers as well as non-linear relationships with the other variables; so any significant results involving pandemic anxiety scale should be evaluated carefully.

Our prediction was not correct, we found that only two variables were significantly correlated (ps < .001). These variables were the Mental Flexibility Questionnaire (State) and the Brief Resilience Scale where the resulted p-values were significantly correlated (ps < .001). The pair of variables that were not correlated were extroversion and the pandemic anxiety scale where the p-value was 0.11. The effect sizes of the correlations were spread out. Extroversion and the Pandemic Anxiety Scale had a trivial correlation of |0.09|). Extroversion and Mental Flexibility Questionnaire (State) had a moderate correlation of 0.31. Extroversion and Brief Resilience Scale had a moderate correlation of 0.36. Pandemic Anxiety Scale and Mental Flexibility Questionnaire (State) had a weak correlation of |0.18|. Pandemic Anxiety Scale and Brief Resiliency Scale had a moderate correlation of |0.32|. Mental Flexibility Scale (State) and Brief Resilience Scale had a strong correlation of 0.68 (rs > .5; Cohen, 1988). Our second hypothesis was supported, that reporting higher levels on the Mental Flexibility Scale (State) would result in participants who reported higher levels of resilience on the Brief Resilience Scale, 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 if sig or not.]

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Extroversion 3.94 1.44
Pandemic Anxiety Scale 3.35 0.65 -.09
[-.20, .02]
Mental Flexibility Questionnaire (State) 3.74 0.99 .31** -.18**
[.20, .40] [-.29, -.07]
Brief Resilience Scale 2.70 0.87 .36** -.32** .68**
[.26, .45] [-.41, -.21] [.62, .74]
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.