Correlation HW

Author

Alisha Patel

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(exercise_cat, sleep_hours))

State Your Hypotheses - PART OF YOUR WRITEUP

We predict that intolerance of uncertainty, general anxiety, and pandemic anxiety will be positively correlated, and all three of these variables will be negatively correlated with self-esteem.

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

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

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

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

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

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$gad, d$pas_covid)

plot(d$gad, d$iou)

plot(d$gad, d$rse)

plot(d$pas_covid, d$iou)

plot(d$pas_covid, d$rse)

plot(d$iou, d$rse)

Check Your Variables

describe(d)
          vars    n mean sd median trimmed  mad   min  max range  skew kurtosis
gad          1 1039    0  1  -0.32   -0.11 0.94 -1.11 2.23  3.34  0.76    -0.56
pas_covid    2 1039    0  1   0.02    0.02 0.97 -2.93 2.65  5.58 -0.19    -0.03
iou          3 1039    0  1  -0.14   -0.07 1.05 -1.72 2.76  4.48  0.53    -0.54
rse          4 1039    0  1   0.06    0.03 1.03 -2.31 1.87  4.19 -0.28    -0.65
            se
gad       0.03
pas_covid 0.03
iou       0.03
rse       0.03
# also use histograms to examine your continuous variables
hist(d$gad)

hist(d$pas_covid)

hist(d$iou)

hist(d$rse)

Issues with My Data - PART OF YOUR WRITEUP

Make a note right here if you have any outliers. Make sure you describe what variable the outliers are in and how many there are.

Make a note here if you have any indications of non-linearity in your variable pairings.

Make a note here if you have any skew/kurtosis and describe what variables it occurs in.

Briefly describe any issues with your data and how they might impact the interpretation of your results. As usual, this should be written in an appropriate scientific tone.

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$gad, d$pas_covid)

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$gad, y = d$pas_covid)
Correlation matrix 
     [,1]
[1,] 0.37
Sample Size 
[1] 1039
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 
            gad pas_covid   iou   rse
gad        1.00      0.37  0.69 -0.70
pas_covid  0.37      1.00  0.36 -0.27
iou        0.69      0.36  1.00 -0.65
rse       -0.70     -0.27 -0.65  1.00
Sample Size 
[1] 1039
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
          gad pas_covid iou rse
gad         0         0   0   0
pas_covid   0         0   0   0
iou         0         0   0   0
rse         0         0   0   0

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

Write Up Results

We predict that intolerance of uncertainty, general anxiety, and pandemic anxiety will be positively correlated, and all three of these variables will be negatively correlated with self-esteem. This hypothesis was correct. There weren’t any issues with my data. The sums for all four continuous variables were 0 indicating no outliers. Skew and kurtosis were all in range (-2 - +2) meaning there were no indications of non-normality in the variables. All variables produced significant results: p < .001. The interpretation for effect size for intolerance of uncertainty was strong, general anxiety was strong, pandemic anxiety was moderate, and self-esteem was trivial according to Cohen (1988). (refer to Figure 1).

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Intolerance of Uncertainty -0.00 1.00
Self-esteem (RSE-10) 0.00 1.00 .37**
[.31, .42]
Depression score (PHQ-9) 0.00 1.00 .69** .36**
[.66, .72] [.30, .41]
Perceived Stress (PSS) 0.00 1.00 -.70** -.27** -.65**
[-.73, -.67] [-.33, -.22] [-.68, -.61]
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.