1 Loading Libraries

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

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

d <- read.csv(file="Data/projectdata.csv", header=T)

# 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

We predict that maturity, need to belong, self efficacy, and narcissism will all be correlated with each other. Additionally, we predict that maturity will be negatively correlated with narcissism, such that participants who report higher levels of narcissism will report lower maturity.

4 Check Your Variables

# you only need to check the variables you're using in the current analysis
# it's always a good idea to look them to be sure that everything is correct
str(d)
## 'data.frame':    2132 obs. of  7 variables:
##  $ ResponseId  : chr  "R_BJN3bQqi1zUMid3" "R_2TGbiBXmAtxywsD" "R_12G7bIqN2wB2N65" "R_39pldNoon8CePfP" ...
##  $ age         : chr  "1 between 18 and 25" "1 between 18 and 25" "1 between 18 and 25" "1 between 18 and 25" ...
##  $ gender      : chr  "f" "m" "m" "f" ...
##  $ moa_maturity: num  3.67 3.33 3.67 3 3.67 ...
##  $ belong      : num  2.8 4.2 3.6 4 3.4 4.2 3.9 3.6 2.9 2.5 ...
##  $ efficacy    : num  3.4 3.4 2.2 2.8 3 2.4 2.3 3 3 3.7 ...
##  $ npi         : num  0.6923 0.1538 0.0769 0.0769 0.7692 ...
# 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(moa_maturity, belong, efficacy, 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 2132 3.61 0.43   3.67    3.67 0.49 1.33   4  2.67 -1.23
## belong          2 2132 3.21 0.61   3.20    3.23 0.59 1.30   5  3.70 -0.27
## efficacy        3 2132 3.11 0.44   3.10    3.12 0.44 1.20   4  2.80 -0.19
## npi             4 2132 0.27 0.30   0.15    0.23 0.23 0.00   1  1.00  1.00
##              kurtosis   se
## moa_maturity     1.71 0.01
## belong          -0.10 0.01
## efficacy         0.36 0.01
## npi             -0.56 0.01
# NOTE: Our fake variable has high kurtosis, which we'll ignore for the lab. 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 project manuscript.

# also use histograms to examine your continuous variables

hist(d$moa_maturity)

hist(d$belong)

hist(d$efficacy)

hist(d$npi)

# last, use scatterplots to examine your continuous variables together, for each pairing

plot(d$moa_maturity, d$belong)

plot(d$moa_maturity, d$efficacy)

plot(d$moa_maturity, d$npi)

plot(d$belong, d$efficacy)

plot(d$belong, d$npi)

plot(d$efficacy, d$npi)

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.

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

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

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

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

sum(d2$npi< -3 | d2$npi > 3)
## [1] 0

5.2 Issues with My Data

All of my variables are continuous and normally distributed. Three of my variables have outliers, maturity, need to belong, and self efficacy. Maturity had 16, need to belong had 2, and self efficacy had 10. Outliers can distort the relationship between two variables and sway the correlation in their direction.It does not appear that any of the relationships between the variables are linear. 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.

[Make sure to revise the above paragraph for your HW.]

6 Run a Single Correlation

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

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$moa_maturity, y = d2$npi)
## Correlation matrix 
##       [,1]
## [1,] -0.08
## Sample Size 
## [1] 2132
## 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|

Remember, Pearson’s r is also an effect size!

corr_output_m <- corr.test(d2)

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##              moa_maturity belong efficacy   npi
## moa_maturity         1.00  -0.02     0.17 -0.08
## belong              -0.02   1.00    -0.27 -0.06
## efficacy             0.17  -0.27     1.00  0.15
## npi                 -0.08  -0.06     0.15  1.00
## Sample Size 
## [1] 2132
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##              moa_maturity belong efficacy  npi
## moa_maturity         0.00   0.34        0 0.00
## belong               0.34   0.00        0 0.02
## efficacy             0.00   0.00        0 0.00
## npi                  0.00   0.01        0 0.00
## 
##  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

10 Write Up Results

To test our hypothesis that maturity, need to belong, self efficacy, and narcissism would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. None of the variables completley met the required assumptions of the test, with 3 of the variables have outliers and none of the variables having a linear relationship with each other so any significant results from any of these varaibles should be evaluated carefully.

All of our variables were significantly correlated except for maturity and need to belong as the p value for all correlations were <0.05 and the p value for maturity and need to belong was (0.34). The effect size for maturity and all other variables was small (-0.02)belong (0.17)efficacy (-0.08)npi. The effect size between need to belong and all other variables was small (-0.27)efficacy (-0.06)npi. All of the effect sizes were small. Our second hypothesis was supported as it was significant and the p value was 0.00. The effect size between the two was small (0.00)

[In your HW, revise the above two paragraphs to fit your results. Make sure to discuss ALL predicted correlations and if sig or not.]

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
maturity 3.61 0.43
need to belong scale 3.21 0.61 -.02
[-.06, .02]
general self efficacy scale 3.11 0.44 .17** -.27**
[.13, .21] [-.31, -.23]
narcissistic personality inventory 0.27 0.30 -.08** -.06** .15**
[-.12, -.03] [-.10, -.02] [.11, .20]
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.