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 maturity (measured by the Maturity Scale), period of emerging adulthood (measured by the Inventory of the Dimensions of Emerging Adulthood), belongingness (measured by the Belong Scale), and social media use (measured by the Social Media Use Scale) will all be correlated with each other. Furthermore, we predict that the emergence of adulthood will be lower in participants who are higher in 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':    3127 obs. of  6 variables:
##  $ gender      : chr  "f" "m" "m" "f" ...
##  $ race_rc     : chr  "white" "white" "white" "other" ...
##  $ moa_maturity: num  3.67 3.33 3.67 3 3.67 ...
##  $ idea        : num  3.75 3.88 3.75 3.75 3.5 ...
##  $ belong      : num  2.8 4.2 3.6 4 3.4 4.2 3.9 3.6 2.9 2.5 ...
##  $ socmeduse   : int  47 23 34 35 37 13 37 43 37 29 ...
# 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,idea,belong,socmeduse))

# you can use the describe() command on an entire dataframe (d) or just on a single variable (d$moa_maturity)
describe(d2)
##              vars    n  mean   sd median trimmed  mad  min max range  skew
## moa_maturity    1 3127  3.59 0.43   3.67    3.65 0.49  1.0   4   3.0 -1.20
## idea            2 3127  3.57 0.38   3.62    3.62 0.37  1.0   4   3.0 -1.49
## belong          3 3127  3.23 0.61   3.30    3.25 0.59  1.3   5   3.7 -0.26
## socmeduse       4 3127 34.48 8.57  35.00   34.75 7.41 11.0  55  44.0 -0.30
##              kurtosis   se
## moa_maturity     1.87 0.01
## idea             4.22 0.01
## belong          -0.12 0.01
## socmeduse        0.26 0.15
# our socmeduse 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$idea)

hist(d2$belong)

hist(d2$socmeduse)

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

plot(d$moa_maturity, d$belong)

plot(d$moa_maturity, d$socmeduse)

plot(d$idea, d$belong)

plot(d$idea, d$socmeduse)

plot(d$belong, d$socmeduse)

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

sum(d2$idea < -3 | d2$idea > 3)
## [1] 33
d2$belong <- scale(d2$belong, center=T, scale=T)
hist(d2$belong)

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

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

6 Run a Single Correlation

corr_output <- corr.test(d2$moa_maturity, d2$idea)
corr_output <- corr.test(d2$moa_maturity, d2$belong)
corr_output <- corr.test(d2$moa_maturity, d2$socmeduse)
corr_output <- corr.test(d2$idea, d2$belong)
corr_output <- corr.test(d2$idea, d2$socmeduse)
corr_output <- corr.test(d2$belong, d2$socmeduse)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$belong, y = d2$socmeduse)
## Correlation matrix 
##      [,1]
## [1,] 0.28
## Sample Size 
## [1] 3127
## 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 idea belong socmeduse
## moa_maturity         1.00 0.15   0.00      0.09
## idea                 0.15 1.00   0.22      0.23
## belong               0.00 0.22   1.00      0.28
## socmeduse            0.09 0.23   0.28      1.00
## Sample Size 
## [1] 3127
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##              moa_maturity idea belong socmeduse
## moa_maturity         0.00    0   0.98         0
## idea                 0.00    0   0.00         0
## belong               0.98    0   0.00         0
## socmeduse            0.00    0   0.00         0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

10 Write Up Results

To test our hypothesis that maturity (measured by the Maturity Scale), period of emerging adulthood (measured by the Inventory of the Dimensions of Emerging Adulthood), belongingness (measured by the Belong Scale), and social media use (measured by the Social Media Use Scale) would be correlated with one another, 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 no outliers.

As predicted, we found that all four variables were significantly correlated (all ps < .001). The effect sizes of all correlations were large (rs > .5; Cohen, 1988). This test also supported our second hypothesis, that self-esteem would be lower in participants who are higher in stress or who report more symptoms of depression, 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 (moa_maturity) -0.00 1.00
Emergence of Adulthood (idea) 0.00 1.00 .15**
[.11, .18]
Belongingness (belong) -0.00 1.00 -.00 .22**
[-.04, .03] [.19, .25]
Social Media Use (socmeduse) -0.00 1.00 .09** .23** .28**
[.06, .13] [.19, .26] [.25, .31]
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.