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

We predict that eating disorder behaviors, neuroticism, extroversion, and self-esteem will all be correlated with each other. Additionally, we predict that self-esteem will be negatively correlated with eating disorder behaviors, such that participants with lower self-esteem will report higher engagement in eating disorder behaviors.

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':    1066 obs. of  7 variables:
##  $ X       : int  1 20 30 31 49 57 81 86 104 113 ...
##  $ gender  : chr  "female" "male" "female" "female" ...
##  $ exercise: num  0 2 3 1.5 2 2 2 2.5 0.5 1 ...
##  $ big5_ext: num  2 1.67 6 5 5.67 ...
##  $ big5_neu: num  6 6.67 4 4 5 ...
##  $ rse     : num  2.3 1.6 3.9 1.7 2.4 1.8 3.5 2.6 3 3.5 ...
##  $ edeq12  : num  1.58 1.83 1 1.67 1.33 ...
# 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(edeq12, big5_ext, big5_neu, rse))

# 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
## edeq12      1 1066 1.87 0.73   1.67    1.80 0.74   1   4     3  0.73    -0.48
## big5_ext    2 1066 4.34 1.46   4.67    4.39 1.48   1   7     6 -0.27    -0.82
## big5_neu    3 1066 4.35 1.51   4.67    4.39 1.48   1   7     6 -0.29    -0.79
## rse         4 1066 2.65 0.71   2.70    2.67 0.74   1   4     3 -0.25    -0.66
##            se
## edeq12   0.02
## big5_ext 0.04
## big5_neu 0.05
## rse      0.02
# NOTE: Our fake variable has high kurtosis, which we'll ignore for the lab. 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 project manuscript.

# also use histograms to examine your continuous variables

hist(d$big5_ext)

hist(d$big5_neu)

hist(d$edeq12)

hist(d$rse)

# last, use scatterplots to examine your continuous variables together, for each pairing

plot(d$big5_ext, d$big5_neu)

plot(d$big5_ext, d$rse)

plot(d$big5_ext, d$edeq12)

plot(d$big5_neu, d$rse)

plot(d$big5_neu, d$edeq12)

plot(d$rse, d$edeq12)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have two 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: 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.

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

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

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

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

sum(d2$big5_neu < -3 | d2$big5_neu > 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 the assumptions of Pearson’s correlation coefficient.None of my variables show significant outliers, non-normality, or non-linear relationships. As a result, Pearson’s r will provide an accurate measure of the linear relationships among my variables without the risk of distortion from outliers or non-linearity.

6 Run a Single Correlation

corr_output <- corr.test(d$rse, d$edeq12)

7 View Single Correlation

corr_output
## Call:corr.test(x = d$rse, y = d$edeq12)
## Correlation matrix 
## [1] -0.53
## Sample Size 
## [1] 1066
## These are the unadjusted probability values.
##   The probability values  adjusted for multiple tests are in the p.adj object. 
## [1] 0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

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|

Remember, Pearson’s r is also an effect size!

corr_output_m <- corr.test(d2)

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##          edeq12 big5_ext big5_neu   rse
## edeq12     1.00    -0.16     0.35 -0.53
## big5_ext  -0.16     1.00    -0.29  0.35
## big5_neu   0.35    -0.29     1.00 -0.61
## rse       -0.53     0.35    -0.61  1.00
## Sample Size 
## [1] 1066
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##          edeq12 big5_ext big5_neu rse
## edeq12        0        0        0   0
## big5_ext      0        0        0   0
## big5_neu      0        0        0   0
## rse           0        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

10 Write Up Results

To test our hypothesis that eating disorder behavior, neuroticism, extroversion, and self-esteem would be correlated, we calculated a series of Pearson’s correlation coefficients. All four variables met the required assumptions of the test, including normality and the absence of significant outliers. As predicted, we found significant correlations among all variables (all ps < .001).

For example, eating disorder behavior (EDE-Q12) was strongly negatively correlated with self-esteem (RSE; r = -0.53, p < .001). Additionally, neuroticism showed a moderate positive correlation with eating disorder behavior (r = 0.35, p < .001) and a strong negative correlation with self-esteem (r = -0.61, p < .001). Extroversion, on the other hand, had weaker correlations with eating disorder behavior (r = -0.16, p < .001) and neuroticism (r = -0.29, p < .001), but a moderate positive correlation with self-esteem (r = 0.35, p < .001).

These results support our hypothesis and demonstrate meaningful relationships between these psychological constructs. Full correlation coefficients and significance levels are reported in Table 1.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Neurotocism 4.35 1.51
Extroversion 4.34 1.46 -.29**
[-.35, -.24]
Self Esteem 2.65 0.71 -.61** .35**
[-.65, -.57] [.29, .40]
Eating disorder behavior 1.87 0.73 .35** -.16** -.53**
[.30, .41] [-.22, -.10] [-.57, -.49]
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.