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 stress (measured by the Perceived Stress Questionnaire), importance of independence (measured by the Markers of Adulthood-Importance), satisfaction with life (measured by the Satisfaction with Life Scale), and self-efficacy (measured by the General Self Efficacy Scale) will all be correlated with each other. Furthermore, we predict that self-efficacy will be higher in participants who are lower in stress. We predict that self-efficacy is negatively correlated with stress.

4 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':    2092 obs. of  6 variables:
##  $ age             : chr  "1 between 18 and 25" "1 between 18 and 25" "1 between 18 and 25" "1 between 18 and 25" ...
##  $ income          : chr  "1 low" "1 low" "rather not say" "rather not say" ...
##  $ moa_independence: num  3.67 3.67 3.5 3 3.83 ...
##  $ swb             : num  4.33 4.17 1.83 5.17 3.67 ...
##  $ efficacy        : num  3.4 3.4 2.2 2.8 3 2.4 2.3 3 3 3.7 ...
##  $ stress          : num  3.3 3.3 4 3.2 3.1 3.5 3.3 2.4 2.9 2.7 ...
# 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(moa_independence,swb,efficacy,stress))

# 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
## moa_independence    1 2092 3.54 0.47   3.67    3.61 0.49 1.0 4.0   3.0 -1.49
## swb                 2 2092 4.43 1.33   4.50    4.49 1.48 1.0 7.0   6.0 -0.36
## efficacy            3 2092 3.11 0.44   3.10    3.12 0.44 1.2 4.0   2.8 -0.20
## stress              4 2092 3.07 0.60   3.10    3.07 0.59 1.3 4.6   3.3 -0.02
##                  kurtosis   se
## moa_independence     2.75 0.01
## swb                 -0.49 0.03
## efficacy             0.39 0.01
## stress              -0.15 0.01
# 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$moa_independence)

hist(d2$swb)

hist(d2$efficacy)

hist(d2$stress)

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

plot(d$stress,d$moa_independence)

plot(d$stress,d$swb)

plot(d$efficacy,d$moa_independence)

plot(d$efficacy,d$swb)

plot(d$moa_independence,d$swb)

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.

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

sum(d2$moa_independence < -3 | d2$moa_independence > 3)
## [1] 36
d2$swb <- scale(d2$swb, center=T, scale=T)
hist(d2$swb)

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

sum(d2$efficacy < -3 | d2$efficacy > 3)
## [1] 10
d2$stress <- scale(d2$stress, center=T, scale=T)
hist(d2$stress)

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

5.2 Issues with My Data

All but one of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, independence measured by the Markers of Adulthood had high kurtosis (2.75) and had 36 outliers. The self-efficacy measure had 10 outliers, but the skew and kurtosis showed to be normal. Outliers can distort the relationship between two variables and sway the correlation in their direction. These variables also appears to have non-linear relationships with the other variables. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction. Any correlations with the independence measure and the self-efficacy measure should be evaluated carefully due to these risks.

6 Run a Single Correlation

corr_output <- corr.test(d2$efficacy,d2$stress)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$efficacy, y = d2$stress)
## Correlation matrix 
##      [,1]
## [1,] -0.4
## Sample Size 
## [1] 2092
## 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|

corr_output_m <- corr.test(d2)

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##                  moa_independence   swb efficacy stress
## moa_independence             1.00  0.08     0.09  -0.02
## swb                          0.08  1.00     0.38  -0.50
## efficacy                     0.09  0.38     1.00  -0.40
## stress                      -0.02 -0.50    -0.40   1.00
## Sample Size 
## [1] 2092
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##                  moa_independence swb efficacy stress
## moa_independence             0.00   0        0   0.46
## swb                          0.00   0        0   0.00
## efficacy                     0.00   0        0   0.00
## stress                       0.46   0        0   0.00
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

10 Write Up Results

To test our hypothesis that stress (measured by the Perceived Stress Questionnaire), importance of independence (measured by the Markers of Adulthood-Importance), satisfaction with life (measured by the Satisfaction with Life Scale), and self-efficacy (measured by the General Self Efficacy Scale) 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 all variables meeting the standards of normality and no outliers. Two variables, independence and self-efficacy, did have some outliers and non-linear relationships with the other variables, and so any significant results involving that variable should be evaluated carefully.

We found that not all of the variables correlate with each other. Perceived stress doesn’t correlate with the importance of independence (r=-.02, p=0.46). There is a trivial effect size between the importance of independence and satisfaction with life (r=0.08, p<.001) and self-efficacy (r=0.09, p<.001). There is a moderate effect size between satisfaction with life and self-efficacy (r=0.38, p<.001). There is a strong effect size between perceived stress and satisfaction with life (r=-.5, p<.001). Overall, the effect sizes varied (Cohen, 1988). This test also supported our second hypothesis, that self-efficacy and stress would be negatively correlated (r=-.40, p<.001), as can be seen by the correlation coefficients reported in Table 1.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
moa_independence 0.00 1.00
swb 0.00 1.00 .08**
[.04, .13]
efficacy 0.00 1.00 .09** .38**
[.05, .13] [.34, .41]
stress 0.00 1.00 -.02 -.50** -.40**
[-.06, .03] [-.53, -.46] [-.44, -.37]
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.