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 Self-Esteem, Intolerance of Uncertainty, Neuroticism, and Generalized Anxiety Disorder will all be correlated with mental health disorder status . Additionally, we predict that intolerance of uncertainty will be postively correlated with neuroticism, such that participants who report higher levels of intolerance of uncertainty will report higher levels of neuroticism .

4 Check Your Variables

# We're going to create a fake variable for this lab, so that we have four variables. 

# NOTE: YOU WILL SKIP THIS STEP FOR THE HOMEWORK!

d$gad <- (d$rse * d$iou)/d$big5_open 

# 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':    1225 obs. of  7 variables:
##  $ X                 : int  1 321 401 469 520 1390 1422 2183 2247 2482 ...
##  $ sexual_orientation: chr  "Heterosexual/Straight" "Heterosexual/Straight" "Heterosexual/Straight" "Heterosexual/Straight" ...
##  $ mhealth           : chr  "none or NA" "none or NA" "obsessive compulsive disorder" "depression" ...
##  $ big5_open         : num  5.33 4 6 5 3.67 ...
##  $ iou               : num  3.19 2.48 2.81 2.59 2.22 ...
##  $ rse               : num  2.3 3.8 3.1 3 2.6 3 1.3 3 3.2 1.8 ...
##  $ gad               : num  1.37 2.36 1.45 1.56 1.58 ...
# 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(gad, rse, iou, big5_open))

# 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
## gad          1 1225 1.29 0.62   1.16    1.21 0.40 0.37 9.88  9.51  3.93
## rse          2 1225 2.63 0.72   2.70    2.65 0.74 1.00 4.00  3.00 -0.22
## iou          3 1225 2.56 0.90   2.41    2.51 0.99 1.00 5.00  4.00  0.50
## big5_open    4 1225 5.25 1.13   5.33    5.33 0.99 1.00 7.00  6.00 -0.73
##           kurtosis   se
## gad          35.93 0.02
## rse          -0.73 0.02
## iou          -0.58 0.03
## big5_open     0.44 0.03
# 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

# because we are looking at 4 variables, we will have 4 histograms. You may not have this many for your HW. Make as many as you need to reflect your hypothesis.

hist(d2$gad)

hist(d2$rse)

hist(d2$iou)

hist(d2$big5_open)

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

# because we are looking at 4 variables, we will have 6 pairings/plots. You may not have this many for your HW. Make as many as you need to reflect your hypothesis.

plot(d2$big5_open, d2$iou)

plot(d2$big5_open, d2$gad)

plot(d2$big5_open, d$rse)

plot(d2$iou, d2$gad)

plot(d2$iou, d2$rse)

plot(d2$gad, d2$rse)

5 Check Your Assumptions

5.1 Pearson’s Correlation Coefficient Assumptions

  • Should have two for each participant.
  • Variables should be continuous and normally distributed.
  • Outliers should be identified and removed.
  • Relationship between the variables should be liner .

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 always check and then discuss in your write-up.

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

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

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

sum(d2$big5_open < -3 | d2$big5_open > 3)
## [1] 6
d2$rse <- scale(d2$rse, center= T, scale= T)
hist(d2$rse)

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

sum(d2$gad < -3 | d2$gad > 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, a fake measure of something fake had high kurtosis (#) and had 6 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. This variable, …, also appears to have … relationships with the other three 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 … 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$iou, d2$big5_open)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$iou, y = d2$big5_open)
## Correlation matrix 
##       [,1]
## [1,] -0.09
## Sample Size 
## [1] 1225
## 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 
##             gad   rse   iou big5_open
## gad        1.00  0.08  0.38     -0.66
## rse        0.08  1.00 -0.66      0.10
## iou        0.38 -0.66  1.00     -0.09
## big5_open -0.66  0.10 -0.09      1.00
## Sample Size 
## [1] 1225
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##            gad  rse iou big5_open
## gad       0.00 0.01   0         0
## rse       0.01 0.00   0         0
## iou       0.00 0.00   0         0
## big5_open 0.00 0.00   0         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

10 Write Up Results

To test our hypothesis that GAD, RSE, BIG5, and IOU would be correlated with another, we calculated a series of Pearson’s correlation coefficients. Two of the variables (IOU, and RSE) met the required assumptions of the test, with all three meeting the standards of normality and containing no outliers . Two variables, GAD, had #22 and BIG5 had 6 outliers as well as nonlinear relationships with the other variables; so any significant results involving fakeness should be evaluated carefully.

As predicted, we found that all four were significantly correlated (all ps < .001). The effect sizes were a mix (rs > #; Cohen, 1988). Our second hypothesis was supported, that IOU would be higher in participants who reported higher levels of BIG5, as can be seen by the correlation coefficients reported in Table 1.

[In your HW, revise the above two paragraphs to fit your results. Make sure to discuss ALL predicted correlations and whether supported or not. Always report the Pearson’s r and p-value for any prediction.]

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Self-Esteem 1.29 0.62
Intolerance of Uncertainty 2.63 0.72 .08**
[.02, .13]
Big 5 Neuroticism 5.25 1.13 -.66** .10**
[-.69, -.62] [.05, .16]
Generalized Anxiety Disorder 2.56 0.90 .38** -.66** -.09**
[.33, .42] [-.69, -.63] [-.14, -.03]
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.