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

3 State Your Hypothesis

We predict that conscientiousness, anxiety related to the covid pandemic, stress, and prevelance of eating disorders will all be correlated with each other. Furthermore, we predict that there will be a significant relationship between perceived stress and anxiety related to the covid pandemic, with the relationship being positive. # 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':    1203 obs. of  6 variables:
##  $ sexual_orientation: chr  "Heterosexual/Straight" "Heterosexual/Straight" "Heterosexual/Straight" "Heterosexual/Straight" ...
##  $ mhealth           : chr  "none or NA" "anxiety disorder" "none or NA" "none or NA" ...
##  $ big5_con          : num  6 3.33 5.33 5.67 6 ...
##  $ pas_covid         : num  3.22 4.56 3.33 4.22 3.22 ...
##  $ pss               : num  3.25 3.75 1 3.25 2 2 4 1.25 1.25 2.5 ...
##  $ edeq12            : num  1.58 1.83 1 1.67 1.42 ...
# 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(big5_con,pas_covid,pss,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
## big5_con     1 1203 4.84 1.19   5.00    4.88 1.48 1.00   7  6.00 -0.29    -0.27
## pas_covid    2 1203 3.24 0.67   3.22    3.25 0.66 1.22   5  3.78 -0.13    -0.01
## pss          3 1203 2.93 0.95   3.00    2.92 1.11 1.00   5  4.00  0.08    -0.75
## edeq12       4 1203 1.88 0.73   1.75    1.81 0.74 1.00   4  3.00  0.68    -0.55
##             se
## big5_con  0.03
## pas_covid 0.02
## pss       0.03
## edeq12    0.02
# 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$big5_con)

hist(d2$pas_covid)

hist(d2$pss)

hist(d2$edeq12)

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

plot(d$big5_con, d$pss)

plot(d$big5_con, d$edeq12)

plot(d$pas_covid, d$pss)

plot(d$pas_covid, d$edeq12)

plot(d$pss, d$edeq12)

4 Check Your Assumptions

4.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

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

sum(d2$big5_con < -3 | d2$big5_con > 3)
## [1] 2
d2$pas_covid <- scale(d2$pas_covid, center=T, scale=T)
hist(d2$pas_covid)

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

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

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

4.2 Issues with My Data

All but one of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, a measure of conscientiousness, had 2 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. Any correlations with my measure of conscientiousness should be evaluated carefully due to these risks.

5 Run a Single Correlation

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

6 View Single Correlation

corr_output
## Call:corr.test(x = d2$pas_covid, y = d2$pss)
## Correlation matrix 
##      [,1]
## [1,] 0.35
## Sample Size 
## [1] 1203
## 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

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

8 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##           big5_con pas_covid   pss edeq12
## big5_con      1.00     -0.01 -0.34  -0.19
## pas_covid    -0.01      1.00  0.35   0.25
## pss          -0.34      0.35  1.00   0.46
## edeq12       -0.19      0.25  0.46   1.00
## Sample Size 
## [1] 1203
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           big5_con pas_covid pss edeq12
## big5_con       0.0       0.7   0      0
## pas_covid      0.7       0.0   0      0
## pss            0.0       0.0   0      0
## edeq12         0.0       0.0   0      0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

9 Write Up Results

To test our hypothesis that conscientiousness, covid pandemic anxiety, stress, prevalence of eating disorders would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Most of our data met the assumptions of the test, with three variables meeting the standards of normality and no outliers. One variable, conscientiousness, did have outliers 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 pandemic anxiety would be higher in participants who are higher in stress.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Conscientiousness -0.00 1.00
Covid pandemic anxiety -0.00 1.00 -.01
[-.07, .05]
Perceived stress -0.00 1.00 -.34** .35**
[-.39, -.29] [.30, .40]
Eating disorder prevalence -0.00 1.00 -.19** .25** .46**
[-.25, -.14] [.20, .31] [.42, .51]
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.