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 openness, intolerance of uncertainty, self esteem and perceived stress will all be correlated. Additionally, we predict that self-esteem will be negatively correlated with perceived stress, such that participants with higher self-esteem will report lower levels of perceived stress.

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':    1252 obs. of  7 variables:
##  $ X         : int  1 20 30 31 33 49 57 81 86 104 ...
##  $ gender    : chr  "female" "male" "female" "female" ...
##  $ employment: chr  "3 employed" "1 high school equivalent" "1 high school equivalent" "3 employed" ...
##  $ big5_open : num  5.33 5.33 5 6 5 ...
##  $ iou       : num  3.19 4 1.59 3.37 1.7 ...
##  $ rse       : num  2.3 1.6 3.9 1.7 3.9 2.4 1.8 3.5 2.6 3 ...
##  $ pss       : num  3.25 3.75 1 3.25 2 2 4 1.25 2.5 2.5 ...
# 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(big5_open, iou, rse, pss))

# 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_open    1 1252 5.25 1.12   5.33    5.34 0.99   1   7     6 -0.74     0.43
## iou          2 1252 2.57 0.91   2.41    2.51 0.99   1   5     4  0.49    -0.60
## rse          3 1252 2.62 0.72   2.70    2.64 0.74   1   4     3 -0.21    -0.73
## pss          4 1252 2.95 0.95   3.00    2.95 1.11   1   5     4  0.06    -0.76
##             se
## big5_open 0.03
## iou       0.03
## rse       0.02
## pss       0.03
# 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_open)

hist(d$iou)

hist(d$rse)

hist(d$pss)

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

plot(d$big5_open, d$iou)

plot(d$big5_open, d$rse)

plot(d$big5_open, d$pss)

plot(d$iou, d$rse)

plot(d$iou, d$pss)

plot(d$rse, d$pss)

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

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

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

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

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

5.2 Issues with My Data

Three of my variables—big5_open, iou, and rse—meet all of the assumptions of Pearson’s correlation coefficient. They are fairly normally distributed, with minimal skew and kurtosis (ranging from -0.74 to 0.49 for skew and -0.73 to 0.43 for kurtosis). Additionally, each variable has a low number of outliers, with only big5_open showing six standardized values beyond three standard deviations. The variable pss also meets assumptions overall, with a skew of 0.06 and kurtosis of -0.76, indicating a reasonably normal distribution.

Given these distributions, Pearson’s r is suitable for assessing correlations among big5_open, iou, rse, and pss, as they appear linear and do not have excessive outliers that would skew the results. However, while all variables are mostly normal, any findings, especially with big5_open, should be interpreted cautiously due to its slightly higher outlier count. Still, these variables largely align with Pearson’s assumptions, supporting the reliability of correlation estimates in this analysis.

[Make sure to revise the above paragraph for your HW.]

6 Run a Single Correlation

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

7 View Single Correlation

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

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 
##           big5_open   iou   rse   pss
## big5_open      1.00 -0.09  0.10 -0.04
## iou           -0.09  1.00 -0.66  0.64
## rse            0.10 -0.66  1.00 -0.74
## pss           -0.04  0.64 -0.74  1.00
## Sample Size 
## [1] 1252
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           big5_open iou rse  pss
## big5_open      0.00   0   0 0.11
## iou            0.00   0   0 0.00
## rse            0.00   0   0 0.00
## pss            0.11   0   0 0.00
## 
##  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 big5_open, iou, rse, and pss would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Three of the variables (big5_open, iou, and rse) met the required assumptions of the test, with all three meeting standards of normality and containing minimal outliers. However, pss showed slight deviations with a kurtosis below -0.7, but overall was still reasonably normal for analysis.

As predicted, we found significant correlations among most of the variables. Specifically, iou and pss showed a strong positive correlation (r = 0.64, p < .001), while rse and pss were strongly negatively correlated (r = -0.74, p < .001). Other correlations were smaller, such as between big5_open and rse (r = 0.10, p < .001). All correlations, except for that between big5_open and pss (p = .11), were statistically significant, as shown in Table 1. These results support our hypothesis that iou, rse, and pss would correlate strongly, with large effect sizes observed for these variables (Cohen’s conventions for r).Our secondary hypothesis—that higher pss scores (indicating perceived stress) would correlate with lower rse (self-esteem) scores—was also supported, as indicated by the strong negative correlation between these two variables.

[In your HW, revise the above two paragraphs to fit your results. Make sure to discuss ALL predicted correlations and if sig or not.]

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Openness 5.25 1.12
Intolerance of Uncertainty 2.57 0.91 -.09**
[-.14, -.03]
Self-esteem 2.62 0.72 .10** -.66**
[.05, .15] [-.69, -.63]
Perceived stress 2.95 0.95 -.04 .64** -.74**
[-.10, .01] [.60, .67] [-.76, -.71]
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

Robins, R. W., Hendin, H. M., & Trzesniewski, K. H. (2001). Measuring Global Self-Esteem:Construct Validation of a Single-Item Measure and the Rosenberg Self-Esteem Scale.Personality and Social Psychology Bulletin, 27(2), 151-161.

Cohen, S., Kamarck, T., & Mermelstein, R. (1983). A Global Measure of Perceived Stress.Journal of Health and Social Behavior, 24(4), 385-396.