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/eammi2_new_final.csv", header=T)

3 State Your Hypothesis

I predict that mindfulness (measured by mindful), social media use (measured by socmeduse), satisfaction with life (measured by swb), and dimensions of emerging adulthood (measured by idea) will all be correlated with each other.

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':    2156 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" ...
##  $ idea     : num  3.75 3.88 3.75 3.75 3.5 ...
##  $ swb      : num  4.33 4.17 1.83 5.17 3.67 ...
##  $ mindful  : num  2.4 1.8 2.2 2.2 3.2 ...
##  $ 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(idea,swb,mindful,socmeduse))

# 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
## idea         1 2156  3.57 0.39   3.62    3.61 0.37  1.00   4  3.00 -1.49
## swb          2 2156  4.43 1.33   4.50    4.49 1.48  1.00   7  6.00 -0.35
## mindful      3 2156  3.72 0.84   3.73    3.72 0.79  1.13   6  4.87 -0.04
## socmeduse    4 2156 34.27 8.58  35.00   34.53 7.41 11.00  55 44.00 -0.30
##           kurtosis   se
## idea          3.96 0.01
## swb          -0.49 0.03
## mindful      -0.15 0.02
## socmeduse     0.19 0.18
# 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$idea)

hist(d2$swb)

hist(d2$mindful)

hist(d2$socmeduse)

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

plot(d2$idea, d2$mindful)

plot(d2$idea, d2$socmeduse)

plot(d2$swb, d2$mindful)

plot(d2$swb, d2$socmeduse)

plot(d2$mindful, d2$socmeduse)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have one measurement for each score for each participant

In our Data Prep and Basic Stats lab, we dropped any participants with missing data. So we’re good for this assumption!

  • Variables should be continuous and normally distributed

Checked in the section above!

  • Relationship between the variables should be linear

This one is a bit tricky! We’ll talk about it in class; feel free to take notes here. look at the scatterplots and use your own assumptions but most likely will be linear

  • Outliers should be identified and removed

We’ll do this one below.

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.

d$idea_std <- scale(d$idea, center=T, scale=T)
hist(d$idea_std)

sum(d$idea_std < -3 | d$idea_std > 3)
## [1] 26
d$swb_std <- scale(d$swb, center=T, scale=T)
hist(d$swb_std)

sum(d$swb_std < -3 | d$swb_std > 3)
## [1] 0
d$mindful_std <- scale(d$mindful, center=T, scale=T)
hist(d$mindful_std)

sum(d$mindful_std < -3 | d$mindful_std > 3)
## [1] 1
d$socmeduse_std <- scale(d$socmeduse, center=T, scale=T)
hist(d$socmeduse_std)

sum(d$socmeduse_std < -3 | d$socmeduse_std > 3)
## [1] 0

5.2 Issues with My Data

All but one of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, the dimensions of emerging adulthood had high kurtosis (3.96) and had 26 outliers. I only found 1 other outlier in my mindfulness variable. Outliers can distort the relationship between two variables and sway the correlation in their direction. However, this variable does not appear to have non-linear relationships with the other variables. Still, any correlations with my dimensions of emerging adulthood should be evaluated carefully due to these risks.

6 Create a Correlation Matrix

corr_output_m <- corr.test(d2)

7 View Test Output

effect size (r) cutoffs: < .1 = trivial; < .3 = small; < .5 = medium; > .5 = large

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##            idea   swb mindful socmeduse
## idea       1.00 -0.01   -0.13      0.22
## swb       -0.01  1.00    0.29      0.09
## mindful   -0.13  0.29    1.00     -0.12
## socmeduse  0.22  0.09   -0.12      1.00
## Sample Size 
## [1] 2156
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           idea  swb mindful socmeduse
## idea      0.00 0.63       0         0
## swb       0.63 0.00       0         0
## mindful   0.00 0.00       0         0
## socmeduse 0.00 0.00       0         0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

8 Write Up Results

To test my hypothesis that mindfulness (measured by mindful), social media use (measured by socmeduse), satisfaction with life (measured by swb), and dimensions of emerging adulthood (measured by idea) would be correlated with one another, I 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. One variable, dimensions of emerging adulthood, did have outliers, and so any significant results involving that variable should be evaluated carefully.

I found that all of the four variables were significantly correlated (all ps < .001), except satisfaction with life and dimensions of emerging adulthood (p = .63). The effect sizes of all correlations were either trivial or small (rs < .3; Cohen, 1988).

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Dimensions of Emerging Adulthood (idea) 3.57 0.39
Satisfaction with Life (swb) 4.43 1.33 -.01
[-.05, .03]
Mindfulness (mindful) 3.72 0.84 -.13** .29**
[-.17, -.08] [.25, .33]
Social Media Use (socmeduse) 34.27 8.58 .22** .09** -.12**
[.18, .26] [.05, .13] [-.16, -.07]
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.