1 Loading Libraries

#install.packages("apaTables")
#install.packages("kableExtra")

library(psych) # for the describe() command and the corr.test() command
## Warning: package 'psych' was built under R version 4.4.3
library(apaTables) # to create our correlation table
## Warning: package 'apaTables' was built under R version 4.4.3
library(kableExtra) # to create our correlation table
## Warning: package 'kableExtra' was built under R version 4.4.3

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

There will be a significant relationship between Intolerance of Uncertainty, Mental Flexibility, and General Anxiety Disorder. Specifically, Mental Flexibility will be negatively related to Intolerance of Uncertainty and General Anxiety.

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':    328 obs. of  7 variables:
##  $ X                  : int  1 401 469 1390 2689 2752 2835 3935 4050 4058 ...
##  $ relationship_status: chr  "In a relationship/married and cohabiting" "Single, divorced or widowed" "In a relationship/married and cohabiting" "In a relationship/married and cohabiting" ...
##  $ income             : chr  "3 high" "3 high" "2 middle" "3 high" ...
##  $ iou                : num  3.19 2.81 2.59 1.48 3.26 ...
##  $ mfq_26             : num  4.2 4.7 4.6 2.95 4.15 3.6 5.2 3.15 4.55 3.7 ...
##  $ gad                : num  1.86 2.14 1.71 1 4 ...
##  $ edeq12             : num  1.58 3.08 1.83 1.5 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(iou, gad, 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
## iou       1 328 2.18 0.68   2.11    2.13 0.71 1.04 4.44  3.41  0.67    -0.01
## gad       2 328 1.54 0.61   1.43    1.43 0.42 1.00 4.00  3.00  1.64     2.72
## mfq_26    3 328 4.53 0.60   4.57    4.56 0.56 2.40 5.95  3.55 -0.42     0.22
##          se
## iou    0.04
## gad    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$iou)

hist(d$gad)

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$iou, d$gad)

plot(d$iou, d$mfq_26)

plot(d$gad, 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$iou <- scale(d2$iou, center=T, scale=T)
hist(d2$iou)

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

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

5.2 Issues with My Data

Zero of my variables met all of the assumptions of Pearson’s correlation coefficient. One variable, Intolerance to Uncertainty had low kurtosis (-0.01) and 1 outliers. The next variable, Generalized Anxiet disorder had high Kurtosis (1.64) and 5 outliers. The last variable, Mental Flexibility had low Kurtosis (-0.42) and 1 outlier. Outliers can distort the relationship between two variables and sway the correlation in their direction. All these variables also appears to have non-linear relationships with the other two variables. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction. All correlations should be evaluated carefully due to these risks.

6 Run a Single Correlation

corr_output <- corr.test(d2$iou, d2$gad)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$iou, y = d2$gad)
## Correlation matrix 
##      [,1]
## [1,] 0.53
## Sample Size 
## [1] 328
## 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 
##          iou   gad mfq_26
## iou     1.00  0.53  -0.51
## gad     0.53  1.00  -0.41
## mfq_26 -0.51 -0.41   1.00
## Sample Size 
## [1] 328
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##        iou gad mfq_26
## iou      0   0      0
## gad      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 Mental Flexibility, Intolerance of Uncertainty, and Generalized Anxiety Disorder 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, with both meeting the standards of normality and containing no outliers. So any significant results involving any of the variables should be evaluated carefully.

As predicted, we found that all three variables were significantly correlated (all ps < .50). The effect sizes of two correlations were strong (rs > 0.5; Cohen, 1988) and one was moderate (rs < 0.5; Cohen, 1988) Additionally, Mental Flexibility was found to be negatively related to Intolerance of Uncertainty, and negatively related to Generalized Anxiety Disorder, as predicted. 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
Intolerance to Uncertainty 2.18 0.68
Generalized Anxiety Disorder 1.54 0.61 .53**
[.45, .60]
Mental Flexibility 4.53 0.60 -.51** -.41**
[-.59, -.42] [-.49, -.31]
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.