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
Correlation HW
Loading Libraries
Importing Data
<- read.csv(file="Data/mydata.csv", header=T)
d
# 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.
<- subset(d, select=-c(gender, age)) d
State Your Hypotheses - PART OF YOUR WRITEUP
We predict that negative effects of Covid, worry, and extraversion will be positively correlated, and all three variables will be negatively correlated with positive effects of Covid.
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 (will do below)
- 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
$covid_neg <- scale(d$covid_neg, center=T, scale=T)
dhist(d$covid_neg)
sum(d$covid_neg < -3 | d$covid_neg > 3)
[1] 11
$pswq <- scale(d$pswq, center=T, scale=T)
dhist(d$pswq)
sum(d$pswq < -3 | d$pswq > 3)
[1] 0
$big5_ext <- scale(d$big5_ext, center=T, scale=T)
dhist(d$big5_ext)
sum(d$big5_ext < -3 | d$big5_ext > 3)
[1] 0
$covid_pos <- scale(d$covid_pos, center=T, scale=T)
dhist(d$covid_pos)
sum(d$covid_pos < -3 | d$covid_pos > 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_ext, d$pswq)
plot(d$big5_ext, d$covid_pos)
plot(d$big5_ext, d$covid_neg)
plot(d$pswq, d$covid_pos)
plot(d$pswq, d$covid_neg)
plot(d$covid_pos, d$covid_neg)
Check Your Variables
describe(d)
vars n mean sd median trimmed mad min max range skew kurtosis
big5_ext 1 1272 0 1 -0.02 0.03 1.03 -2.33 1.82 4.15 -0.24 -0.78
pswq 2 1272 0 1 0.04 0.01 1.17 -2.23 2.41 4.63 -0.08 -0.92
covid_pos 3 1272 0 1 -0.61 -0.22 0.00 -0.61 3.84 4.44 1.58 1.48
covid_neg 4 1272 0 1 -0.64 -0.19 0.00 -0.64 3.64 4.28 1.31 0.50
se
big5_ext 0.03
pswq 0.03
covid_pos 0.03
covid_neg 0.03
# also use histograms to examine your continuous variables
hist(d$big5_ext)
hist(d$pswq)
hist(d$covid_pos)
hist(d$covid_neg)
Issues with My Data - PART OF YOUR WRITEUP
In the data, we found 11 outliers in the Covid Negative variable, and 12 outliers in the Covid Positive variable. Outliers can skew the relationships between variables to be inaccurate, therefore, it is important to be wary of them. There are no issues with non-linearity or linearity. The skew and kurtotisis have no issues as all variable correlations are between -2 and +2.
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.test(d$big5_ext, d$covid_neg) corr_output
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_ext, y = d$covid_neg)
Correlation matrix
[,1]
[1,] -0.15
Sample Size
[1] 1272
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.test(d) corr_output_m
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_ext pswq covid_pos covid_neg
big5_ext 1.00 -0.25 -0.12 -0.15
pswq -0.25 1.00 0.12 0.26
covid_pos -0.12 0.12 1.00 0.66
covid_neg -0.15 0.26 0.66 1.00
Sample Size
[1] 1272
Probability values (Entries above the diagonal are adjusted for multiple tests.)
big5_ext pswq covid_pos covid_neg
big5_ext 0 0 0 0
pswq 0 0 0 0
covid_pos 0 0 0 0
covid_neg 0 0 0 0
To see confidence intervals of the correlations, print with the short=FALSE option
Write Up Results (can copy paste from written above)
Again our hypothesis is, we predict that negative effects of Covid, worry, and extraversion will be positively correlated, and all three variables will be negatively correlated with positive effects of Covid. Some issues we found with our data were, 11 outliers in the Covid Negative variable, and 12 outliers in the Covid Positive variable. Outliers can skew the relationships between variables to be inaccurate, therefore, it is important to be wary of them. There are no issues with non-linearity or linearity. The skew and kurtotisis have no issues as all variable correlations are between -2 and +2. Our results found that all four variables had statistically significant correlations (See Table 1). Effective sizes range from weak to strong. Directionality, was both as predicted and unexpected. For example, Extraversion is negatively correlated with worry, predictably. However, unexpectedly, Covid Negative is positively correlated with Covid Positive.
Variable | M | SD | 1 | 2 | 3 |
---|---|---|---|---|---|
Extraversion (big5_ext) | -0.00 | 1.00 | |||
Worry (pswq) | 0.00 | 1.00 | -.25** | ||
[-.30, -.19] | |||||
Positive Effects of Covid (covid_pos) | 0.00 | 1.00 | -.12** | .12** | |
[-.17, -.07] | [.07, .18] | ||||
Negative Effects of Covid (covid_neg) | -0.00 | 1.00 | -.15** | .26** | .66** |
[-.20, -.10] | [.20, .31] | [.63, .69] | |||
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.