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/arc_clean.csv", header=T)

3 State Your Hypothesis

We hypothesize that stress (measured by the PSS-4), depression symptoms, self-esteem (measured by the RSE-10), and fakeness (a fake measure from the fake FKE-3) will all be correlated with each other. Furthermore, we predict that self-esteem will be lower in participants who are higher in stress or who report more symptoms of depression.

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':    1250 obs. of  6 variables:
##  $ X           : int  1 20 30 31 33 57 68 81 86 104 ...
##  $ gender_rc   : chr  "f" "m" "f" "f" ...
##  $ ethnicity_rc: chr  "white" "white" "white" "white" ...
##  $ pss         : num  3.25 3.75 1 3.25 2 4 3.75 1.25 2.5 2.5 ...
##  $ phq         : num  1.33 3.33 1 2.33 1.11 ...
##  $ rse         : num  2.3 1.6 3.9 1.7 3.9 1.8 1.3 3.5 2.6 3 ...
# we're going to create a fake variable for this lab, so that it has four variables and mirrors the homework assignment. SKIP THIS STEP FOR THE HOMEWORK
d$fake <- (d$pss*d$phq)/d$rse

# 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(pss,phq,rse,fake))

# 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 kurtosis   se
## pss     1 1250 2.93 0.95   3.00    2.93 1.11 1.00   5  4.00  0.09    -0.74 0.03
## phq     2 1250 2.07 0.86   1.89    1.99 0.99 1.00   4  3.00  0.64    -0.69 0.02
## rse     3 1250 2.63 0.71   2.70    2.65 0.74 1.00   4  3.00 -0.22    -0.70 0.02
## fake    4 1250 3.31 3.39   1.94    2.65 1.77 0.25  20 19.75  1.89     3.75 0.10
# 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$pss)

hist(d2$phq)

hist(d2$rse)

hist(d2$fake)

# last, use scatterplots to examine your continuous variables together
plot(d$pss, d$phq)

plot(d$pss, d$rse)

plot(d$pss, d$fake)

# nonlinear- low amount of stress there is a weak positive relationship, high amount of stress there is a strong positive relationship, relationship differs as a function of one of the variables
# correlation tests designed to work with linear relationships, impacts analyses and conclusions we can make

plot(d$phq, d$rse)

plot(d$phq, d$fake)

plot(d$rse, d$fake)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have two measurements for each participant (can’t look at correlation with only one, should have no missing data)
  • Variables should be continuous and normally distributed (continuous = no categorical or ordinal variables- make note of any issues in write up)
  • Outliers should be identified and removed (they impact the validity of our test, can make misleading claims, looking for univariate variables based on z score - if above +3 or below -3 they are an outlier)
  • Relationship between the variables should be linear (have to transform variable, drop it, or use other statistical test if it is not, include in write up)

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

sum(d2$pss < -3 | d2$pss > 3)
## [1] 0
# This sum is counting any participants that are less than -3 or higher than +3

d2$phq <- scale(d2$phq, center=T, scale=T)
hist(d2$phq)

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

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

sum(d2$fake < -3 | d2$fake > 3)
## [1] 31
# normally we would drop the participants that are outside of this range, but we are keeping them for the class.

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 fake measure of something fake (FKE-3) had high kurtosis (3.75) and had 31 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 fake measure of fakeness should be evaluated carefully due to these risks.

6 Run a Single Correlation

corr_output <- corr.test(d2$pss, d2$phq)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$pss, y = d2$phq)
## Correlation matrix 
##      [,1]
## [1,] 0.75
## Sample Size 
## [1] 1250
## 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
# 0.75 is R value- measure of relationship between stress and depression in participants and measure of effect size- positive relationship and strong
# more tests we run, greater chance of getting a false positive- to avoid, use anovas to control for family-wise error rate/risk of false positives. Need to adjust p value to make it more conservative if doing correlations. R automatically gives adjusted p value if we use a matrix instead of single correlation.

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 
##        pss   phq   rse  fake
## pss   1.00  0.75 -0.74  0.79
## phq   0.75  1.00 -0.75  0.87
## rse  -0.74 -0.75  1.00 -0.83
## fake  0.79  0.87 -0.83  1.00
## Sample Size 
## [1] 1250
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##      pss phq rse fake
## pss    0   0   0    0
## phq    0   0   0    0
## rse    0   0   0    0
## fake   0   0   0    0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option
# First set gives relationship between all of our pairs. Diagonal is the 1.00's that are correlation a variable with itself. Our variables are so correlated that the p values are all less than 0.001 still, but if we had less correlated p values, then the values above diagonal would be different than below because they are the adjusted ones. 
# Report adjusted p values from above the diagonal

10 Write Up Results

To test our hypothesis that stress (measured by the PSS-4), depression symptoms (measured by the PHQ-9), self-esteem (measured by the RSE-10), and fakeness (a fake measure FKE-3) would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Most of uur data met the assumptions of the test, with all variables meeting the standards of normality and no outliers. One variable, fakeness, did have outliers and non-linear relationships with the other variables, and so any significant results involving that variable should be evaluated carefully.

As predicted, we found that all four variables were significantly correlated (all ps < .001). The effect sizes of all correlations were large (rs > .5; Cohen, 1988). This test also supported our second hypothesis, that self-esteem would be lower in participants who are higher in stress or who report more symptoms of depression, as can be seen by the correlation coefficients reported in Table 1.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Perceived stress (PSS-4) -0.00 1.00
Depression symptoms (PHQ-9) -0.00 1.00 .75**
[.72, .77]
Self-esteem (RSE-10) -0.00 1.00 -.74** -.75**
[-.76, -.71] [-.77, -.72]
Fake (FKE-3) -0.00 1.00 .79** .87** -.83**
[.77, .81] [.85, .88] [-.84, -.81]
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.