rum <- read.csv("ruminationComplete.csv", na.string = "99") ## Imports the data into R
rum_scores <- rum %>% mutate(rumination = rowSums(across(CRQS1:CRSQ13)),
depression = rowSums(across(CDI1:CDI26))) ### I'm calculating
## total scores
corr <- cor(rum_scores$rumination, rum_scores$depression,
use = "pairwise.complete.obs") ## Correlation between rumination and depression
### Let's create a distribution of null correlations
nsim <- 100000
cor.c <- vector(mode = "numeric", length = nsim)
for(i in 1:nsim){
depre <- sample(rum_scores$depression,
212,
replace = TRUE)
rumia <- sample(rum_scores$rumination,
212,
replace = TRUE)
cor.c[i] <- cor(depre, rumia, use = "pairwise.complete.obs")
}
hist(cor.c, breaks = 120,
xlim= c(min(cor.c), 0.70),
main = "Histograma of null correlations")
abline(v = corr, col = "darkblue", lwd = 2, lty = 1)
abline(v = c(quantile(cor.c, .025),quantile(cor.c, .975) ),
col= "red",
lty = 2,
lwd = 2)