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

I predict that social media use and mindfullness be correlated with each other. Additionally, we predict that social media use will be negatively correlated with mindfulness, such that participants who report higher social media use will report lower mindfulness.

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!


# 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':    854 obs. of  7 variables:
##  $ ResponseID  : chr  "R_12G7bIqN2wB2N65" "R_3lLnoV2mYVYHFvf" "R_1gTNDGWsqikPuEX" "R_3G1XvswZmPZTkMU" ...
##  $ gender      : chr  "m" "f" "f" "f" ...
##  $ disability  : chr  "psychiatric" "other" "learning" "psychiatric" ...
##  $ mindful     : num  2.2 1.6 1.8 4.27 3.4 ...
##  $ socmeduse   : int  34 37 26 23 35 30 40 34 38 42 ...
##  $ efficacy    : num  2.2 3.1 2.9 3.1 2.8 2.9 3.3 1.9 2.7 3 ...
##  $ moa_maturity: num  3.67 2 4 3.67 3.67 ...
# 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(mindful, socmeduse))

# 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
## mindful      1 854  3.47 0.84   3.47    3.48 0.79  1.13  5.67  4.53 -0.05
## socmeduse    2 854 34.17 8.62  35.00   34.43 7.41 11.00 55.00 44.00 -0.30
##           kurtosis   se
## mindful      -0.18 0.03
## socmeduse     0.20 0.30
# 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$mindful)

hist(d2$socmeduse)

# 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$mindful, d2$socmeduse)

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

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

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

5.2 Issues with My Data

Both of my variables meet all of the assumptions of Pearson’s correlation coefficient. I checked for outlines and there was none. I also checked for kurtosis and it was good for social media use and mindfulness.

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

6 Run a Single Correlation

corr_output <- corr.test(d2$mindful, d2$socmeduse)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$mindful, y = d2$socmeduse)
## Correlation matrix 
##       [,1]
## [1,] -0.05
## Sample Size 
## [1] 854
## These are the unadjusted probability values.
##   The probability values  adjusted for multiple tests are in the p.adj object. 
##      [,1]
## [1,] 0.11
## 
##  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 
##           mindful socmeduse
## mindful      1.00     -0.05
## socmeduse   -0.05      1.00
## Sample Size 
## [1] 854
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##           mindful socmeduse
## mindful      0.00      0.11
## socmeduse    0.11      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 soical media use and mindfulness would be negetively correlated with one another, we calculated a series of Pearson’s correlation coefficients. Both of the variables (mindfulness and social media use) met the required assumptions of the test, with both meeting the standards of normality and containing no outliers.

As predicted, we found that mindfulness and social media use were negetively correlated though the relationship was not statistically significant (r = -0.05, p = .11). This result does not support our hypothesis that higher levels of mindfulness would be associated with lower social media use. The effect size of this correlation was small, indicating a weak (rs > .29; Cohen, 1988).relationship between these variables, 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
Mindfulness 3.47 0.84
Social Media Use 34.17 8.62 -.05
[-.12, .01]
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.