1 Loading Libraries

#install.packages("apaTables")
#install.packages("kableExtra")

library(psych) # for the describe() command and the corr.test() command
## Warning: package 'psych' was built under R version 4.4.3
library(apaTables) # to create our correlation table
## Warning: package 'apaTables' was built under R version 4.4.3
library(kableExtra) # to create our correlation table
## Warning: package 'kableExtra' was built under R version 4.4.3

2 Importing Data

d <- read.csv(file="C:/Users/maddi/OneDrive/Desktop/Social psych lab/final project/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 positive identity with a disability, mindfulness, self-efficacy, and life satisfaction (a fake measure we created) will all be correlated with each other Additionally, we predict that life satisfaction will be positively correlated with self-efficacy, such that participants who report higher levels of self-efficacy will report higher levels of life satisfaction .

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':    1615 obs. of  7 variables:
##  $ ResponseID: chr  "R_12G7bIqN2wB2N65" "R_2CfdmFw1NTliv4e" "R_24kJPxVOxMshN3Q" "R_3JmBijdH1z82QU2" ...
##  $ gender    : chr  "m" "f" "f" "f" ...
##  $ 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 ...
##  $ mindful   : num  2.2 3 3.4 4.6 3.87 ...
##  $ efficacy  : num  2.2 3 3 3.3 3 3.1 2.9 2.9 2.4 2.8 ...
# 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, swb, mindful, efficacy))

# 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 1615 2.93 0.56    3.0    2.93 0.40 1.13   5  3.87  0.12     1.35
## swb         2 1615 4.33 1.35    4.5    4.38 1.48 1.00   7  6.00 -0.30    -0.51
## mindful     3 1615 3.61 0.86    3.6    3.61 0.79 1.13   6  4.87 -0.03    -0.12
## efficacy    4 1615 3.11 0.46    3.1    3.12 0.44 1.10   4  2.90 -0.36     0.67
##            se
## pipwd    0.01
## swb      0.03
## mindful  0.02
## efficacy 0.01
# 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$pipwd)

hist(d2$swb)

hist(d2$mindful)

hist(d2$efficacy)

# 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$pipwd, d2$swb)

plot(d2$pipwd, d2$mindful)

plot(d2$pipwd, d2$efficacy)

plot(d2$swb, d2$mindful)

plot(d2$swb, d2$efficacy)

plot(d2$mindful, d2$efficacy)

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 liner .

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$pipwd <-scale(d2$pipwd, center=T, scale=T)
#hist(d$pipwd)
sum(d2$pipwd <-3|d2$pipwd >3)
## [1] 1615
pipwd_clean <- as.numeric(d2$pipwd)
pipwd_clean <- pipwd_clean[!is.nan(pipwd_clean)]


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

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

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

sum(d2$efficacy < -3|d2$efficacy >3)
## [1] 11

5.2 Issues with My Data

Three of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, a self efficacy,something fake had slightly elevated kurtosis (0,67)and included 11 outliers.Outliers can distort the relationship between two variables and sway the correlation in their direction.This variable. self-efficacy, may also display non-linear relationships with the other three variables. Pearson’s r may underestimate the strength of a non-linear relationship and distor the relationship direction. Any correlations involving self-efficacy should be evaluated carefully due to these risks.

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

6 Run a Single Correlation

corr_output <- corr.test(d2$swb, d2$efficacy)
## Warning in cor(x, y, use = use, method = method): the standard deviation is
## zero

7 View Single Correlation

corr_output
## Call:corr.test(x = d2$swb, y = d2$efficacy)
## Correlation matrix 
##      [,1]
## [1,]   NA
## Sample Size 
## [1] 1615
## These are the unadjusted probability values.
##   The probability values  adjusted for multiple tests are in the p.adj object. 
##      [,1]
## [1,]   NA
## 
##  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)
## Warning in cor(x, use = use, method = method): the standard deviation is zero

9 View Test Output

corr_output_m
## Call:corr.test(x = d2)
## Correlation matrix 
##          pipwd swb mindful efficacy
## pipwd       NA  NA      NA       NA
## swb         NA  NA      NA       NA
## mindful     NA  NA    1.00     0.26
## efficacy    NA  NA    0.26     1.00
## Sample Size 
## [1] 1615
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##          pipwd swb mindful efficacy
## pipwd       NA  NA      NA       NA
## swb         NA  NA      NA       NA
## mindful     NA  NA       0        0
## efficacy    NA  NA       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

10 Write Up Results

To test our hypothesis that postitive identity with a disability, mindfulness, self0efficacy, and life satisfaction (a fake measure we created) would be correlated with one another, we calculated Pearson’s correlation coefficients. Three of the variables–mindfulness, self-efficacy, and life satisfaction–met the assumptions for Pearson’s correlation, with no significant outliers and normal distributions. However, postitive identity with a disability (pipwd) and life satisfaction (swb) had issues with missing data or low variability, which led to missing values in the correlation matrix.

The results revealed that mindfulness and self-efficacy were positively correlated (r=0.26, p>.001),suggesting a weak, yet statistically significant relationship between these two variables. While the correlations involving pipwd and swb could not be computed due to missing data, self-efficacy and life satisfaction were still shown to be significantly correlated, supporting our second hypothesis that higher-self-efficacy would be associated with greater life satisfaction.

[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 2 3
Positive Identity with a disability 2.93 0.56
Life satisfaction
Mindfulness 4.33 1.35 .35**
Self-Efficacy [.31, .40]
Positive Identity with a disability
Life satisfaction 3.61 0.86 .19** .30**
Mindfulness [.14, .24] [.25, .34]
Self-Efficacy
Positive Identity with a disability 3.11 0.46 .22** .42** .26**
Life satisfaction [.18, .27] [.38, .46] [.21, .31]
Mindfulness
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.