Correlation Lab

Author

Wyatt Sluder

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

Importing Data

d <- read.csv(file="Data/mydata.csv", header=T)

# since we're focusing on our continuous variables, we're going to drop our categorical variables. this will make some stuff we're doing later easier.
d <- subset(d, select=-c(gender, employment))

State Your Hypotheses - PART OF YOUR WRITEUP

There will be a correlation between neuroticism, extroversion, agreeableness, and openness during the covid pandemic.

Check Your Assumptions

Pearson’s Correlation Coefficient Assumptions

  • Should have two measurements for each participant for each variable (confirmed by earlier procedures – we dropped any participants with missing data)
  • Variables should be continuous and normally distributed, or assessments of the relationship may be inaccurate (confirmed above – if issues, make a note and continue)
  • Outliers should be identified and removed, or results will be inaccurate (will do below)
  • Relationship between the variables should be linear, or they will not be detected (will do below)

Checking for Outliers

Outliers can mask potential effects and cause Type II error (you assume there is no relationship when there really is one, e.g., false negative).

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.

# using the scale() command to standardize our variable, viewing a histogram, and then counting statistical outliers
d$big5_agr <- scale(d$big5_agr, center=T, scale=T)
hist(d$big5_agr)

sum(d$big5_agr < -3 | d$big5_agr > 3)
[1] 4
d$big5_ext <- scale(d$big5_ext, center=T, scale=T)
hist(d$big5_ext)

sum(d$big5_ext < -3 | d$big5_ext > 3)
[1] 0
d$big5_neu <- scale(d$big5_neu, center=T, scale=T)
hist(d$big5_neu)

sum(d$big5_neu < -3 | d$big5_neu > 3)
[1] 0
d$big5_open <- scale(d$big5_open, center=T, scale=T)
hist(d$big5_open)

sum(d$big5_open < -3 | d$big5_open > 3)
[1] 12

Checking for Linear Relationships

Non-linear relationships cannot be detected by Pearson’s correlation (the type of correlation we’re doing here). This means that you may underestimate the relationship between a pair of variables if they have a non-linear relationship, and thus your understanding of what’s happening in your data will be inaccurate.

Visually check that relationships are linear and write a brief description of any potential nonlinearity. You will have to use your judgement. There are no penalties for answering ‘wrong’, so try not to stress out about it too much – just do your best.

# use scatterplots to examine your continuous variables together
plot(d$big5_agr, d$big5_neu)

plot(d$big5_agr, d$big5_open)

plot(d$big5_agr, d$big5_ext)

plot(d$big5_neu, d$big5_open)

plot(d$big5_neu, d$big5_ext)

plot(d$big5_ext, d$big5_open)

Check Your Variables

describe(d)
          vars    n mean sd median trimmed  mad   min  max range  skew kurtosis
big5_neu     1 1722    0  1   0.17    0.04 0.98 -2.25 1.71  3.96 -0.31    -0.73
big5_agr     2 1722    0  1   0.02    0.04 0.89 -3.57 1.82  5.39 -0.39    -0.02
big5_open    3 1722    0  1   0.11    0.07 0.87 -3.69 1.58  5.26 -0.72     0.43
big5_ext     4 1722    0  1  -0.01    0.03 1.02 -2.31 1.82  4.13 -0.25    -0.76
            se
big5_neu  0.02
big5_agr  0.02
big5_open 0.02
big5_ext  0.02
# also use histograms to examine your continuous variables
hist(d$big5_neu)

hist(d$big5_agr)

hist(d$big5_open)

hist(d$big5_ext)

Issues with My Data - PART OF YOUR WRITEUP

There were 12 outliers for scores on openness, as well as 4 outliers for agreeableness. These may skew data making it seem more extreme due to only a few participant’s scores.

Run Pearson’s Correlation

There are two ways to run Pearson’s correlation in R. You can calculate each correlation one-at-a-time using multiple commands, or you can calculate them all at once and report the scores in a matrix. The matrix output can be confusing at first, but it’s more efficient. We’ll do it both ways.

Run a Single Correlation

corr_output <- corr.test(d$big5_neu, d$big5_ext)

View Single Correlation

Strong effect: Between |0.50| and |1|

Moderate effect: Between |0.30| and |0.49|

Weak effect: Between |0.10| and |0.29|

Trivial effect: Less than |0.09|

corr_output
Call:corr.test(x = d$big5_neu, y = d$big5_ext)
Correlation matrix 
      [,1]
[1,] -0.31
Sample Size 
[1] 1722
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

Create a Correlation Matrix

corr_output_m <- corr.test(d)

View Test Output

Strong effect: Between |0.50| and |1|

Moderate effect: Between |0.30| and |0.49|

Weak effect: Between |0.10| and |0.29|

Trivial effect: Less than |0.09|

corr_output_m
Call:corr.test(x = d)
Correlation matrix 
          big5_neu big5_agr big5_open big5_ext
big5_neu      1.00    -0.11     -0.03    -0.31
big5_agr     -0.11     1.00      0.08     0.09
big5_open    -0.03     0.08      1.00     0.21
big5_ext     -0.31     0.09      0.21     1.00
Sample Size 
[1] 1722
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
          big5_neu big5_agr big5_open big5_ext
big5_neu      0.00        0      0.18        0
big5_agr      0.00        0      0.00        0
big5_open     0.18        0      0.00        0
big5_ext      0.00        0      0.00        0

 To see confidence intervals of the correlations, print with the short=FALSE option

Write Up Results

Our hypothesis that there would be a correlation among personality traits was not supported. Although there was a indication neuroticism and openness are correlated at 0.18 correlation coefficient, a weak effect, none of the other variables were correlated at all. There were outliers in two different groups, 4 for agreeableness and 12 for openness.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Neuroticism -0.00 1.00
Agreeableness 0.00 1.00 -.11**
[-.15, -.06]
Openness 0.00 1.00 -.03 .08**
[-.08, .01] [.03, .12]
Extroversion -0.00 1.00 -.31** .09** .21**
[-.35, -.26] [.04, .14] [.17, .26]
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.