[MATH-814] Added Kendalls correlation to R testcases.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1537664 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2013-10-31 21:17:09 +00:00
parent 3631295c43
commit 9c23ce3fd1
1 changed files with 36 additions and 2 deletions

View File

@ -51,6 +51,17 @@ verifySpearmansCorrelation <- function(matrix, expectedCorrelation, name) {
} }
} }
# Verify Kendall's correlation
verifyKendallsCorrelation <- function(matrix, expectedCorrelation, name) {
correlation <- cor(matrix, method="kendall")
output <- c("Kendall's Correlation matrix test dataset = ", name)
if (assertEquals(expectedCorrelation, correlation,tol,"Kendall's Correlations")) {
displayPadded(output, SUCCEEDED, WIDTH)
} else {
displayPadded(output, FAILED, WIDTH)
}
}
# function to verify p-values # function to verify p-values
verifyPValues <- function(matrix, pValues, name) { verifyPValues <- function(matrix, pValues, name) {
dimension <- dim(matrix)[2] dimension <- dim(matrix)[2]
@ -145,6 +156,19 @@ expectedCorrelation <- matrix(c(
nrow = 7, ncol = 7, byrow = TRUE) nrow = 7, ncol = 7, byrow = TRUE)
verifySpearmansCorrelation(longley, expectedCorrelation, "longley") verifySpearmansCorrelation(longley, expectedCorrelation, "longley")
# Kendall's
expectedCorrelation <- matrix(c(
1, 0.9166666666666666, 0.9333333333333332, 0.3666666666666666, 0.05, 0.8999999999999999,
0.8999999999999999, 0.9166666666666666, 1, 0.9833333333333333, 0.45, 0.03333333333333333,
0.9833333333333333, 0.9833333333333333, 0.9333333333333332, 0.9833333333333333, 1,
0.4333333333333333, 0.05, 0.9666666666666666, 0.9666666666666666, 0.3666666666666666,
0.45, 0.4333333333333333, 1, -0.2166666666666666, 0.4666666666666666, 0.4666666666666666, 0.05,
0.03333333333333333, 0.05, -0.2166666666666666, 1, 0.05, 0.05, 0.8999999999999999, 0.9833333333333333,
0.9666666666666666, 0.4666666666666666, 0.05, 1, 0.9999999999999999, 0.8999999999999999,
0.9833333333333333, 0.9666666666666666, 0.4666666666666666, 0.05, 0.9999999999999999, 1),
nrow = 7, ncol = 7, byrow = TRUE)
verifyKendallsCorrelation(longley, expectedCorrelation, "longley")
# Swiss Fertility --------------------------------------------------------- # Swiss Fertility ---------------------------------------------------------
fertility <- matrix(c(80.2,17.0,15,12,9.96, fertility <- matrix(c(80.2,17.0,15,12,9.96,
83.1,45.1,6,9,84.84, 83.1,45.1,6,9,84.84,
@ -222,4 +246,14 @@ expectedCorrelation <- matrix(c(
nrow = 5, ncol = 5, byrow = TRUE) nrow = 5, ncol = 5, byrow = TRUE)
verifySpearmansCorrelation(fertility, expectedCorrelation, "swiss fertility") verifySpearmansCorrelation(fertility, expectedCorrelation, "swiss fertility")
# Kendall's
expectedCorrelation <- matrix(c(
1, 0.1795465254708308, -0.4762437404200669, -0.3306111613580587, 0.2453703703703704,
0.1795465254708308, 1, -0.4505221560842292, -0.4761645631778491, 0.2054604569820847,
-0.4762437404200669, -0.4505221560842292, 1, 0.528943683925829, -0.3212755391722673,
-0.3306111613580587, -0.4761645631778491, 0.528943683925829, 1, -0.08479652265379604,
0.2453703703703704, 0.2054604569820847, -0.3212755391722673, -0.08479652265379604, 1),
nrow = 5, ncol = 5, byrow = TRUE)
verifyKendallsCorrelation(fertility, expectedCorrelation, "swiss fertility")
displayDashes(WIDTH) displayDashes(WIDTH)