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

There will be a significant relationship between Positive Identity as a Person With a Disability, perceived stress, and social support. Specifically, psychosocial impact of disability will be positively related to stress and negatively related to social support.

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':    1616 obs. of  7 variables:
##  $ ResponseID: chr  "R_12G7bIqN2wB2N65" "R_2CfdmFw1NTliv4e" "R_24kJPxVOxMshN3Q" "R_3JmBijdH1z82QU2" ...
##  $ race_rc   : chr  "white" "white" "multiracial" "white" ...
##  $ party_rc  : chr  "apolitical" "democrat" "democrat" "apolitical" ...
##  $ pipwd     : num  2.33 3.53 3 3 3.13 ...
##  $ swb       : num  1.83 5.5 5 4.67 3 ...
##  $ support   : num  5.17 6.08 6 6 6 ...
##  $ stress    : num  4 2.4 2.9 3.5 2.5 3.5 4.4 2.8 1.8 3.6 ...
# 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(pipwd, stress, 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 kurtosis
## pipwd      1 1616 2.94 0.56   3.00    2.93 0.40 1.13 5.0  3.87  0.12     1.36
## stress     2 1616 3.13 0.61   3.10    3.12 0.59 1.40 4.7  3.30  0.02    -0.19
## support    3 1616 5.43 1.16   5.67    5.54 1.11 0.00 7.0  7.00 -1.00     1.08
##           se
## pipwd   0.01
## stress  0.02
## support 0.03
# NOTE: If you have high skew or kurtosis for any of your project variables, you will need to discuss it below in the Issues with My Data and Write up Results sections, as well as in your final project manuscript if your data does not meet the normality assumption.


# also use histograms to examine your continuous variables
# Because we are looking at 3 variables, we will have 3 histograms.

hist(d$pipwd)

hist(d$stress)

hist(d$support)

# last, use scatterplots to examine your continuous variables together, for each pairing
# because we are looking at 3 variables, we will have 3 pairings/plots. 

plot(d$pipwd, d$stress)

plot(d$pipwd,d$support)

plot(d$stress, 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: For correlations, you will NOT screen out outliers or take any action based on what you see here. This is something you will simply check and then discuss in your write-up.We will learn how to removed outliers in later analyses.

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

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

sum(d2$pipwd < -3 | d2$pipwd > 3)
## [1] 15
d2$stress <- scale(d2$stress, center=T, scale=T)
hist(d2$stress)

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

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

5.2 Issues with My Data

Two of my variables, Positive Identity as a Person With a Disability and Stress meet all of the assumptions of Pearson’s correlation coefficient. One variable, support, had some skew (-1.00) and kurtosis (1.08) and 21 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. This variable, support, appears to have linear relationships with the other two variables though. Any correlations with support should be evaluated carefully due to these risks.

6 Run a Single Correlation

corr_output <- corr.test(d2$pipwd, d2$stress)

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$pipwd, y = d2$stress)
## Correlation matrix 
##       [,1]
## [1,] -0.31
## Sample Size 
## [1] 1616
## 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

corr_output_m <- corr.test(d2)

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##         pipwd stress support
## pipwd    1.00  -0.31    0.20
## stress  -0.31   1.00   -0.22
## support  0.20  -0.22    1.00
## Sample Size 
## [1] 1616
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##         pipwd stress support
## pipwd       0      0       0
## stress      0      0       0
## support     0      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!

Remember, Pearson’s r is also an effect size! We don’t report effect sizes for non-sig correlations.

  • 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|

10 Write Up Results

To test our hypothesis that Positive Identity as a Person With a Disability, Percieved Stress, and Percieved Social Support, would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. All three variables met assumptions of linearity and normality. However, Positive Identity had 15 outliers, and Perceived Social Support had a skew of 1.00 and kurtosis of 1.08, with 21 outliers, so results involving Social Support should be evaluated carefully.

As we predicted, we found that all three variables were significantly correlated (all ps < .001). The effect sizes of all correlations were small to moderate (rs > .20; Cohen, 1988). Opposite to what we predicted though due to a misinterpretation in variable framing/wording, Positive Identity as a Person With a Disability was found to be negatively related to stress (r = –.31) and positively related to social support (r = .20). Please refer to the correlation coefficients reported in Table 1.

Table 1: Means, standard deviations, and correlations with confidence intervals
Variable M SD 1 2
Positive Identity as a Person With a Disability 2.94 0.56
Percieved Stress 3.13 0.61 -.31**
[-.36, -.27]
Perceived Support 5.43 1.16 .20** -.22**
[.15, .24] [-.27, -.18]
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.