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 satisfaction with life and role transitions will be correlated with each other. Furthermore, we predict that satisfaction with life will be higher in participants who are higher in need for belonging. Similarly, we predict that higher scores from the maturity scale will correlate with higher role transition scores.

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':    3075 obs. of  6 variables:
##  $ gender      : chr  "f" "m" "m" "f" ...
##  $ marriage5   : chr  "are currently divorced from one another" "are currently married to one another" "are currently married to one another" "are currently married to one another" ...
##  $ moa_role    : num  3 2.67 2.5 2 2.67 ...
##  $ moa_maturity: num  3.67 3.33 3.67 3 3.67 ...
##  $ swb         : num  4.33 4.17 1.83 5.17 3.67 ...
##  $ belong      : num  2.8 4.2 3.6 4 3.4 4.2 3.9 3.6 2.9 2.5 ...
# 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(belong, swb, moa_maturity, moa_role))

# 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
## belong          1 3075 3.23 0.61   3.30    3.25 0.59 1.3   5   3.7 -0.27
## swb             2 3075 4.47 1.32   4.67    4.53 1.48 1.0   7   6.0 -0.37
## moa_maturity    3 3075 3.59 0.43   3.67    3.65 0.49 1.0   4   3.0 -1.20
## moa_role        4 3075 2.97 0.72   3.00    3.00 0.74 1.0   4   3.0 -0.33
##              kurtosis   se
## belong          -0.13 0.01
## swb             -0.45 0.02
## moa_maturity     1.89 0.01
## moa_role        -0.85 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$belong)

hist(d2$swb)

hist(d2$moa_maturity)

hist(d2$moa_role)

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

plot(d$belong, d$moa_maturity)

plot(d$belong, d$moa_role)

plot(d$swb, d$moa_maturity)

plot(d$swb, d$moa_role)

plot(d$moa_maturity, d$moa_role)

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

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

sum(d2$swb < -3 | d2$swb > 3)
## [1] 0
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] 21
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

5.2 Issues with My Data

All but two of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, need for belonging, had 7 outliers, while another variable, maturity, had 21 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$belong, d2$swb)
corr_output <- corr.test(d2$moa_maturity, d2$moa_role)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$moa_maturity, y = d2$moa_role)
## Correlation matrix 
##      [,1]
## [1,] 0.36
## Sample Size 
## [1] 3075
## 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 
##              belong   swb moa_maturity moa_role
## belong         1.00 -0.14         0.00     0.06
## swb           -0.14  1.00         0.13     0.17
## moa_maturity   0.00  0.13         1.00     0.36
## moa_role       0.06  0.17         0.36     1.00
## Sample Size 
## [1] 3075
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##              belong swb moa_maturity moa_role
## belong         0.00   0         0.98        0
## swb            0.00   0         0.00        0
## moa_maturity   0.98   0         0.00        0
## moa_role       0.00   0         0.00        0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

10 Write Up Results

To test our hypothesis that satisfaction with life and role transitions will be correlated with each other, that satisfaction with life will be higher in participants who are higher in need for belonging and that higher scores from the maturity scale will correlate with higher role transition scores, 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, need for belonging and maturity, did have outliers, and so any significant results involving that variable should be evaluated carefully.

We found that all variables were significantly correlated (all ps < .001), except between belonging and maturity. The effect sizes of all correlations were weak (.10 < rs < .29; Cohen, 1988) except a moderate effect size between maturity and role transitions. This test also did not support our second hypothesis, that satisfaction with life will be higher in participants who are higher in need for belonging, and supported our third hypothesis, that higher scores from the maturity scale will correlate with higher role transition scores 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
Role Transitions -0.00 1.00
Maturity 0.00 1.00 -.14**
[-.18, -.11]
Life Satisfaction 0.00 1.00 .00 .13**
[-.03, .04] [.09, .16]
Need for Belogning -0.00 1.00 .06** .17** .36**
[.03, .10] [.14, .21] [.33, .39]
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.