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 openness (measured by the big5_open), worry (measured by the pswq), mental flexibility (measured by the mfq_26), and self-esteem (measured by the rse) will all be correlated with each other. Furthermore, we predict that self-esteem will be positively correlated with mental flexibility.

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':    1337 obs. of  6 variables:
##  $ sexual_orientation : chr  "Heterosexual/Straight" "Heterosexual/Straight" "Heterosexual/Straight" "Heterosexual/Straight" ...
##  $ relationship_status: chr  "In a relationship/married and cohabiting" "Prefer not to say" "Prefer not to say" "In a relationship/married and cohabiting" ...
##  $ big5_open          : num  5.33 5.33 5 6 5 ...
##  $ pswq               : num  4.94 3.36 1.86 3.94 2.62 ...
##  $ mfq_26             : num  4.2 3.35 4.65 4.65 4.5 4.3 5.25 5 4.7 4.05 ...
##  $ rse                : num  2.3 1.6 3.9 1.7 3.9 2.4 1.8 1.3 3.5 2.6 ...
# 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(big5_open, pswq, mfq_26, rse))

# you can use the describe() command on an entire dataframe (d) or just on a single variable (d$big5_open)
describe(d2)
##           vars    n mean   sd median trimmed  mad min max range  skew kurtosis
## big5_open    1 1337 5.23 1.12   5.33    5.31 0.99   1   7     6 -0.69     0.33
## pswq         2 1337 2.75 0.79   2.79    2.75 0.95   1   5     4  0.01    -0.77
## mfq_26       3 1337 4.28 0.70   4.35    4.31 0.67   1   6     5 -0.55     0.96
## rse          4 1337 2.61 0.72   2.70    2.62 0.74   1   4     3 -0.17    -0.72
##             se
## big5_open 0.03
## pswq      0.02
## mfq_26    0.02
## rse       0.02
# also use histograms to examine your continuous variables
hist(d2$big5_open)

hist(d2$pswq)

hist(d2$mfq_26)

hist(d2$rse)

# last, use scatterplots to examine your continuous variables together
plot(d$big5_open, d2$pswq)

plot(d$big5_open, d2$mfq_26)

plot(d$big5_open, d2$rse)

plot(d$pswq, d2$mfq_26)

plot(d$pswq, d2$rse)

plot(d$mfq_26, d2$rse)

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

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

sum(d2$pswq < -3 | d2$pswq > 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] 10
d2$rse <- scale(d2$rse, center=T, scale=T)
hist(d2$rse)

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

5.2 Issues with My Data

All but two of my variables meet all of the assumptions of Pearson’s correlation coefficient. Two variables, measure of openness (big5_open) and measure of mental flexibility (mfq) had outliers, respectively 7 and 10 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. The variable of big5_open also appears to have non-linear relationships with the other variables. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction. Any correlations with my big5_open measure of openness should be evaluated carefully due to these risks.

6 Run a Single Correlation

corr_output <- corr.test(d2$big5_open, d2$pswq)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$big5_open, y = d2$pswq)
## Correlation matrix 
##       [,1]
## [1,] -0.02
## Sample Size 
## [1] 1337
## These are the unadjusted probability values.
##   The probability values  adjusted for multiple tests are in the p.adj object. 
##      [,1]
## [1,] 0.48
## 
##  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 
##           big5_open  pswq mfq_26   rse
## big5_open      1.00 -0.02   0.31  0.08
## pswq          -0.02  1.00  -0.45 -0.52
## mfq_26         0.31 -0.45   1.00  0.59
## rse            0.08 -0.52   0.59  1.00
## Sample Size 
## [1] 1337
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           big5_open pswq mfq_26  rse
## big5_open      0.00 0.48      0 0.01
## pswq           0.48 0.00      0 0.00
## mfq_26         0.00 0.00      0 0.00
## rse            0.00 0.00      0 0.00
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

10 Write Up Results

To test our hypothesis that openness (measured by the big5_open), worry (measured by the pswq), mental flexibility (measured by the mfq_26), and self-esteem (measured by the rse) will all be correlated with each other, we calculated a series of Pearson’s correlation coefficients. Half of our data met the assumptions of the test, with all variables meeting the standards of normality and no outliers. Two variable, openness and mental flexibility, did have outliers, and openness also had non-linear relationships with the other variables, and so any significant results involving the variables should be evaluated carefully.

We found that variables of worry, mental flexibility, and self-esteem were significantly correlated (all ps < .01). Two variable, openness and worry, were not significantly correlated (ps > .01). The effect sizes of correlations among self-esteem and worry and mental flexibility were large (rs > .5; Cohen, 1988). The effect sizes of correlations among mental flexibility and openness and worry were moderate (0.49 > rs > .30; Cohen, 1988), The effect sizes of correlations among openness and worry and self-esteem were trivial (rs < .09; Cohen, 1988). This test supported our second hypothesis, that self-esteem will be positively correlated with mental flexibility, 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
Openness (big5_open) 0.00 1.00
Worry (pswq) 0.00 1.00 -.02
[-.07, .03]
Mental flexibility (mfq_26) 0.00 1.00 .31** -.45**
[.26, .35] [-.49, -.41]
Self-esteem (rse) -0.00 1.00 .08** -.52** .59**
[.03, .13] [-.56, -.48] [.55, .62]
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.