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

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 there will be a significant relationship between overall worry, pandemic anxiety, and resilience. Specifically, overall worry will be positively related to pandemic anxiety and negatively related to resilience; and pandemic anxiety will be negatively related to resilience.

4 Check Your Variables

# it's always a good idea to look them to be sure that everything is correct
str(d)
## 'data.frame':    290 obs. of  7 variables:
##  $ X        : int  7888 7365 8747 7357 8760 8654 8272 8738 7911 8463 ...
##  $ education: chr  "2 equivalent to high school completion" "1 equivalent to not completing high school" "2 equivalent to high school completion" "2 equivalent to high school completion" ...
##  $ mhealth  : chr  "none or NA" "none or NA" "none or NA" "none or NA" ...
##  $ pswq     : num  3.43 2.14 1.57 1.43 1.5 ...
##  $ pas_covid: num  4.44 3.11 3.22 1.78 2.78 ...
##  $ brs      : num  2 3.83 3.83 4 4.67 ...
##  $ support  : num  4.83 5 4.83 3.33 4.83 ...
# 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(pswq, pas_covid, brs))

# 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
## pswq         1 290 2.91 0.68   3.00    2.95 0.74 1.14   4  2.86 -0.43    -0.62
## pas_covid    2 290 3.35 0.64   3.44    3.37 0.66 1.00   5  4.00 -0.40     0.71
## brs          3 290 2.66 0.87   2.67    2.66 0.99 1.00   5  4.00  0.10    -0.64
##             se
## pswq      0.04
## pas_covid 0.04
## brs       0.05
# also use histograms to examine your continuous variables
# Because we are looking at 3 variables, we will have 3 histograms.

hist(d$pswq)

hist(d$pas_covid)

hist(d$brs)

# 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$pswq, d$pas_covid)

plot(d$pswq, d$brs)

plot(d$pas_covid, d$brs)

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

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

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

5.2 Issues with My Data

Two of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, pandemix anxiety, although it had skew and kurotsis within normal range, had 2 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$pswq, d2$pas_covid)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$pswq, y = d2$pas_covid)
## Correlation matrix 
##      [,1]
## [1,]  0.3
## Sample Size 
## [1] 290
## 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 
##            pswq pas_covid   brs
## pswq       1.00       0.3 -0.58
## pas_covid  0.30       1.0 -0.30
## brs       -0.58      -0.3  1.00
## Sample Size 
## [1] 290
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           pswq pas_covid brs
## pswq         0         0   0
## pas_covid    0         0   0
## brs          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 overall worry, pandemic anxiety, and resilience would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Two of the variables (overall worry and resilience) met the required assumptions of the test, with both meeting the standards of normality and containing no outliers. One variable, pandemic anxiety, had skew and kurtosis within the normal range, but had 2 outliers; so any significant results involving fakeness should be evaluated carefully.

As predicted, we found that all three variables were significantly correlated (all ps < .001). The effect sizes of the correlations between pandemic anxiety with both overall worry and resilience were moderate (rs = .30; Cohen, 1988). The effect size of the correlation of pandemic anxiety and resilience was strong (rs > .50; Cohen, 1988). Additionally, overalll worry was found to be positively related to pandemic anxiety and negatively related to resilience, as predicted. Pandemic anxiety was also, as predicted, negatively related to resilience. 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
Overall worry 2.91 0.68
Pandemic Anxiety 3.35 0.64 .30**
[.19, .40]
Resilience 2.66 0.87 -.58** -.30**
[-.65, -.50] [-.40, -.19]
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.