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 markers of maturity (measured by the Markers of Adulthood Scale), support (measured by the Perceived Social Support Scale), social media use (measured by Social Media Use Scale), and stress (measured by the Perceived Stress Questionnaire) will all be correlated with each other. Furthermore, we predict that stress will be lower in participants who are higher in support or who have higher markers of maturity.

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':    3133 obs. of  6 variables:
##  $ gender      : chr  "f" "m" "m" "f" ...
##  $ sibling     : chr  "at least one sibling" "at least one sibling" "at least one sibling" "at least one sibling" ...
##  $ moa_maturity: num  3.67 3.33 3.67 3 3.67 ...
##  $ support     : num  6 6.75 5.17 5.58 6 ...
##  $ socmeduse   : int  47 23 34 35 37 13 37 43 37 29 ...
##  $ 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_maturity, support, socmeduse, 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_maturity    1 3133  3.59 0.43   3.67    3.65 0.49  1.0  4.0   3.0 -1.20
## support         2 3133  5.54 1.13   5.75    5.66 0.99  0.0  7.0   7.0 -1.10
## socmeduse       3 3133 34.48 8.56  35.00   34.75 7.41 11.0 55.0  44.0 -0.31
## stress          4 3133  3.05 0.60   3.00    3.05 0.59  1.3  4.7   3.4  0.03
##              kurtosis   se
## moa_maturity     1.87 0.01
## support          1.45 0.02
## socmeduse        0.26 0.15
## stress          -0.17 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_maturity)

hist(d2$support)

hist(d2$socmeduse)

hist(d2$stress)

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

plot(d$moa_maturity, d$socmeduse)

plot(d$moa_maturity, d$stress)

plot(d$support, d$socmeduse)

plot(d$support, d$stress)

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

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

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

sum(d2$socmeduse < -3 | d2$socmeduse > 3)
## [1] 0
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. One variable, maturity (measured by the Markers of Adulthood Scale) had 22 outliers. The other variable, support (measured by the Perceived Social Support Scale) had 43 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction. Any correlations with my maturity and support measures should be evaluated carefully due to these risks.

6 Run a Single Correlation

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

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$moa_maturity, y = d2$support)
## Correlation matrix 
##      [,1]
## [1,] 0.11
## Sample Size 
## [1] 3133
## 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_maturity support socmeduse stress
## moa_maturity         1.00    0.11      0.09  -0.05
## support              0.11    1.00      0.21  -0.21
## socmeduse            0.09    0.21      1.00   0.10
## stress              -0.05   -0.21      0.10   1.00
## Sample Size 
## [1] 3133
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##              moa_maturity support socmeduse stress
## moa_maturity            0       0         0      0
## support                 0       0         0      0
## socmeduse               0       0         0      0
## stress                  0       0         0      0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

10 Write Up Results

To test our hypothesis that markers of maturity (measured by the Markers of Adulthood Scale), support (measured by the Perceived Social Support Scale), social media use (measured by Social Media Use Scale), and stress (measured by the Perceived Stress Questionnaire) will all be correlated with each other, we calculated a series of Pearson’s correlation coefficients. Most of our data met the assumptions of the test, with all variables meeting the standards of normality and two variables not containing outliers. Two variables, maturity and support, did have outliers and non-linear relationships with the other variables, and so any significant results involving those variables should be evaluated carefully.

Contrary to as we predicted, we found that all three variables were significantly correlated (all ps < .05). The effect sizes of all correlations were weak or even trivial (rs < 0.29, some rs < 0.10; Cohen, 1988). This test supported our second hypothesis, that stress will be lower in participants who are higher in support or who have higher markers of maturity, 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
Maturity 0.00 1.00
Support 0.00 1.00 .11**
[.07, .14]
Social Media Use -0.00 1.00 .09** .21**
[.06, .13] [.18, .25]
Stress -0.00 1.00 -.05** -.21** .10**
[-.09, -.02] [-.24, -.18] [.06, .13]
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.