Correlation HW

Author

Marley Burchenson

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

Importing Data

d <- read.csv(file="Data/mydata.csv", header=T)
# 
# since we're focusing on our continuous variables, we're going to drop our categorical variables. this will make some stuff we're doing later easier.
d <- subset(d, select=-c(sexual_orientation, mhealth))

State Your Hypotheses - PART OF YOUR WRITEUP

We predict that self-esteem, social support, and mental well-being will be positively correlated, and that all three of these variables will be negatively correlated with intolerance of uncertainty.

Check Your Assumptions

Pearson’s Correlation Coefficient Assumptions

  • Should have two measurements for each participant for each variable (confirmed by earlier procedures – we dropped any participants with missing data)
  • Variables should be continuous and normally distributed, or assessments of the relationship may be inaccurate (will do below)
  • Outliers should be identified and removed, or results will be inaccurate (will do below)
  • Relationship between the variables should be linear, or they will not be detected (will do below)

Checking for Outliers

Outliers can mask potential effects and cause Type II error (you assume there is no relationship when there really is one, e.g., false negative).

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.

# using the scale() command to standardize our variable, viewing a histogram, and then counting statistical outliers
d$rse <- scale(d$rse, center=T, scale=T)
hist(d$rse)

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

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

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

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

Checking for Linear Relationships

Non-linear relationships cannot be detected by Pearson’s correlation (the type of correlation we’re doing here). This means that you may underestimate the relationship between a pair of variables if they have a non-linear relationship, and thus your understanding of what’s happening in your data will be inaccurate.

Visually check that relationships are linear and write a brief description of any potential nonlinearity. You will have to use your judgement. There are no penalties for answering ‘wrong’, so try not to stress out about it too much – just do your best.

# # use scatterplots to examine your continuous variables together
plot(d$rse, d$support)

plot(d$rse, d$swemws)

plot(d$rse, d$iou)

plot(d$support, d$swemws)

plot(d$support, d$iou)

plot(d$iou, d$swemws)

Check Your Variables

describe(d)
        vars    n mean sd median trimmed  mad   min  max range  skew kurtosis
support    1 1140    0  1   0.10    0.06 1.03 -2.68 1.49  4.18 -0.43    -0.57
swemws     2 1140    0  1   0.00    0.03 1.00 -2.53 2.19  4.72 -0.26    -0.29
rse        3 1140    0  1   0.09    0.03 1.03 -2.26 1.89  4.15 -0.24    -0.74
iou        4 1140    0  1  -0.17   -0.07 1.09 -1.71 2.68  4.39  0.51    -0.62
          se
support 0.03
swemws  0.03
rse     0.03
iou     0.03
# 
# # also use histograms to examine your continuous variables
hist(d$rse)

hist(d$support)

hist(d$swemws)

hist(d$iou)

Issues with My Data - PART OF YOUR WRITEUP

We checked to make sure our data met all the assumptions of Pearsons Correlation Coefficient and we found zero outliers indicating that our data is well-suited for Pearson’s correlation analysis. Additionally, all relationships between variables were linear.

Run Pearson’s Correlation

There are two ways to run Pearson’s correlation in R. You can calculate each correlation one-at-a-time using multiple commands, or you can calculate them all at once and report the scores in a matrix. The matrix output can be confusing at first, but it’s more efficient. We’ll do it both ways.

Run a Single Correlation

corr_output <- corr.test(d$rse, d$iou)

View Single Correlation

Strong effect: Between |0.50| and |1|

Moderate effect: Between |0.30| and |0.49|

Weak effect: Between |0.10| and |0.29|

Trivial effect: Less than |0.09|

corr_output
Call:corr.test(x = d$rse, y = d$iou)
Correlation matrix 
      [,1]
[1,] -0.66
Sample Size 
[1] 1140
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

Create a Correlation Matrix

corr_output_m <- corr.test(d)

View Test Output

Strong effect: Between |0.50| and |1|

Moderate effect: Between |0.30| and |0.49|

Weak effect: Between |0.10| and |0.29|

Trivial effect: Less than |0.09|

corr_output_m
Call:corr.test(x = d)
Correlation matrix 
        support swemws   rse   iou
support    1.00   0.60  0.52 -0.43
swemws     0.60   1.00  0.78 -0.65
rse        0.52   0.78  1.00 -0.66
iou       -0.43  -0.65 -0.66  1.00
Sample Size 
[1] 1140
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
        support swemws rse iou
support       0      0   0   0
swemws        0      0   0   0
rse           0      0   0   0
iou           0      0   0   0

 To see confidence intervals of the correlations, print with the short=FALSE option

Write Up Results

As predicted, self-esteem, social support, and mental well-being were positively correlated, while all three variables were negatively correlated with intolerance of uncertainty.

Our data met all assumptions of Pearson’s Correlation Coefficient with zero outliers and a linear relationship between all variables. All significant correlations were in the expected directions indicating moderate to strong effects based on Cohen’s (1988) guidelines.

These findings align with our hypotheses and indicate that greater self-esteem, social support, and mental well-being are associated with lower intolerance of uncertainty, and that is perfectly adequate because all of the actual R values and p values are reported in the table. (See Table 1)

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Social Support 0.00 1.00
Mental Well-being Scale 0.00 1.00 .60**
[.56, .64]
Self-esteem -0.00 1.00 .52** .78**
[.48, .56] [.76, .80]
Intolerance of Uncertainty 0.00 1.00 -.43** -.65** -.66**
[-.48, -.38] [-.69, -.62] [-.69, -.62]
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.