r Sys.Date(){r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE)
{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
{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)
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.
```{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)
d\(fake <- (d\)pss*d\(phq)/d\)rse
d2 <- subset(d, select=c(pss, phq,rse,fake))
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
hist(d2\(pss) hist(d2\)phq) hist(d2\(rse) hist(d2\)fake)
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)
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.
```{r} corr_output <- corr.test(d2\(pss, d2\)phq) corr_output <- corr.test(d2\(pss, d2\)rse)
# View Single Correlation
```{r}
corr_output
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)
{r} corr_output_m
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)
table_out2$Variable <- c(“Perceived stress (PSS-4)”, ““,”Depression symptoms (PHQ-9)“,”“,”“,”Self-esteem (RSE-10)“,”“,”“,”Fake (FKE-3)“,”“,”“)
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.