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 need to belong, efficacy, social media use, and scores on the narcissistic personality inventory will all be correlated with each other. Furthermore, we predict that social media use will have a positive correlation with participants who report higher scores on the narcissistic personality inventory.

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':    3146 obs. of  6 variables:
##  $ race_rc  : chr  "white" "white" "white" "other" ...
##  $ marriage5: chr  "are currently divorced from one another" "are currently married to one another" "are currently married to one another" "are currently married to one another" ...
##  $ belong   : num  2.8 4.2 3.6 4 3.4 4.2 3.9 3.6 2.9 2.5 ...
##  $ efficacy : num  3.4 3.4 2.2 2.8 3 2.4 2.3 3 3 3.7 ...
##  $ socmeduse: int  47 23 34 35 37 13 37 43 37 29 ...
##  $ npi      : num  0.6923 0.1538 0.0769 0.0769 0.7692 ...
# 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(belong, efficacy, socmeduse, npi))

# 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
## belong       1 3146  3.23 0.61   3.30    3.25 0.59  1.3   5   3.7 -0.26
## efficacy     2 3146  3.13 0.45   3.10    3.13 0.44  1.1   4   2.9 -0.24
## socmeduse    3 3146 34.45 8.55  35.00   34.72 7.41 11.0  55  44.0 -0.31
## npi          4 3146  0.28 0.31   0.15    0.24 0.23  0.0   1   1.0  0.94
##           kurtosis   se
## belong       -0.13 0.01
## efficacy      0.45 0.01
## socmeduse     0.27 0.15
## npi          -0.69 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$belong)

hist(d2$efficacy)

hist(d2$socmeduse)

hist(d2$npi)

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

plot(d2$belong, d2$socmeduse)

plot(d2$belong, d2$npi)

plot(d2$efficacy, d2$socmeduse)

plot(d2$efficacy, d2$npi)

plot(d$socmeduse, d2$npi)

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

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

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

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

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

5.2 Issues with My Data

All of my variables meet most of the assumptions of Pearson’s correlation coefficient. The variables appear to have non-linear relationships with each other. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction. Correlations should be evaluated carefully due to these risks.

6 Run a Single Correlation

corr_output <- corr.test(d2$belong, d2$efficacy)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$belong, y = d2$efficacy)
## Correlation matrix 
##       [,1]
## [1,] -0.26
## Sample Size 
## [1] 3146
## 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 
##           belong efficacy socmeduse   npi
## belong      1.00    -0.26      0.28 -0.06
## efficacy   -0.26     1.00      0.04  0.17
## socmeduse   0.28     0.04      1.00  0.06
## npi        -0.06     0.17      0.06  1.00
## Sample Size 
## [1] 3146
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           belong efficacy socmeduse npi
## belong         0     0.00      0.00   0
## efficacy       0     0.00      0.03   0
## socmeduse      0     0.03      0.00   0
## npi            0     0.00      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 need to belong, efficacy, social media use, and scores on the narcissistic personality inventory 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. The variables did have issues concerning non-linear relationships with each other, and so any significant results involving these variables should be evaluated carefully.

As predicted, we found that all four variables were significantly correlated (all ps < .05). The effect sizes of all correlations were trivial to weak (rs > .05 and < .29 ; Cohen, 1988). This test weakly supported our second hypothesis, that social media use would be positively correlated with participants who reported higher scores on the narcissistic personality inventory, as can be seen by the correlation coefficients reported in Table 1. The trivial effect size of the correlation indicates that though the results may be statistically significant, they are not as practically meaningful.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
belong -0.00 1.00
efficacy -0.00 1.00 -.26**
[-.29, -.23]
socmeduse -0.00 1.00 .28** .04*
[.25, .31] [.00, .07]
npi 0.00 1.00 -.06** .17** .06**
[-.10, -.03] [.13, .20] [.02, .09]
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.