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
## Warning: package 'apaTables' was built under R version 4.4.2
library(kableExtra) # to create our correlation table
## Warning: package 'kableExtra' was built under R version 4.4.2

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 people who are more open to new experiences and to others were more likely to adapt positively to COVID-19 comparatively to those who are less open. # 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':    1337 obs. of  7 variables:
##  $ X        : int  20 30 31 48 49 57 58 69 79 81 ...
##  $ age      : chr  "1 under 18" "1 under 18" "4 between 36 and 45" "4 between 36 and 45" ...
##  $ mhealth  : chr  "anxiety disorder" "none or NA" "none or NA" "depression" ...
##  $ covid_pos: int  0 0 0 0 0 0 0 0 0 0 ...
##  $ covid_neg: int  0 0 0 0 0 0 0 0 0 0 ...
##  $ big5_open: num  5.33 5 6 4.33 6.67 ...
##  $ big5_ext : num  1.67 6 5 4.33 5.67 ...
# We're going to create a fake variable for this lab, so that we have four variables. 
# NOTE: YOU WILL SKIP THIS STEP FOR THE HOMEWORK!


# 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(covid_pos, covid_neg, big5_open, big5_ext))

# 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
## covid_pos    1 1337 2.05 3.38   0.00    1.32 0.00   0  15    15  1.58     1.47
## covid_neg    2 1337 1.21 1.87   0.00    0.85 0.00   0   8     8  1.29     0.44
## big5_open    3 1337 5.21 1.13   5.33    5.29 0.99   1   7     6 -0.75     0.54
## big5_ext     4 1337 4.37 1.45   4.33    4.41 1.48   1   7     6 -0.24    -0.78
##             se
## covid_pos 0.09
## covid_neg 0.05
## big5_open 0.03
## big5_ext  0.04
# 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$covid_pos)

hist(d$covid_neg)

hist(d$big5_open)

hist(d$big5_ext)

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

plot(d$covid_pos, d$covid_neg)

plot(d$covid_pos, d$big5_open)

plot(d$covid_pos, d$big5_ext)

plot(d$covid_neg, d$big5_open)

plot(d$covid_neg, d$big5_ext)

plot(d$big5_ext, d$big5_open)

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.

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

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

sum(d2$covid_pos < -3 | d2$covid_pos > 3)
## [1] 13
d2$covid_neg <- scale(d2$covid_neg, center=T, scale=T)
hist(d2$covid_neg)

sum(d2$covid_neg < -3 | d2$covid_neg > 3)
## [1] 11
d2$big5_open <- scale(d2$big5_open, center=T, scale=T)
hist(d2$big5_open)

sum(d2$big5_open < -3 | d2$big5_open > 3)
## [1] 9
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

4.2 Issues with My Data

Three of my variables met the assumptions for Pearson’s correlation coefficient. COVID positivity had 13 outliers, COVID negativity had 11, and openness had 9, while extraversion contained no outliers. Outliers may influence correlation values, so results involving COVID positivity, COVID negativity, and openness should be interpreted with caution.

5 Run a Single Correlation

corr_output <- corr.test(d$covid_pos, d$covid_neg)

6 View Single Correlation

corr_output
## Call:corr.test(x = d$covid_pos, y = d$covid_neg)
## Correlation matrix 
## [1] 0.66
## Sample Size 
## [1] 1337
## 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

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|

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

corr_output_m <- corr.test(d2)

8 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##           covid_pos covid_neg big5_open big5_ext
## covid_pos      1.00      0.66      0.08    -0.12
## covid_neg      0.66      1.00      0.04    -0.15
## big5_open      0.08      0.04      1.00     0.18
## big5_ext      -0.12     -0.15      0.18     1.00
## Sample Size 
## [1] 1337
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           covid_pos covid_neg big5_open big5_ext
## covid_pos         0      0.00      0.01        0
## covid_neg         0      0.00      0.17        0
## big5_open         0      0.17      0.00        0
## big5_ext          0      0.00      0.00        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

9 Write Up Results

To test our hypothesis that openness and extraversion would be positively associated with positive adaptation to COVID-19 experiences, we calculated Pearson’s correlation coefficients for the relationships between COVID positivity (covid_pos), COVID negativity (covid_neg), openness (big5_open), and extraversion (big5_ext).

Three of the variables—COVID positivity, COVID negativity, and openness—had outliers. Specifically, COVID positivity had 13 outliers, COVID negativity had 11, and openness had 9. Extraversion, however, met all assumptions without any significant outliers.

The analysis showed that COVID positivity and COVID negativity were strongly positively correlated (r = .66, p < .001). As hypothesized, extraversion and openness were weakly but significantly correlated (r = .18, p < .001). However, the expected relationship between openness and COVID positivity was weak and not statistically significant (r = .08, p = .01). The correlations between extraversion and both COVID positivity and negativity were weak to trivial, with both correlations falling below .20.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
COVID Positive 2.05 3.38
COVID Negative 1.21 1.87 .66**
[.63, .69]
Openness 5.21 1.13 .08** .04
[.02, .13] [-.02, .09]
Extraversion 4.37 1.45 -.12** -.15** .18**
[-.18, -.07] [-.20, -.10] [.13, .23]
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.