Hey all,
I have a quick question, might seem kind of silly but I want to publish my code along with my manuscript for transparency so I want to make sure I'm not making a mistake. So I created a simulated dataframe here, if you want me to reprex I can but if you copy and paste that, it will create the dataframe. So I'm creating a vector, one with a total score and one with a mean score. And my question is, when calculating a partial correlation (or any correlation) in R, do I actually need to generate a mean score beforehand or does R or the pcor.test function handle this automatically. Because if you look at the results when running the p.cor.test values from the total score and mean score, they are identical. Long story short, can I just use the total score in this scenario?
Create a data frame with 15 rows and 5 numeric columns
data <- data.frame(
Column1 = seq(1, 15),
Column2 = rnorm(15),
Column3 = runif(15),
Column4 = rnorm(15, mean = 10, sd = 2),
Column5 = sample(1:100, 15),
Column6 = rnorm(15, mean = 12),
Column7 = rnorm(15),
Column8 = rnorm(15)
)
Calculate Totatscore and Meanscore
data$Totatscore <- data$Column1 + data$Column2 + data$Column3 + data$Column4 + data$Column5
data$Meanscore <- (data$Column1 + data$Column2 + data$Column3 + data$Column4 + data$Column5) / 5
pcor.test(data$Totatscore, data$Column8, list(data$Column6 + data$Column7), method = "pearson")
pcor.test(data$Meanscore, data$Column8, list(data$Column6 + data$Column7), method = "pearson")