1 Loading Libraries

#install.packages("apaTables")
#install.packages("kableExtra")

library(psych) # for the describe() command and the corr.test() command
## Warning: package 'psych' was built under R version 4.5.3
library(apaTables) # to create our correlation table
## Warning: package 'apaTables' was built under R version 4.5.3
library(kableExtra) # to create our correlation table
## Warning: package 'kableExtra' was built under R version 4.5.3

2 Importing Data

d <- read.csv(file="projectdata.csv")
# For HW, import the your project dataset you cleaned previously; this will be the dataset you'll use throughout the rest of the semester

3 State Your Hypothesis

I predict there will be a significant relationship between satisfaction with life, narcissism, and maturity. Specifically, satisfaction with life will be negatively related to narcissism, but positively related to maturity.

4 Check Your Variables

str(d)
## 'data.frame':    3126 obs. of  7 variables:
##  $ ResponseID  : chr  "R_BJN3bQqi1zUMid3" "R_2TGbiBXmAtxywsD" "R_12G7bIqN2wB2N65" "R_39pldNoon8CePfP" ...
##  $ sibling     : chr  "at least one sibling" "at least one sibling" "at least one sibling" "at least one sibling" ...
##  $ edu         : chr  "2 Currently in college" "5 Completed Bachelors Degree" "2 Currently in college" "2 Currently in college" ...
##  $ npi         : num  0.6923 0.1538 0.0769 0.0769 0.7692 ...
##  $ swb         : num  4.33 4.17 1.83 5.17 3.67 ...
##  $ moa_maturity: num  3.67 3.33 3.67 3 3.67 ...
##  $ efficacy    : num  3.4 3.4 2.2 2.8 3 2.4 2.3 3 3 3.7 ...
# Since we're focusing only on our continuous variables, we're going to subset them into their own dataframe. This will make some stuff we're doing later on easier.

d2 <- subset(d, select=c(swb, npi, 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
## swb             1 3126 4.47 1.32   4.67    4.53 1.48   1   7     6 -0.36
## npi             2 3126 0.28 0.31   0.15    0.24 0.23   0   1     1  0.94
## moa_maturity    3 3126 3.59 0.43   3.67    3.65 0.49   1   4     3 -1.20
##              kurtosis   se
## swb             -0.46 0.02
## npi             -0.69 0.01
## moa_maturity     1.87 0.01
# also use histograms to examine your continuous variables
# Because we are looking at 3 variables, we will have 3 histograms.

hist(d$swb)

hist(d$npi)

hist(d$moa_maturity)

# last, use scatterplots to examine your continuous variables together, for each pairing
# because we are looking at 3 variables, we will have 3 pairings/plots. 

plot(d$swb, d$npi)

plot(d$swb, d$moa_maturity)

plot(d$npi, 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: For correlations, you will NOT screen out outliers or take any action based on what you see here. This is something you will simply check and then discuss in your write-up.We will learn how to removed outliers in later analyses.

# We are going to standardize (z-score) all of our 3 variables, and check them for outliers.

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

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

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

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

5.2 Issues with My Data

Two of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, maturity, had a relatively high kurtosis (1.87) and 22 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction.

6 Run a Single Correlation

corr_output <- corr.test(d2$swb, d2$npi)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$swb, y = d2$npi)
## Correlation matrix 
##      [,1]
## [1,] 0.03
## Sample Size 
## [1] 3126
## These are the unadjusted probability values.
##   The probability values  adjusted for multiple tests are in the p.adj object. 
##      [,1]
## [1,] 0.07
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option

8 Create a Correlation Matrix

corr_output_m <- corr.test(d2)

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##               swb   npi moa_maturity
## swb          1.00  0.03         0.12
## npi          0.03  1.00        -0.08
## moa_maturity 0.12 -0.08         1.00
## Sample Size 
## [1] 3126
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##               swb  npi moa_maturity
## swb          0.00 0.07            0
## npi          0.07 0.00            0
## moa_maturity 0.00 0.00            0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option
# Remember to report the p-values from the matrix that are ABOVE the diagonal!

Remember, Pearson’s r is also an effect size! We don’t report effect sizes for non-sig correlations.

  • 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|

10 Write Up Results

To test my hypothesis that life satisfaction, narcissism, and maturity would be correlated with one another, I calculated a series of Pearson’s correlation coefficients. Two of the variables (satisfaction with life and narcissim) met the required assumptions of the test, with both meeting the standards of normality and containing no outliers. One variable, maturity, had a relatively high kurtosis (1.87) and 22 outliers; so any significant results involving maturity should be evaluated carefully.

Unlike I predicted, I found that only two variables were correlated, maturity & satisfaction with life. The p values of maturity & satisfaction with life and maturity & narcissism were <.001. Unlike I predicted, narcissism & satisfaction with life do not appear to be strongly correlated, due to a P value of .07.

Maturity & narcissism and narcissism & satisfaction with life both had trival effect sizes (rs .08 & .03; Cohen, 1988). Maturity & satisfaction with life have a weak correlation 0f .12. Please refer to the correlation coefficients reported in Table 1.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2
Satisfaction With Life 4.47 1.32
Narcissism 0.28 0.31 .03
[-.00, .07]
Maturity 3.59 0.43 .12** -.08**
[.09, .16] [-.12, -.05]
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.