1 Loading Libraries

#install.packages("apaTables")
#install.packages("kableExtra")

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

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

# For HW, import the your project dataset you cleaned previously; this will be the dataset you'll use throughout the rest of the semester

3 State Your Hypothesis

There will be a significant relationship between self esteem, resilience, and anxiety . Specifically, anxiety will be negatively related to self-estee, but positively related to resilience

There will be a significant relationship between General Anxiety Disorder, self esteem, and resilience. Specifically, general anxiety will be negatively related to self-esteem and negatively related to resilience.

4 Check Your Variables

# Since we're focusing only on our continuous variables, we're going to subset them into their own dataframe. This will make some stuff we're doing later on easier.

d2 <- subset(d, select = c(brs, rse, gad))

# 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
## brs    1 417 2.67 0.88   2.67    2.67 0.99   1   5     4  0.10    -0.68 0.04
## rse    2 417 2.24 0.70   2.20    2.22 0.74   1   4     3  0.33    -0.65 0.03
## gad    3 417 2.54 0.93   2.57    2.55 1.27   1   4     3 -0.04    -1.19 0.05
# NOTE: Our fake variable has high kurtosis, which we'll ignore for the lab because we created it to be problematic. If you have high skew or kurtosis for any of your project variables, you will need to discuss it below in the Issues with My Data and Write up Results sections, as well as in your final project manuscript if your data does not meet the normality assumption.


# also use histograms to examine your continuous variables
# Because we are looking at 3 variables, we will have 3 histograms.

hist(d$gad)

hist(d$rse)

hist(d$brs)

# last, use scatterplots to examine your continuous variables together, for each pairing
# because we are looking at 3 variables, we will have 3 pairings/plots. 

plot(d$gad, d$rse)

plot(d$rse, d$brs)

plot(d$gad, d$brs)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have … for each participant.
  • Variables should be … and normally distributed.
  • Outliers should be identified and removed.
  • Relationship between the variables should be … .

5.1.1 Checking for Outliers

Note: For correlations, you will NOT screen out outliers or take any action based on what you see here. This is something you will simply check and then discuss in your write-up.We will learn how to removed outliers in later analyses.

# We are going to standardize (z-score) all of our 3 variables, and check them for outliers.

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

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

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

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

5.2 Issues with My Data

[all] of my variables meet all of the assumptions of Pearson’s correlation coefficient. GAD had kurtosis (-1.19) and no extreme outliers , indicating a pretty normal distribution. Outliers can distort the relationship between two variables and sway the correlation in their direction. Pearson’s r may is appropriate in analyzing the relationship between these variables

6 Run a Single Correlation

corr_output <- corr.test(d2$gad, d2$rse)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$gad, y = d2$rse)
## Correlation matrix 
##       [,1]
## [1,] -0.65
## Sample Size 
## [1] 417
## 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

corr_output_m <- corr.test(d2)

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##       brs   rse   gad
## brs  1.00  0.65 -0.59
## rse  0.65  1.00 -0.65
## gad -0.59 -0.65  1.00
## Sample Size 
## [1] 417
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##     brs rse gad
## brs   0   0   0
## rse   0   0   0
## gad   0   0   0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option
# Remember to report the p-values from the matrix that are ABOVE the diagonal!

Remember, Pearson’s r is also an effect size! We don’t report effect sizes for non-sig correlations.

  • 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|

10 Write Up Results

To test our hypothesis that unhappiness, life satisfaction, and worry (a fake variable we created for this lab) would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Two of the variables (unhappiness and life satisfaction) met the required assumptions of the test, with both meeting the standards of normality and containing no outliers. One variable, worry, was slightly skewed and kurtotic still fell in the acceptable range. Because of this Pearson’s r was determined to be appropriate for this analysis.

As predicted, we found that all three variables were significantly correlated (all ps < .001). The effect sizes of all correlations were large (rs > .5; Cohen, 1988). Additionally, resilience was found to be positively related to self-esteem r=-.65, and negatively related to anxiety r=.59, as predicted. Please refer to the correlation coefficients reported in Table 1.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2
Anxiety 2.54 0.93
Resilience 2.24 0.70 -.65**
[-.70, -.59]
Self-esteem 2.67 0.88 -.59** .65**
[-.65, -.52] [.59, .70]
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.