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

I predict that independence, maturity, mindfulness, stress will all be correlated with each other. Furthermore, I predict that stress and mindfulness will be negatively correlated.

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':    3069 obs. of  6 variables:
##  $ edu             : chr  "2 Currently in college" "5 Completed Bachelors Degree" "2 Currently in college" "2 Currently in college" ...
##  $ marriage5       : chr  "are currently divorced from one another" "are currently married to one another" "are currently married to one another" "are currently married to one another" ...
##  $ moa_independence: num  3.67 3.67 3.5 3 3.83 ...
##  $ moa_maturity    : num  3.67 3.33 3.67 3 3.67 ...
##  $ mindful         : num  2.4 1.8 2.2 2.2 3.2 ...
##  $ stress          : num  3.3 3.3 4 3.2 3.1 3.5 3.3 2.4 2.9 2.7 ...
# 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(moa_independence, moa_maturity, mindful,stress))

# 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
## moa_independence    1 3069 3.54 0.46   3.67    3.61 0.49 1.00 4.0  3.00 -1.44
## moa_maturity        2 3069 3.59 0.43   3.67    3.65 0.49 1.00 4.0  3.00 -1.20
## mindful             3 3069 3.71 0.84   3.73    3.71 0.79 1.13 6.0  4.87 -0.06
## stress              4 3069 3.05 0.60   3.00    3.05 0.59 1.30 4.7  3.40  0.04
##                  kurtosis   se
## moa_independence     2.52 0.01
## moa_maturity         1.87 0.01
## mindful             -0.13 0.02
## stress              -0.16 0.01
# 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(d$moa_independence)

hist(d$moa_maturity)

hist(d$mindful)

hist(d$stress)

# last, use scatterplots to examine your continuous variables together
plot(d$moa_independence, d$moa_maturity)

plot(d$moa_independence, d$mindful)

plot(d$moa_independence, d$stress)

plot(d$moa_maturity, d$mindful)

plot(d$moa_maturity, d$stress)

plot(d$mindful, d$stress)

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

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

sum(d2$moa_maturity < -3 | d2$maturity > 3)
## [1] 0
d2$mindful <- scale(d2$mindful, center=T, scale=T)
hist(d2$mindful)

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

sum(d2$stress < -3 | d2$stress > 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, with the exception of a third having a nonlinear relationship. One variable, independence, had high kurtosis (2.52) and had 50 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. This variable 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 independence should be evaluated carefully due to these risks.

6 Run a Single Correlation

corr_output <- corr.test(d2$moa_independence, d2$moa_maturity)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$moa_independence, y = d2$moa_maturity)
## Correlation matrix 
##      [,1]
## [1,] 0.39
## Sample Size 
## [1] 3069
## 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 
##                  moa_independence moa_maturity mindful stress
## moa_independence             1.00         0.39    0.02  -0.02
## moa_maturity                 0.39         1.00    0.05  -0.06
## mindful                      0.02         0.05    1.00  -0.40
## stress                      -0.02        -0.06   -0.40   1.00
## Sample Size 
## [1] 3069
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##                  moa_independence moa_maturity mindful stress
## moa_independence             0.00            0    0.43   0.43
## moa_maturity                 0.00            0    0.01   0.01
## mindful                      0.30            0    0.00   0.00
## stress                       0.21            0    0.00   0.00
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

10 Write Up Results

To test my hypothesis that independence, maturity, mindfulness, and stress would be correlated with one another, I calculated a series of Pearson’s correlation coefficients. Some of my data met the assumptions of the test. One variable, independence, did have outliers and non-linear relationships with the other variables, two others had nonlinear relationships with one or more variable, and so any significant results involving those variables should be evaluated carefully.

As predicted, we found that three variables were significantly correlated (all ps < .01). The effect sizes of 2 correlations were moderate (rs > .5; Cohen, 1988). This test supported our second hypothesis, that stress will be higher in participants who are less mindful 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
moa_independence -0.00 1.00
moa_maturity -0.00 1.00 .39**
[.36, .42]
mindful 0.00 1.00 .02 .05**
[-.02, .05] [.02, .09]
stress 0.00 1.00 -.02 -.06** -.40**
[-.06, .01] [-.09, -.02] [-.43, -.37]
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.