1 Loading Libraries

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

# 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 intolerance of uncertainty symptoms (measured by the iou), mental flexibility trait symptoms (measured by the mfq_26), mental flexibility state symptoms (measured by the mfq_state), and disordered eating symptoms (measured by the edeq12) will all be correlated with each other. Furthermore, we predict that intolerance of uncertainty will be lower in participants who are lower in mental flexibility trait symptoms or who report lower symptoms of mental flexibility states. We predict that disordered eating symptoms will be positively correlated with intolerance of uncertainty and negatively correlated with mental flexibility trait symptoms.

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':    1030 obs. of  6 variables:
##  $ iou      : num  3.19 4 1.59 3.37 1.7 ...
##  $ mfq_26   : num  4.2 3.35 4.65 4.65 4.5 4.3 5.25 4.45 4.7 4.05 ...
##  $ mfq_state: num  3.62 3 5.88 4 4.62 ...
##  $ edeq12   : num  1.58 1.83 1 1.67 1.42 ...
##  $ mhealth  : chr  "none or NA" "anxiety disorder" "none or NA" "none or NA" ...
##  $ treatment: chr  "no psychological disorders" "in treatment" "not in treatment" "no psychological disorders" ...
# 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

# 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(iou, mfq_26, mfq_state, edeq12))

# 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 1030 2.60 0.91   2.44    2.54 0.99 1.0   5   4.0  0.45    -0.66
## mfq_26       2 1030 4.30 0.67   4.35    4.31 0.67 1.8   6   4.2 -0.29     0.10
## mfq_state    3 1030 4.07 1.01   4.12    4.12 0.93 1.0   6   5.0 -0.51     0.08
## edeq12       4 1030 1.90 0.74   1.75    1.83 0.74 1.0   4   3.0  0.66    -0.58
##             se
## iou       0.03
## mfq_26    0.02
## mfq_state 0.03
## edeq12    0.02
# 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$iou)

hist(d2$mfq_26)

hist(d2$mfq_state)

hist(d2$edeq12)

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

plot(d2$iou, d2$mfq_state)

plot(d2$iou, d2$edeq12)

plot(d2$mfq_26, d2$mfq_state)

plot(d2$mfq_26, d2$edeq12)

plot(d2$mfq_state, d2$edeq12)

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.

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

sum(d2$iou< -3 | d2$iou > 3)
## [1] 0
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] 3
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] 4
d2$edeq12 <- scale(d2$edeq12, center=T, scale=T)
hist(d2$edeq12)

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

5.2 Issues with My Data

All of my variables meet all of the assumptions of Pearson’s correlation coefficient. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction.

6 Run a Single Correlation

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

7 View Single Correlation

#p can never = 0, instead it can be written p<0.01

corr_output
## Call:corr.test(x = d2$iou, y = d2$mfq_26)
## Correlation matrix 
##      [,1]
## [1,] -0.6
## Sample Size 
## [1] 1030
## 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|

corr_output_m <- corr.test(d2)

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##             iou mfq_26 mfq_state edeq12
## iou        1.00  -0.60     -0.63   0.49
## mfq_26    -0.60   1.00      0.76  -0.29
## mfq_state -0.63   0.76      1.00  -0.35
## edeq12     0.49  -0.29     -0.35   1.00
## Sample Size 
## [1] 1030
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           iou mfq_26 mfq_state edeq12
## iou         0      0         0      0
## mfq_26      0      0         0      0
## mfq_state   0      0         0      0
## edeq12      0      0         0      0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

10 Write Up Results

#A brief write-up summarizing the hypothesis, any issues with the data, and the results are reported. A table with the correlation test results is also provided in the write-up. Effect sizes are discussed if relevant (i.e., if results are significant). To test our hypothesis that intolerance of uncertainty symptoms (measured by the iou), mental flexibility trait symptoms (measured by the mfq_26), mental flexibility state symptoms (measured by the mfq_state), and disordered eating symptoms (measured by the edeq12) will all be correlated with each other. All of our data met the assumptions of the test, with all variables meeting the standards of normality and no outliers.

As predicted, we found that all four variables were significantly correlated (all ps < .001). The effect sizes between iou and mfq_26, mfq_state, and between mfq_26 and mfq_state were large (rs > .5; Cohen, 1988). The effect sizes between iou and edeq12, and between mfq_state and edeq12 were moderate(rs >0.29, rs <0.49; Cohen, 1988). The effect size of mfq_26 and edeq12 was weak (rs = 0.29; Cohen 1988) This test also supported our second hypothesis, that intolerance of uncertainty will be lower in participants who are lower in mental flexibility trait symptoms or who report lower symptoms of mental flexibility states, and our third hypothesis that disordered eating symptoms will be positively correlated with intolerance of uncertainty and negatively correlated with mental flexibility trait symptoms, we calculated a series of Pearson’s correlation coefficients, as can be seen by the correlation coefficients reported in Table 1.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Intolerance of Uncertainty (iou) 0.00 1.00
Mental flexibility traits (mfq_12) -0.00 1.00 -.60**
[-.63, -.55]
Mental flexibility state (mfq_state) -0.00 1.00 -.63** .76**
[-.66, -.59] [.74, .79]
Disordered eating symptoms (edeq12) -0.00 1.00 .49** -.29** -.35**
[.45, .54] [-.34, -.23] [-.40, -.29]
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.