I am trying to create a function in R to find a correlation coefficient for n-dimensional non-zero-variance variables using the equation seen at the bottom of this image: Click Here
So far, I have only made the example data-set I am working with:
a <- c(4, 6, 2, 5)
b <- c(8, 1, 3, 7)
c <- c(6, 3, 1, 3)
d <- c(7, 5, 7, 5)
e <- c(9, 2, 6, 1)
f <- c(4, 6, 4, 5)
al <- data.frame(a, b, c, d, e, f)
al
But I am having trouble incorporating the equation into the rest of my code.I know how to make a correlation matrix:
corrmatrix <- cor(al)
head(round(corrmatrix,3))
But I don't know if that should be where I start off or if I can work with the original data-set. I guess the math behind the equation is what is holding me back. For example: How do I use the "det()" function? Is there a function for getting the standardized vector of a variable?
Thank you in advance for any assistance!