Correlation HW

Author

Kate Curtis

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(gender, age))

State Your Hypotheses - PART OF YOUR WRITEUP

We predict that subjective well being, mindfulness awareness, and need to belong will all be positively correlated, and all three variables will be negatively correlated with social media use.

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

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

sum(d$mindful< -3 | d$mindful > 3)
[1] 1
d$belong <- scale(d$belong, center=T, scale=T)
hist(d$belong)

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

sum(d$socmeduse< -3 | d$socmeduse > 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$swb, d$mindful) 

#linear
plot(d$swb, d$belong)

#nonlinear 
plot(d$swb, d$socmeduse)

#nonlinear 

plot(d$mindful, d$belong)

#nonlinear
plot(d$mindful, d$socmeduse)

#nonlinear

plot(d$belong, d$socmeduse)

#linear 

Check Your Variables

describe(d)
          vars    n mean sd median trimmed  mad   min  max range  skew kurtosis
swb          1 2156    0  1   0.05    0.04 1.12 -2.59 1.93  4.52 -0.35    -0.50
mindful      2 2156    0  1   0.02    0.01 0.94 -3.07 2.71  5.79 -0.04    -0.15
belong       3 2156    0  1  -0.02    0.03 0.98 -3.15 2.95  6.09 -0.27    -0.09
socmeduse    4 2156    0  1   0.09    0.03 0.86 -2.71 2.41  5.12 -0.30     0.20
            se
swb       0.02
mindful   0.02
belong    0.02
socmeduse 0.02
 # also use histograms to examine your continuous variables
hist(d$swb)

hist(d$mindful)

hist(d$belong)

hist(d$socmeduse)

Issues with My Data - PART OF YOUR WRITEUP

There were ouliers in the data. The mindfulness awareness scale had 1 outlier, and the need to belong scale had 2 outliers. There was some non-linearity between a few of the variables. Subjective well being and need to belong were non-linear, as well as subjective well being and social media use, mindfulness and need to belong, and finally mindfulness and social media use. There was no skew or kurtosis in the data.

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$swb, d$mindful)

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$swb, y = d$mindful)
Correlation matrix 
     [,1]
[1,] 0.29
Sample Size 
[1] 2156
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 
            swb mindful belong socmeduse
swb        1.00    0.29  -0.15      0.09
mindful    0.29    1.00  -0.22     -0.12
belong    -0.15   -0.22   1.00      0.27
socmeduse  0.09   -0.12   0.27      1.00
Sample Size 
[1] 2156
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
          swb mindful belong socmeduse
swb         0       0      0         0
mindful     0       0      0         0
belong      0       0      0         0
socmeduse   0       0      0         0

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

Write Up Results

We predicted that subjective well being, mindfulness awareness, and need to belong will all be positively correlated, and all three variables will be negatively correlated with social media use. There were ouliers in the data. The mindfulness awareness scale had 1 outlier, and the need to belong scale had 2 outliers. There was some non-linearity between a few of the variables. Subjective well being and need to belong were non-linear, as well as subjective well being and social media use, mindfulness and need to belong, and finally mindfulness and social media use. There was no skew or kurtosis in the data. The first part of our hypothesis that subjective well being, mindfulness awareness, and need to belong would all be positively correlated was not supported, subjective well being and need to belong, and need to belong and mindfulness were negatively correlated, see Table 1. The second part of our hypothesis was also not supported, social media use was positively correlated with subjective well being and need to belong, see Table 1. The results were all stistically significant, (p <.001). The effect sizes between subjective well being and between need to belong and social media use were weak. Lastly, the effect sizes between the rest of the variables were trivial (Choen, 1998).

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2 3
Subjective Well Being -0.00 1.00
Mindfulness Attention Awareness -0.00 1.00 .29**
[.25, .33]
Need to Belong -0.00 1.00 -.15** -.22**
[-.19, -.11] [-.26, -.18]
Social Media Use 0.00 1.00 .09** -.12** .27**
[.05, .13] [-.16, -.07] [.23, .31]
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.