If we want to use the formula, the Xbar
is mean
, sigma
is sum
and sqrt
for the corresponding symbol in the formula
num1 <- sum((X - mean(X))*(Y - mean(Y)))
den1 <- sqrt(sum((X - mean(X))^2) * sum((Y - mean(Y))^2))
num1/den1
[1] -0.599539
-testing with cor
cor(X, Y)
#[1] -0.599539
X <- c(2, 3, 5, 10, 8, 5)
Y <- c(7, 6, 9, 1, 6, 3)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.