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/eammi2_data_cleaned.csv", header=T)

3 State Your Hypothesis

We predict that stress (measured by the PSQ), support (measured by the MSPSS), social well being (measured by the SWLS), and independence (measured by MOA) will all be correlated with each other. # for HW: all four of continuous varibles will be correlated with each other; do not have to specify directionality

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':    3079 obs. of  6 variables:
##  $ race_rc         : chr  "white" "white" "white" "other" ...
##  $ income          : chr  "1 low" "1 low" "rather not say" "rather not say" ...
##  $ stress          : num  3.3 3.3 4 3.2 3.1 3.5 3.3 2.4 2.9 2.7 ...
##  $ support         : num  6 6.75 5.17 5.58 6 ...
##  $ swb             : num  4.33 4.17 1.83 5.17 3.67 ...
##  $ moa_independence: num  3.67 3.67 3.5 3 3.83 ...
# 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(stress,support,swb,moa_independence))

# 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
## stress              1 3079 3.05 0.60   3.00    3.05 0.59 1.3 4.7   3.4  0.04
## support             2 3079 5.54 1.13   5.75    5.66 0.99 0.0 7.0   7.0 -1.12
## swb                 3 3079 4.47 1.32   4.67    4.53 1.48 1.0 7.0   6.0 -0.37
## moa_independence    4 3079 3.54 0.47   3.67    3.61 0.49 1.0 4.0   3.0 -1.44
##                  kurtosis   se
## stress              -0.17 0.01
## support              1.50 0.02
## swb                 -0.45 0.02
## moa_independence     2.51 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$stress)

hist(d2$support)

hist(d2$swb)

hist(d2$moa_independence)

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

plot(d2$stress, d2$swb)

plot(d2$stress, d2$moa_independence) #can say that it could or not be linear- judgement call?? 

plot(d2$support, d2$swb)

plot(d2$support, d2$moa_independence) 

plot(d2$swb, d2$moa_independence)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have one measurement for each score for each participant

In our Data Prep and Basic Stats lab, we dropped any participants with missing data. So we’re good for this assumption!

  • Variables should be continuous and normally distributed

Checked in the section above!

  • Relationship between the variables should be linear

This one is a bit tricky! We’ll talk about it in class; feel free to take notes here.

  • Outliers should be identified and removed

We’ll do this one below.

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.

d$stress_std <- scale(d$stress, center=T, scale=T)
hist(d$stress_std)

sum(d$stress_std < -3 | d$stress_std > 3)
## [1] 0
d$support_std <- scale(d$support, center=T, scale=T)
hist(d$support_std)

sum(d$support_std < -3 | d$support_std > 3)
## [1] 44
## 44 outliers
d$swb_std <- scale(d$swb, center=T, scale=T)
hist(d$swb_std)

sum(d$swb_std < -3 | d$swb_std > 3)
## [1] 0
d$moa_independence_std <- scale(d$moa_independence, center=T, scale=T)
hist(d$moa_independence_std)

sum(d$moa_independence_std < -3 | d$moa_independence_std > 3)
## [1] 51
#51 outliers

5.2 Issues with My Data

Half of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, independence (MOA), had a high kurtosis (2.51) and 51 outliers. Another variable, support (MSPSS), had 41 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. Independence 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 support and independence should be evaluated carefully due to these risks.

6 Create a Correlation Matrix

corr_output_m <- corr.test(d2)

7 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##                  stress support   swb moa_independence
## stress             1.00   -0.21 -0.51            -0.02
## support           -0.21    1.00  0.48             0.10
## swb               -0.51    0.48  1.00             0.10
## moa_independence  -0.02    0.10  0.10             1.00
## Sample Size 
## [1] 3079
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##                  stress support swb moa_independence
## stress             0.00       0   0             0.17
## support            0.00       0   0             0.00
## swb                0.00       0   0             0.00
## moa_independence   0.17       0   0             0.00
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

8 Write Up Results

To test our hypothesis that stress (measured by the PSQ), support (measured by the MSPSS), social well being (measured by the SWLS), and independence (measured by MOA) will all be correlated with each other, we calculated a series of Pearson’s correlation coefficients. Most of our data met the assumptions of the test, with half the variables meeting the standards of normality and no outliers. Two variables, independence and support, did have outliers, and independence also had a high kurtosis (2.51). Independence had a non-linear relationships with the other variables, so any significant results involving that variable should be evaluated carefully.

Our prediction was mostly correct. We found that most our variables were significantly correlated (ps < .001). However, stress and independence were not significantly correlated (p > .001) The effect sizes of all correlations but one were large (rs > .5; Cohen, 1988). Independence and stress had a correlation with a trivial effect size (r < .1).

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Stress (PSQ) 3.05 0.60
Support (MSPSS) 5.54 1.13 -.21**
[-.25, -.18]
Social Well Being (SWLS)) 4.47 1.32 -.51** .48**
[-.53, -.48] [.45, .50]
Independence (MOA)) 3.54 0.47 -.02 .10** .10**
[-.06, .01] [.07, .14] [.07, .14]
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.