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 extroversion, worry, loneliness, and support will all be correlated with each other. Additionally, we predict support will be negatively correlated with loneliness, such that participants who report higher levels of support will report lower levels of loneliness.

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':    349 obs. of  7 variables:
##  $ X                  : int  1 31 49 57 86 113 133 179 190 208 ...
##  $ relationship_status: chr  "In a relationship/married and cohabiting" "In a relationship/married and cohabiting" "In a relationship/married and cohabiting" "In a relationship/married and cohabiting" ...
##  $ mhealth            : chr  "none or NA" "none or NA" "none or NA" "anxiety disorder" ...
##  $ big5_ext           : num  2 5 5.67 4 5.33 ...
##  $ pswq               : num  4.94 3.94 2.94 2.81 3.5 ...
##  $ isolation_a        : num  2.25 2.5 2 1.25 3 1 1 2.75 2.75 1 ...
##  $ support            : num  2.5 2.5 3.83 4.17 1.33 ...
# 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(big5_ext, pswq, isolation_a, support))

# 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
## big5_ext       1 349 4.64 1.34   4.67    4.70 1.48 1.33 7.00  5.67 -0.35
## pswq           2 349 2.89 0.87   2.88    2.87 0.93 1.12 4.94  3.81  0.14
## isolation_a    3 349 1.68 0.71   1.50    1.59 0.74 1.00 3.50  2.50  0.90
## support        4 349 3.86 0.88   4.00    3.94 0.74 1.00 5.00  4.00 -0.80
##             kurtosis   se
## big5_ext       -0.68 0.07
## pswq           -0.82 0.05
## isolation_a    -0.28 0.04
## support         0.13 0.05
# also use histograms to examine your continuous variables

hist(d$big5_ext)

hist(d$pswq)

hist(d$isolation_a)

hist(d$support)

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

plot(d$big5_ext, d$pswq)

plot(d$big5_ext, d$isolation_a)

plot(d$big5_ext, d$support)

plot(d$pswq, d$isolation_a)

plot(d$pswq, d$support)

plot(d$isolation_a, d$support)

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

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

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

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

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

5.2 Issues with My Data

Four of my variables meet all of the assumptions of Pearson’s correlation coefficient. I had no outliers. But, 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.

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

6 Run a Single Correlation

corr_output <- corr.test(d2$support, d2$isolation_a)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$support, y = d2$isolation_a)
## Correlation matrix 
##       [,1]
## [1,] -0.61
## Sample Size 
## [1] 349
## 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 
##             big5_ext  pswq isolation_a support
## big5_ext        1.00 -0.12       -0.09    0.25
## pswq           -0.12  1.00        0.26   -0.20
## isolation_a    -0.09  0.26        1.00   -0.61
## support         0.25 -0.20       -0.61    1.00
## Sample Size 
## [1] 349
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##             big5_ext pswq isolation_a support
## big5_ext        0.00 0.05        0.11       0
## pswq            0.03 0.00        0.00       0
## isolation_a     0.11 0.00        0.00       0
## support         0.00 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

10 Write Up Results

To test our hypothesis that extroversion, worry, loneliness, and support would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. All 4 of the variables met the required assumptions of the test, with all four meeting the standards of normality and containing no outliers.

We found partial support to my first hypothesis. We found that three variables were significantly correlated (all ps < .05).The effect sizes of 4 correlations were weak. These correlations were: extroversion and worry (r = .12), extroversion and support (r=.25), worry and loneliness (r = .26), and worry and support (r=.20) (rs > .10). The effect size of 1 correlation (support and loneliness) was strong (r = .61 Cohen, 1988) The pair that was not significantly correlated was extroversion and loneliness. Our second hypothesis was also supported, that loneliness would be lower in participants who reported higher levels of support, 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
Extroversion 4.64 1.34
Worry 2.89 0.87 -.12*
[-.22, -.02]
Loneliness 1.68 0.71 -.09 .26**
[-.19, .02] [.16, .36]
Support 3.86 0.88 .25** -.20** -.61**
[.14, .34] [-.30, -.10] [-.67, -.54]
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.