1 Loading Libraries

#install.packages("apaTables")
#nstall.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 perceived positive effects of the COVID-19 lockdown, perceived negative effects of the COVID-19 lockdown, and general worry. Specifically, perceived positive effects of COVID-19 will be negatively related to both perceived negative effects of COVID-19 and general worry; and perceived negative effects of COVID-19 will be positively related to general worry.

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':    1166 obs. of  7 variables:
##  $ X        : int  1 321 401 1390 2183 2247 2526 2609 2689 2752 ...
##  $ treatment: chr  "no psychological disorders" "not in treatment" "not in treatment" "not in treatment" ...
##  $ mhealth  : chr  "none or NA" "none or NA" "obsessive compulsive disorder" "none or NA" ...
##  $ pswq     : num  4.94 1.71 2.44 2.25 3.14 ...
##  $ pas_covid: num  3.22 2.33 4 2.89 3.22 ...
##  $ covid_neg: int  0 0 0 0 0 0 0 0 0 0 ...
##  $ covid_pos: int  0 0 0 0 0 0 0 0 0 0 ...
# 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, pswq))

# 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
## covid_pos    1 1166 1.93 3.34    0.0    1.17 0.00   0 15.00 15.00  1.71
## covid_neg    2 1166 1.13 1.83    0.0    0.77 0.00   0  8.00  8.00  1.40
## pswq         3 1166 2.77 0.80    2.8    2.77 0.93   1  4.94  3.94 -0.03
##           kurtosis   se
## covid_pos     2.01 0.10
## covid_neg     0.81 0.05
## pswq         -0.79 0.02
# 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$covid_pos)

hist(d$covid_neg)

hist(d$pswq)

# 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$covid_pos, d$covid_neg)

plot(d$covid_pos, d$pswq)

plot(d$covid_neg, d$pswq)

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

sum(d2$covid_pos < -3 | d2$covid_pos > 3)
## [1] 30
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] 10
d2$pswq <- scale(d2$pswq,center=T, scale=T)
hist(d2$pswq)

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

5.2 Issues with My Data

One of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, Positive effects of COVID-19 had high kurtosis (2.01) and 30 outliers. Another variable, Negative effects of COVID-19 had 10 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction.

6 Run a Single Correlation

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

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$covid_pos, y = d2$covid_neg)
## Correlation matrix 
##      [,1]
## [1,] 0.66
## Sample Size 
## [1] 1166
## 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 
##           covid_pos covid_neg pswq
## covid_pos      1.00      0.66 0.10
## covid_neg      0.66      1.00 0.21
## pswq           0.10      0.21 1.00
## Sample Size 
## [1] 1166
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           covid_pos covid_neg pswq
## covid_pos         0         0    0
## covid_neg         0         0    0
## pswq              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 positive effects of COVID-19, negative effects of COVID-19 , and general worry would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. One of the variables (general worry) met the required assumptions of the test, with both meeting the standards of normality and containing no outliers. One variable, positive effects of COVID-19, had high kurtosis (2.01) and 31 outliers. Another variable, negative effects of COVID-19 had 10 outliers.

As predicted, we found that all three variables were significantly correlated (all ps were <0.001). The effect sizes of all correlations were all different. The relationshup between positive and negative effects of COVID-19 was strong (r > .50; Cohen, 1988). The relationship between positive effects of COVID-19 and general worry was weak, and so was negative effects of COVID-19 and general worry (r < .29; Cohen, 1988). Additionally, positive effects of COVID-19 was found to be positively related to negative effects of COVID-19 and general worry, contrary to the prediction. Negative effects of COVID-19 was positively related to general worry, 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
Positive effects of COVID-19 1.93 3.34
Negative effects of COVID-19 1.13 1.83 .66**
[.62, .69]
General Worry 2.77 0.80 .10** .21**
[.04, .16] [.15, .26]
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.