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

3 State Your Hypothesis

We predict that moa_maturity (Markers of Adulthood on maturity), idea (Inventory of the dimensions of emerging adulthood), support (multidimensional sclae of received social support), and npi (Narcissistic Personality Inventory) will all be correlated with each other. Furthermore, we predict that npi will be lower in participants who are higher in support or higher moa_maturity.

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':    3111 obs. of  6 variables:
##  $ gender      : chr  "f" "m" "m" "f" ...
##  $ income      : chr  "1 low" "1 low" "rather not say" "rather not say" ...
##  $ moa_maturity: num  3.67 3.33 3.67 3 3.67 ...
##  $ idea        : num  3.75 3.88 3.75 3.75 3.5 ...
##  $ support     : num  6 6.75 5.17 5.58 6 ...
##  $ npi         : num  0.6923 0.1538 0.0769 0.0769 0.7692 ...
# we're going to create a fake variable for this lab, so that it has four variables and mirrors the homework assignment. SKIP THIS STEP FOR THE HOMEWORK


# 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_maturity,idea,support,npi))

# 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_maturity    1 3111 3.59 0.43   3.67    3.65 0.49   1   4     3 -1.20
## idea            2 3111 3.58 0.38   3.62    3.62 0.37   1   4     3 -1.53
## support         3 3111 5.54 1.12   5.75    5.66 0.99   0   7     7 -1.10
## npi             4 3111 0.28 0.31   0.15    0.24 0.23   0   1     1  0.94
##              kurtosis   se
## moa_maturity     1.90 0.01
## idea             4.48 0.01
## support          1.44 0.02
## npi             -0.69 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_maturity)

hist(d2$idea)

hist(d2$support)

hist(d2$npi)

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

plot(d2$moa_maturity, d2$support)

plot(d2$moa_maturity, d2$npi)

plot(d2$idea, d2$support)

plot(d2$idea, d2$npi)

plot(d2$support, d2$npi)

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$moa_maturity_std <- scale(d$moa_maturity, center=T, scale=T)
hist(d$moa_maturity_std)

sum(d$moa_maturity_std < -3 | d$moa_maturity_std > 3)
## [1] 23
d$idea_std <- scale(d$idea, center=T, scale=T)
hist(d$idea_std)

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

sum(d$support_std < -3 | d$support_std > 3)
## [1] 42
d$npi_std <- scale(d$npi, center=T, scale=T)
hist(d$npi_std)

sum(d$npi_std < -3 | d$npi_std > 3)
## [1] 0

5.2 Issues with My Data

All my variables didn’t meet all of the assumptions of Pearson’s correlation coefficient. None of them distributed normally, and one relationship is not linear (The moa_maturity and npi). Also, Three of them have many outliers: moa_maturity (23 outliers), idea (34 outliers), support (42 outliners). Outliers can distort the relationship between two variables and sway the correlation in their direction. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction. I should be evaluateall of my data 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 
##              moa_maturity idea support   npi
## moa_maturity         1.00 0.15    0.11 -0.09
## idea                 0.15 1.00    0.12  0.01
## support              0.11 0.12    1.00 -0.02
## npi                 -0.09 0.01   -0.02  1.00
## Sample Size 
## [1] 3111
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##              moa_maturity idea support  npi
## moa_maturity            0 0.00    0.00 0.00
## idea                    0 0.00    0.00 0.46
## support                 0 0.00    0.00 0.41
## npi                     0 0.46    0.21 0.00
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

8 Write Up Results

To test our hypothesis that moa_maturity (Markers of Adulthood on maturity), idea (Inventory of the dimensions of emerging adulthood), support (multidimensional scale of received social support), and npi (Narcissistic Personality Inventory) would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Most of our data did not met the assumptions of the test, with most of the variables meeting the standards of normality and no outliers. Despite the presence of outliners in moa_maturity, idea, and support, no outliners were detected for npi. I found that most of my variables were significantly correlated (the idea and npi; support and npi are two correlation that are not significantly correlated). The effect sizes of all correlations were small (rs < .3; Cohen, 1988). This test does not supported our second hypothesis. The correlation between support and npi was very week and not statistically significant, which does not strongly support the prediction that higher support is associated with lower npi scores.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
moa_maturity(Markers of Adulthood) 3.59 0.43
idea(Inventory of the dimensions of emerging adulthood) 3.58 0.38 .15**
[.12, .19]
support(Multidimensionalsclae of received social support) 5.54 1.12 .11** .12**
[.07, .14] [.09, .16]
npi(Narcissistic Personality Inventory) 0.28 0.31 -.09** .01 -.02
[-.12, -.05] [-.02, .05] [-.06, .01]
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.