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 resilience, self-esteem, and disordered eating. Specifically, resilience will be positively related to self-esteem and negatively related to disordered eating; and self-esteem will be negatively related to disordered eating.

4 Check Your Variables

# you only need to check the variables you're using in the current analysis
# it's always a good idea to look them to be sure that everything is correct
str(d)
## 'data.frame':    255 obs. of  7 variables:
##  $ X        : int  7888 7365 8760 8738 7911 6591 6638 8414 8448 6890 ...
##  $ mhealth  : chr  "none or NA" "none or NA" "none or NA" "none or NA" ...
##  $ treatment: chr  "seeking treatment" "no psychological disorders" "no psychological disorders" "not in treatment" ...
##  $ brs      : num  2 3.83 4.67 3 3.17 ...
##  $ edeq12   : num  1.33 1.83 1.17 1 1.08 ...
##  $ rse      : num  2.4 1.4 3.9 3.3 3 1.6 3.2 2.3 2.9 3.2 ...
##  $ mfq_26   : num  4.95 3.85 5.65 4.75 3.65 3.45 5.35 4.1 4.05 3.6 ...
# 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, edeq12))

# 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 255 2.55 0.85   2.33    2.52 0.74   1   5     4 0.28    -0.39 0.05
## rse       2 255 2.14 0.65   2.00    2.11 0.59   1   4     3 0.53    -0.25 0.04
## edeq12    3 255 2.16 0.79   2.17    2.14 0.99   1   4     3 0.21    -1.07 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$brs)

hist(d$rse)

hist(d$edeq12)

# 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$brs,d$rse)

plot(d$brs,d$edeq12)

plot(d$rse,d$edeq12)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

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

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

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

5.2 Issues with My Data

My variables meet all of the assumptions of Pearson’s correlation coefficient.

6 Run a Single Correlation

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

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$brs, y = d2$rse)
## Correlation matrix 
##      [,1]
## [1,] 0.64
## Sample Size 
## [1] 255
## 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 edeq12
## brs     1.00  0.64  -0.39
## rse     0.64  1.00  -0.55
## edeq12 -0.39 -0.55   1.00
## Sample Size 
## [1] 255
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##        brs rse edeq12
## brs      0   0      0
## rse      0   0      0
## edeq12   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 resilience, self-esteem, and disordered eating would be correlated with each other, we calculated a series of Pearson’s correlation coefficients. All three of the variables met the required assumptions of the test, with all meeting the standards of normality and containing no outliers.

As predicted, we found that all three variables were significantly correlated (all ps <.001). The correlations between resilience and self-esteem, as well as resilience and disordered eating had a strong effect size (rs > 0.50; Cohen, 1988). The effect size of the correlation between self-esteem and disordered eating was moderate.(rs = 0.39; Cohen, 1988). Additionally, resilience was found to be negatively related to disordered eating, and positively related to self-esteem, 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
Resilience 2.55 0.85
Self-esteem 2.14 0.65 .64**
[.56, .71]
Disordered eating 2.16 0.79 -.39** -.55**
[-.49, -.28] [-.63, -.46]
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.