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 independence, satisfaction with life, the need to belong, and social media use will all be correlated with each other. Furthermore, we predict that social media use will be high in participants who are lower in satisfaction with life or who report a higher need to belong.

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':    2104 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 ...
##  $ 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_independence, swb, belong, 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
## moa_independence    1 2104  3.54 0.47   3.67    3.61 0.49  1.0   4   3.0 -1.49
## swb                 2 2104  4.43 1.33   4.50    4.49 1.48  1.0   7   6.0 -0.36
## belong              3 2104  3.21 0.61   3.20    3.23 0.59  1.3   5   3.7 -0.27
## socmeduse           4 2104 34.24 8.63  35.00   34.51 7.41 11.0  55  44.0 -0.30
##                  kurtosis   se
## moa_independence     2.77 0.01
## swb                 -0.49 0.03
## belong              -0.12 0.01
## socmeduse            0.18 0.19
# 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$belong)

hist(d2$socmeduse)

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

plot(d2$moa_independence, d2$belong)

plot(d2$moa_independence, d2$socmeduse)

plot(d2$swb, d2$belong)

plot(d2$swb, d2$socmeduse)

plot(d2$socmeduse, d2$belong)

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

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

sum(d2$socmeduse < -3 | d2$socmeduse > 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, a measure of importance of independence (moa_independence) had high kurtosis (2.77) and had 36 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 my measure of independence should be evaluated carefully due to these risks.

6 Run a Single Correlation

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] 2104
## 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 belong socmeduse
## moa_independence             1.00  0.08   0.02      0.09
## swb                          0.08  1.00  -0.15      0.09
## belong                       0.02 -0.15   1.00      0.28
## socmeduse                    0.09  0.09   0.28      1.00
## Sample Size 
## [1] 2104
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##                  moa_independence swb belong socmeduse
## moa_independence             0.00   0   0.46         0
## swb                          0.00   0   0.00         0
## belong                       0.46   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 importance of independence, satisfaction with life, the need to belong, and social media use would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Of all the variables, 2 of the 4 had outliers, including independence (moa_independent) which had 36 outliers, and the need to belong (belong) which had 2 outliers. Most of our data did not meet the assumptions of the test, with most variables failing to meet the standards of normality. The data shows inconsistencies and any significant results involving that variable should be evaluated carefully.

We found that most of the variables were significantly correlated (ps < .001).However, the correlation between the need to belong and independence was about 0.46, which is well above the 0.001 threshold. The effect sizes of all correlations were small, falling below the threshold of rs > .5 (Cohen, 1988).

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Independence 0.00 1.00
Satisfaction with Life -0.00 1.00 .08**
[.04, .13]
Need to Belong -0.00 1.00 .02 -.15**
[-.03, .06] [-.19, -.11]
Social Media Use 0.00 1.00 .09** .09** .28**
[.05, .13] [.04, .13] [.24, .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.