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 moa_independence (Markers of Adulthood - Importance), swb (Satisfaction with Life Scale), support (Multidimensional Scale of Perceived Social Support), and stress (Perceived Stress Questionnaire) will all be correlated with each other. Furthermore, we predict that stress will be lower in participants who are higher in satisfaction and support.

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':    2107 obs. of  6 variables:
##  $ gender          : chr  "f" "m" "m" "f" ...
##  $ age             : chr  "1 between 18 and 25" "1 between 18 and 25" "1 between 18 and 25" "1 between 18 and 25" ...
##  $ moa_independence: num  3.67 3.67 3.5 3 3.83 ...
##  $ swb             : num  4.33 4.17 1.83 5.17 3.67 ...
##  $ support         : num  6 6.75 5.17 5.58 6 ...
##  $ 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, swb, support, 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 2107 3.54 0.47   3.67    3.61 0.49 1.0 4.0   3.0 -1.49
## swb                 2 2107 4.43 1.33   4.50    4.49 1.48 1.0 7.0   6.0 -0.36
## support             3 2107 5.53 1.13   5.75    5.66 0.99 0.0 7.0   7.0 -1.10
## stress              4 2107 3.07 0.60   3.10    3.07 0.59 1.3 4.6   3.3 -0.01
##                  kurtosis   se
## moa_independence     2.75 0.01
## swb                 -0.49 0.03
## support              1.35 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(d2$moa_independence)

hist(d2$swb)

hist(d2$support)

hist(d2$stress)

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

plot(d2$moa_independence, d$support)

plot(d2$moa_independence, d$stress)

plot(d2$swb, d$support)

plot(d2$swb, d$stress)

plot(d2$support, 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] 36
d2$swb <- scale(d2$swb, center=T, scale=T)
hist(d2$swb)

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

sum(d2$support < -3 | d2$support > 3)
## [1] 27
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. The first variable, moa_independence, which measures markers of adulthood independence, had high kurtosis (2.75) and had 36 outliers. The second variable, swb, which measures levels of perceived social support, had 27 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction, so any significant results involving these variables should be evaluated carefully.

6 Run a Single Correlation

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

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$moa_independence, y = d2$swb)
## Correlation matrix 
##      [,1]
## [1,] 0.09
## Sample Size 
## [1] 2107
## 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   swb support stress
## moa_independence             1.00  0.09    0.08  -0.02
## swb                          0.09  1.00    0.47  -0.49
## support                      0.08  0.47    1.00  -0.21
## stress                      -0.02 -0.49   -0.21   1.00
## Sample Size 
## [1] 2107
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##                  moa_independence swb support stress
## moa_independence             0.00   0       0   0.48
## swb                          0.00   0       0   0.00
## support                      0.00   0       0   0.00
## stress                       0.48   0       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 moa_independence (Markers of Adulthood - Importance), swb (Satisfaction with Life Scale), support (Multidimensional Scale of Perceived Social Support), and stress (Perceived Stress Questionnaire) would be correlated with one another, 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 variables, moa_independence and swb, did have outliers, so any significant results involving these variables should be evaluated carefully.

As predicted, we found that three variables (moa_independence, swb, and support) were significantly correlated (all ps < .001). However, one variable (stress) was not significantly correlated (p = 0.48). The effect sizes of all correlations were large (rs > .5; Cohen, 1988). This test also supported our second hypothesis, that stress will be lower in participants who are higher in satisfaction and support, 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
Markers of Adulthood Independence 0.00 1.00
Satisfaction with Life -0.00 1.00 .09**
[.04, .13]
Perceived Social Support -0.00 1.00 .08** .47**
[.04, .12] [.44, .50]
Perceieved Stress 0.00 1.00 -.02 -.49** -.21**
[-.06, .03] [-.53, -.46] [-.25, -.17]
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.