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 independence, role, maturity, and safety will all be correlated with each other. We predict that maturity will be positively correlated with independence and safety.

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':    2036 obs. of  6 variables:
##  $ race_rc         : chr  "white" "white" "white" "other" ...
##  $ age             : chr  "1 between 18 and 25" "1 between 18 and 25" "1 between 18 and 25" "1 between 18 and 25" ...
##  $ moa_independence: num  3.67 3.67 3.5 3 3.83 ...
##  $ moa_role        : num  3 2.67 2.5 2 2.67 ...
##  $ moa_safety      : num  2.75 3.25 3 1.25 2.25 2.5 4 3.25 2.75 3.5 ...
##  $ moa_maturity    : num  3.67 3.33 3.67 3 3.67 ...
# 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,moa_role,moa_safety,moa_maturity))

# 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 2036 3.54 0.46   3.67    3.61 0.49 1.00   4  3.00 -1.49
## moa_role            2 2036 2.97 0.72   3.00    3.00 0.74 1.00   4  3.00 -0.33
## moa_safety          3 2036 3.21 0.65   3.25    3.27 0.74 1.00   4  3.00 -0.70
## moa_maturity        4 2036 3.61 0.43   3.67    3.67 0.49 1.33   4  2.67 -1.24
##                  kurtosis   se
## moa_independence     2.74 0.01
## moa_role            -0.81 0.02
## moa_safety          -0.09 0.01
## moa_maturity         1.74 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$moa_role)

hist(d2$moa_safety)

hist(d2$moa_maturity)

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

plot(d$moa_independence, d$moa_safety)

plot(d$moa_independence, d$moa_maturity)

plot(d$moa_role, d$moa_safety)

plot(d$moa_role, d$moa_maturity)

plot(d$moa_safety, d$moa_maturity)

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

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

sum(d2$moa_safety < -3 | d2$moa_safety > 3)
## [1] 14
d2$moa_maturity <- scale(d2$moa_maturity, center=T, scale=T)
hist(d2$moa_maturity)

sum(d2$moa_maturity < -3 | d2$moa_maturity > 3)
## [1] 14

5.2 Issues with My Data

All but one of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, a fake measure of something fake (FKE-3) had high kurtosis (3.75) and had 31 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. This variable 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 my fake measure of fakeness should be evaluated carefully due to these risks.

6 Run a Single Correlation

corr_output <- corr.test(d2$moa_independence, d2$moa_role)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$moa_independence, y = d2$moa_role)
## Correlation matrix 
##      [,1]
## [1,] 0.64
## Sample Size 
## [1] 2036
## 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 moa_role moa_safety moa_maturity
## moa_independence             1.00     0.64       0.30         0.39
## moa_role                     0.64     1.00       0.38         0.37
## moa_safety                   0.30     0.38       1.00         0.37
## moa_maturity                 0.39     0.37       0.37         1.00
## Sample Size 
## [1] 2036
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##                  moa_independence moa_role moa_safety moa_maturity
## moa_independence                0        0          0            0
## moa_role                        0        0          0            0
## moa_safety                      0        0          0            0
## moa_maturity                    0        0          0            0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

10 Write Up Results

To test our hypothesis that independence, role, safety, and maturity would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Most of uur data met the assumptions of the test, with all variables meeting the standards of normality and no outliers.

Unlike predicted, we found that only one variable was significantly correlated (all ps < .001). Three variables were moderately correlated. The effect sizes of all correlations were large (rs > .5; Cohen, 1988). This test also supported our second hypothesis, that maturity will be positively correlated with independence and safety, 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
Perceived independence -0.00 1.00
role -0.00 1.00 .64**
[.61, .66]
safety -0.00 1.00 .30** .38**
[.26, .34] [.34, .41]
maturity -0.00 1.00 .39** .37** .37**
[.35, .42] [.33, .41] [.33, .41]
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.