{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE)

1 Loading Libraries

{r} 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

{r} # import the dataset you cleaned previously # this will be the dataset you'll use throughout the rest of the semester # use ARC data downloaded previous for lab d <- read.csv(file="Data/arc_clean.csv", header=T)

3 State Your Hypothesis

We predict that stress (measured by the PSS-4), depression symptoms (measured by the PHQ-9), self-esteem (measured by the RSE-10), and fakeness (a fake measure from the fake FKE-3) will all be correlated with each other. Furthermore, we predict that self-esteem will be lower in participants who are higher in stress or who report more symptoms of depression. We predict that self esteem will be negatively correlated with stress and depression.

4 Check Your Variables

```{r} # you only need to check the variables you’re using in the current analysis # although you checked them previously, it’s always a good idea to look them over again and be sure that everything is correct str(d)

5 we’re going to create a fake variable for this lab, so that it has four variables and mirrors the homework assignment. SKIP THIS STEP FOR THE HOMEWORK

d\(fake <- (d\)pss*d\(phq)/d\)rse

6 since we’re focusing on our continuous variables, we’re going to subset them into their own dataframe. this will make some stuff we’re doing later easier.

d2 <- subset(d, select=c(pss, phq,rse,fake))

7 you can use the describe() command on an entire dataframe (d) or just on a single variable (d$pss)

describe(d2) # our fake variable has high kurtosis, which I’ll ignore. 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 manuscript

8 also use histograms to examine your continuous variables

hist(d2\(pss) hist(d2\)phq) hist(d2\(rse) hist(d2\)fake)

9 last, use scatterplots to examine your continuous variables together

plot(d\(pss, d\)phq) plot(d\(pss, d\)rse) plot(d\(pss, d\)fake)

plot(d\(phq, d\)fake) plot(d\(phq, d\)rse)

plot(d\(rse, d\)fake)




# Check Your Assumptions

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

### 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 check and then discuss in your write-up.

```{r}
d2$pss <- scale(d2$pss, center=T, scale=T)
hist(d2$pss)
sum(d2$pss < -3 |d2$pss > 3)

d2$phq <- scale(d2$phq, center=T, scale=T)
hist(d2$phq)
sum(d2$phq < -3 |d2$phq > 3)

d2$rse <- scale(d2$rse, center=T, scale=T)
hist(d2$rse)
sum(d2$rse < -3 |d2$rse > 3)

d2$fake <- scale(d2$fake, center=T, scale=T)
hist(d2$fake)
sum(d2$fake < -3 |d2$fake > 3)

9.1 Issues with My Data

All but one of my variables meet all of the assumptions of Pearson’s correlation coefficient. One variable, a fake measure of something fake (FKE-3) had high kurtosis (3.75) and had 31 outliers. Outliers can distort the relationship between two variables and sway the correlation in their direction. This variable also appears to have non-linear relationships with the other variables. Pearson’s r may underestimate the strength of a non-linear relationship and distort the relationship direction. Any correlations with my fake measure of fakeness should be evaluated carefully due to these risks.

10 Run a Single Correlation

```{r} corr_output <- corr.test(d2\(pss, d2\)phq) corr_output <- corr.test(d2\(pss, d2\)rse)


# View Single Correlation
```{r}
corr_output

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

{r} corr_output_m <- corr.test(d2)

12 View Test Output

{r} corr_output_m

13 Write Up Results

To test our hypothesis that stress (measured by the PSS-4), depression symptoms (measured by the PHQ-9), self-esteem (measured by the RSE-10), and fakeness (a fake measure FKE-3) would be correlated with one another, we calculated a series of Pearson’s correlation coefficients. Most of uur data met the assumptions of the test, with all variables meeting the standards of normality and no outliers. One variable, fakeness, did have outliers and non-linear relationships with the other variables, and so any significant results involving that variable should be evaluated carefully.

As predicted, we found that all three variables were significantly correlated (all ps < .001). The effect sizes of all correlations were large (rs > .5; Cohen, 1988). This test also supported our second hypothesis, that self-esteem would be lower in participants who are higher in stress or who report more symptoms of depression, as can be seen by the correlation coefficients reported in Table 1.

```{r echo=FALSE, message=FALSE, warning=FALSE} # you do not have to make any changes to the next two lines UNLESS you changed the name of the dataframe with your continuous variables table_out <- apa.cor.table(d2, filename = “table1.doc”, table.number = 1) table_out2 <- as.data.frame(table_out$table.body)

14 you need to update this section with better descriptions of your variables. you can use the full name of the scale, or brief descriptions along with the scale abbreviation as I have.

15 make sure you enter the variables here in the same order they appear in your d dataframe. you can use the names() command to double-check the order

16 also make sure you don’t change any of the code – all you should be doing is updating the variable descriptions! changing anything else will cause R to throw an error

table_out2$Variable <- c(“Perceived stress (PSS-4)”, ““,”Depression symptoms (PHQ-9)“,”“,”“,”Self-esteem (RSE-10)“,”“,”“,”Fake (FKE-3)“,”“,”“)

17 you don’t need to make any changes to the remainder of the code

as.data.frame(table_out2) %>% kbl(row.names = F, align = c(“l”, “c”, “c”, “c”, “c”, “c”), caption = paste(“Table”,table_out\(table.number,": ",table_out\)table.title, sep=““), format =”html”, table.attr = “style=‘width: 75%;’”) %>% kable_classic() %>% footnote( general = “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.”, symbol = c(“indicates p < .05”, “indicates p < .01.”), symbol_manual = c(“*“,”**“), threeparttable = T) ```

References

Cohen J. (1988). Statistical Power Analysis for the Behavioral Sciences. New York, NY: Routledge Academic.