Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A532D18E5A for ; Sun, 22 Nov 2015 19:19:14 +0000 (UTC) Received: (qmail 69462 invoked by uid 500); 22 Nov 2015 19:19:09 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 69275 invoked by uid 500); 22 Nov 2015 19:19:09 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 69021 invoked by uid 99); 22 Nov 2015 19:19:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 Nov 2015 19:19:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 41369DFFD9; Sun, 22 Nov 2015 19:19:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: psteitz@apache.org To: commits@commons.apache.org Date: Sun, 22 Nov 2015 19:19:10 -0000 Message-Id: <653b8a7b9e11410ba8400e9f170c0521@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] [math] Removed trailing spaces. Removed trailing spaces. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/23b351c8 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/23b351c8 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/23b351c8 Branch: refs/heads/master Commit: 23b351c89461009a3f772c07edd47a9a2a0b9e7b Parents: 7851a3e Author: Phil Steitz Authored: Sun Nov 22 12:18:46 2015 -0700 Committer: Phil Steitz Committed: Sun Nov 22 12:18:46 2015 -0700 ---------------------------------------------------------------------- src/test/R/ChiSquareDistributionTestCases.R | 8 +-- src/test/R/FDistributionTestCases.R | 8 +-- src/test/R/GammaDistributionTestCases.R | 8 +-- .../R/KolmogorovSmirnovDistributionTestCases.R | 6 +- src/test/R/LevyDistributionTestCases.R | 4 +- src/test/R/README.txt | 72 ++++++++++---------- src/test/R/TDistributionTestCases.R | 8 +-- src/test/R/TTestCases | 20 +++--- src/test/R/WeibullDistributionTestCases.R | 8 +-- src/test/R/anovaTestCases | 8 +-- src/test/R/binomialTestCases | 8 +-- src/test/R/cauchyTestCases.R | 6 +- src/test/R/chiSquareTestCases | 20 +++--- src/test/R/correlationTestCases | 16 ++--- src/test/R/covarianceTestCases | 16 ++--- src/test/R/descriptiveTestCases | 6 +- src/test/R/exponentialTestCases | 8 +-- src/test/R/geometricTestCases | 10 +-- src/test/R/hypergeometricTestCases | 12 ++-- src/test/R/multipleOLSRegressionTestCases | 32 ++++----- src/test/R/normalTestCases | 8 +-- src/test/R/pascalTestCases | 6 +- src/test/R/poissonTestCases | 12 ++-- src/test/R/regressionTestCases | 24 +++---- src/test/R/testAll | 2 +- src/test/R/testFunctions | 6 +- src/test/R/zipfTestCases | 6 +- 27 files changed, 174 insertions(+), 174 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/ChiSquareDistributionTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/ChiSquareDistributionTestCases.R b/src/test/R/ChiSquareDistributionTestCases.R index 78929ef..3df58ba 100644 --- a/src/test/R/ChiSquareDistributionTestCases.R +++ b/src/test/R/ChiSquareDistributionTestCases.R @@ -40,7 +40,7 @@ verifyDistribution <- function(points, expected, df, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify density computations @@ -56,7 +56,7 @@ verifyDensity <- function(points, expected, df, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify quantiles @@ -72,7 +72,7 @@ verifyQuantiles <- function(points, expected, df, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -83,7 +83,7 @@ distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.95 densityValues <- c(0.0115379817652, 0.0415948507811, 0.0665060119842, 0.0919455953114, 0.121472591024, 0.000433630076361, 0.00412780610309, 0.00999340341045, 0.0193246438937, 0.0368460089216) distributionPoints <- c(0.210212602629, 0.554298076728, 0.831211613487, 1.14547622606, 1.61030798696, - 20.5150056524, 15.0862724694, 12.8325019940, 11.0704976935, 9.23635689978) + 20.5150056524, 15.0862724694, 12.8325019940, 11.0704976935, 9.23635689978) verifyQuantiles(distributionValues, distributionPoints, df, tol) verifyDistribution(distributionPoints, distributionValues, df, tol) verifyDensity(distributionPoints, densityValues, df, tol) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/FDistributionTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/FDistributionTestCases.R b/src/test/R/FDistributionTestCases.R index e5f3656..ee7c199 100644 --- a/src/test/R/FDistributionTestCases.R +++ b/src/test/R/FDistributionTestCases.R @@ -40,7 +40,7 @@ verifyDistribution <- function(points, expected, numeratorDf, denominatorDf, tol displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify density computations @@ -56,7 +56,7 @@ verifyDensity <- function(points, expected, numeratorDf, denominatorDf, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify quantiles @@ -72,7 +72,7 @@ verifyQuantiles <- function(points, expected, numeratorDf, denominatorDf, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -84,7 +84,7 @@ distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.95 densityValues <- c(0.0689156576706, 0.236735653193, 0.364074131941, 0.481570789649, 0.595880479994, 0.000133443915657, 0.00286681303403, 0.00969192007502, 0.0242883861471, 0.0605491314658) distributionPoints <- c(0.0346808448626, 0.0937009113303, 0.143313661184, 0.202008445998, 0.293728320107, - 20.8026639595, 8.74589525602, 5.98756512605, 4.38737418741, 3.10751166664) + 20.8026639595, 8.74589525602, 5.98756512605, 4.38737418741, 3.10751166664) verifyQuantiles(distributionValues, distributionPoints, numeratorDf, denominatorDf, tol) verifyDistribution(distributionPoints, distributionValues, numeratorDf, denominatorDf, tol) verifyDensity(distributionPoints, densityValues, numeratorDf, denominatorDf, tol) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/GammaDistributionTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/GammaDistributionTestCases.R b/src/test/R/GammaDistributionTestCases.R index 7cbefda..2ed7c95 100644 --- a/src/test/R/GammaDistributionTestCases.R +++ b/src/test/R/GammaDistributionTestCases.R @@ -40,7 +40,7 @@ verifyDistribution <- function(points, expected, alpha, beta, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify density computations @@ -56,7 +56,7 @@ verifyDensity <- function(points, expected, alpha, beta, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify quantiles @@ -72,7 +72,7 @@ verifyQuantiles <- function(points, expected, alpha, beta, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -84,7 +84,7 @@ distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.95 densityValues <- c(0.00427280075546, 0.0204117166709, 0.0362756163658, 0.0542113174239, 0.0773195272491, 0.000394468852816, 0.00366559696761, 0.00874649473311, 0.0166712508128, 0.0311798227954) distributionPoints <- c(0.857104827257, 1.64649737269, 2.17973074725, 2.7326367935, 3.48953912565, - 26.1244815584, 20.0902350297, 17.5345461395, 15.5073130559, 13.3615661365) + 26.1244815584, 20.0902350297, 17.5345461395, 15.5073130559, 13.3615661365) verifyQuantiles(distributionValues, distributionPoints, shape, scale, tol) verifyDistribution(distributionPoints, distributionValues, shape, scale, tol) verifyDensity(distributionPoints, densityValues, shape, scale, tol) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/KolmogorovSmirnovDistributionTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/KolmogorovSmirnovDistributionTestCases.R b/src/test/R/KolmogorovSmirnovDistributionTestCases.R index d458dcc..19f74b7 100644 --- a/src/test/R/KolmogorovSmirnovDistributionTestCases.R +++ b/src/test/R/KolmogorovSmirnovDistributionTestCases.R @@ -21,16 +21,16 @@ ps <- c(0.005, 0.02, 0.031111, 0.04) for (n in ns) { for (p in ps) { res <- .C("pkolmogorov2x", p = as.double(p), n = as.integer(n), PACKAGE = "stats")$p - + cat("/* formatC(.C(\"pkolmogorov2x\", p = as.double(", p, "), n = as.integer(", n, "), PACKAGE = \"stats\")$p, 40) gives\n", sep = "") cat(" * ", formatC(res, digits = 40), "\n", sep = "") cat(" */\n") - + cat("dist = new KolmogorovSmirnovDistributionImpl(", n, ");\n", sep = "") #cat("Assert.assertEquals(", formatC(res, digits = 40), ", dist.cdf(", p, ", true), TOLERANCE);\n", sep = "") cat("Assert.assertEquals(", formatC(res, digits = 40), ", dist.cdf(", p, ", false), TOLERANCE);\n", sep = "") cat("\n") - + #cat("System.out.println(\"", formatC(res, digits = 20), " - \" + dist.cdf(", p, ", false) + \" = \" + (", res, " - dist.cdf(", p, ", false)));\n", sep = "") } } http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/LevyDistributionTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/LevyDistributionTestCases.R b/src/test/R/LevyDistributionTestCases.R index 9e9238e..ed7c367 100644 --- a/src/test/R/LevyDistributionTestCases.R +++ b/src/test/R/LevyDistributionTestCases.R @@ -47,7 +47,7 @@ verifyDistribution <- function(points, expected, m, s, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify density computations @@ -64,7 +64,7 @@ verifyDensity <- function(points, expected, m, s, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/README.txt ---------------------------------------------------------------------- diff --git a/src/test/R/README.txt b/src/test/R/README.txt index c6549bc..eb83ecc 100644 --- a/src/test/R/README.txt +++ b/src/test/R/README.txt @@ -17,34 +17,34 @@ INTRODUCTION -The purpose of the R programs included in this directory is to validate -the target values used in Apache commons math unit tests. Success running the -R and commons-math tests on a platform (OS and R version) means that R and -commons-math give results for the test cases that are close in value. The -tests include configurable tolerance levels; but care must be taken in changing -these, since in most cases the pre-set tolerance is close to the number of -decimal digits used in expressing the expected values (both here and in the +The purpose of the R programs included in this directory is to validate +the target values used in Apache commons math unit tests. Success running the +R and commons-math tests on a platform (OS and R version) means that R and +commons-math give results for the test cases that are close in value. The +tests include configurable tolerance levels; but care must be taken in changing +these, since in most cases the pre-set tolerance is close to the number of +decimal digits used in expressing the expected values (both here and in the corresponding commons-math unit tests). -Of course it is always possible that both R and commons-math give incorrect -values for test cases, so these tests should not be interpreted as definitive -in any absolute sense. The value of developing and running the tests is really -to generate questions (and answers!) when the two systems give different +Of course it is always possible that both R and commons-math give incorrect +values for test cases, so these tests should not be interpreted as definitive +in any absolute sense. The value of developing and running the tests is really +to generate questions (and answers!) when the two systems give different results. -Contributions of additional test cases (both R and Junit code) or just -R programs to validate commons-math tests that are not covered here would be +Contributions of additional test cases (both R and Junit code) or just +R programs to validate commons-math tests that are not covered here would be greatly appreciated. SETUP 0) Download and install R. You can get R here http://www.r-project.org/ -Follow the install instructions and make sure that you can launch R from this -(i.e., either explitly add R to your OS path or let the install package do it -for you). +Follow the install instructions and make sure that you can launch R from this +(i.e., either explitly add R to your OS path or let the install package do it +for you). -1) Launch R from this directory and type +1) Launch R from this directory and type > source("testAll") to an R prompt. This should produce output to the console similar to this: @@ -69,26 +69,26 @@ Distribution test mu = 0, sigma = 0.1..................................SUCCEEDED WORKING WITH THE TESTS -The R distribution comes with online manuals that you can view by launching +The R distribution comes with online manuals that you can view by launching a browser instance and then entering > help.start() -at an R prompt. Poking about in the test case files and the online docs should -bring you up to speed fairly quickly. Here are some basic things to get -you started. I should note at this point that I am by no means an expert R -programmer, so some things may not be implemented in the the nicest way. +at an R prompt. Poking about in the test case files and the online docs should +bring you up to speed fairly quickly. Here are some basic things to get +you started. I should note at this point that I am by no means an expert R +programmer, so some things may not be implemented in the the nicest way. Comments / suggestions for improvement are welcome! All of the test cases use some basic functions and global constants (screen -width and success / failure strings) defined in "testFunctions." The -R "source" function is used to "import" these functions into each of the test -programs. The "testAll" program pulls together and executes all of the +width and success / failure strings) defined in "testFunctions." The +R "source" function is used to "import" these functions into each of the test +programs. The "testAll" program pulls together and executes all of the individual test programs. You can execute any one of them by just entering > source(). -The "assertEquals" function in the testFunctions file mimics the similarly +The "assertEquals" function in the testFunctions file mimics the similarly named function used by Junit: assertEquals <- function(expected, observed, tol, message) { @@ -102,11 +102,11 @@ assertEquals <- function(expected, observed, tol, message) { } } -The and arguments can be scalar values, vectors or +The and arguments can be scalar values, vectors or matrices. If the arguments are vectors or matrices, corresponding entries are compared. -The standard pattern used throughout the tests looks like this (from +The standard pattern used throughout the tests looks like this (from binomialTestCases): Start by defining a "verification function" -- in this example a function to @@ -129,11 +129,11 @@ verifyDensity <- function(points, expected, n, p, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } The displayPadded function just displays its first and second arguments with -enough dots in between to make the whole string WIDTH characters long. It is +enough dots in between to make the whole string WIDTH characters long. It is defined in testFunctions. Then call this function with different parameters corresponding to the different @@ -143,7 +143,7 @@ size <- 10.0 probability <- 0.70 densityPoints <- c(-1,0,1,2,3,4,5,6,7,8,9,10,11) -densityValues <- c(0, 0.0000, 0.0001, 0.0014, 0.0090, 0.0368, 0.1029, +densityValues <- c(0, 0.0000, 0.0001, 0.0014, 0.0090, 0.0368, 0.1029, 0.2001, 0.2668, 0.2335, 0.1211, 0.0282, 0) ... verifyDensity(densityPoints, densityValues, size, probability, tol) @@ -153,16 +153,16 @@ produce one line of output to the console: Density test n = 10, p = 0.7...........................................SUCCEEDED -If you modify the value of tol set at the top of binomialTestCases to make the -test more sensitive than the number of digits specified in the densityValues +If you modify the value of tol set at the top of binomialTestCases to make the +test more sensitive than the number of digits specified in the densityValues vector, it will fail, producing the following output, showing the failure and the expected and observed values: -FAILURE: Density Values +FAILURE: Density Values EXPECTED: 0 0 1e-04 0.0014 0.009 0.0368 0.1029 0.2001 0.2668 0.2335 0.1211 / - 0.0282 0 + 0.0282 0 OBSERVED: 0 5.9049e-06 0.000137781 0.0014467005 0.009001692 0.036756909 / -0.1029193452 0.200120949 0.266827932 0.2334744405 0.121060821 0.0282475249 0 +0.1029193452 0.200120949 0.266827932 0.2334744405 0.121060821 0.0282475249 0 Density test n = 10, p = 0.7..............................................FAILED http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/TDistributionTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/TDistributionTestCases.R b/src/test/R/TDistributionTestCases.R index 723e958..6f91269 100644 --- a/src/test/R/TDistributionTestCases.R +++ b/src/test/R/TDistributionTestCases.R @@ -40,7 +40,7 @@ verifyDistribution <- function(points, expected, df, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify density computations @@ -56,7 +56,7 @@ verifyDensity <- function(points, expected, df, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify quantiles @@ -72,7 +72,7 @@ verifyQuantiles <- function(points, expected, df, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -83,7 +83,7 @@ distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.95 densityValues <- c(0.000756494565517, 0.0109109752919, 0.0303377878006, 0.0637967988952, 0.128289492005, 0.000756494565517, 0.0109109752919, 0.0303377878006, 0.0637967988952, 0.128289492005) distributionPoints <- c(-5.89342953136, -3.36492999891, -2.57058183564, -2.01504837333, -1.47588404882, - 5.89342953136, 3.36492999891, 2.57058183564, 2.01504837333, 1.47588404882) + 5.89342953136, 3.36492999891, 2.57058183564, 2.01504837333, 1.47588404882) verifyQuantiles(distributionValues, distributionPoints, df, tol) verifyDistribution(distributionPoints, distributionValues, df, tol) verifyDensity(distributionPoints, densityValues, df, tol) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/TTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/TTestCases b/src/test/R/TTestCases index 6aa5e2d..38adf7b 100644 --- a/src/test/R/TTestCases +++ b/src/test/R/TTestCases @@ -27,14 +27,14 @@ # Arguments # x a numeric vector of data values. # y an optional numeric vector data values. -# alternative a character string specifying the alternative hypothesis, +# alternative a character string specifying the alternative hypothesis, # must be one of "two.sided" (default), "greater" or "less". You can specify # just the initial letter. # mu a number indicating the true value of the mean (or difference in means # if you are performing a two sample test). # paired a logical indicating whether you want a paired t-test. # var.equal a logical variable indicating whether to treat the two -# variances as being equal. +# variances as being equal. # If TRUE then the pooled variance is used to estimate the variance, # otherwise the Welch (or Satterthwaite) approximation to the degrees # of freedom is used. @@ -54,14 +54,14 @@ verifyTest <- function(out,expectedP, expectedT, displayPadded(output, SUCCEEDED, 80) } else { displayPadded(output, FAILED, 80) - } - output <- c("t test test statistic") + } + output <- c("t test test statistic") if (assertEquals(expectedT, out$statistic, tol, "Ttest t statistic")) { displayPadded(output, SUCCEEDED, 80) } else { displayPadded(output, FAILED, 80) - } + } displayDashes(WIDTH) } @@ -71,14 +71,14 @@ sample1 <- c(93.0, 103.0, 95.0, 101.0, 91.0, 105.0, 96.0, 94.0, 101.0, 88.0, out <- t.test(sample1, mu=100.0) expectedP <- 0.0136390585873 expectedT<- -2.81976445346 -verifyTest(out,expectedP, expectedT, tol) +verifyTest(out,expectedP, expectedT, tol) cat("One-sample, one-sided TTest test cases \n") sample1 <- c(2, 0, 6, 6, 3, 3, 2, 3, -6, 6, 6, 6, 3, 0, 1, 1, 0, 2, 3, 3) out <- t.test(sample1, mu=0.0, alternative="g") expectedP <- 0.000521637019637 expectedT<- 3.86485535541 -verifyTest(out,expectedP, expectedT, tol) +verifyTest(out,expectedP, expectedT, tol) cat("Homoscedastic TTest test cases \n") sample1 <- c(2, 4, 6, 8, 10, 97) @@ -87,10 +87,10 @@ out <- t.test(sample1,sample2,var.equal = TRUE) expectedP <- 0.4833963785 expectedT<- 0.73096310086 verifyTest(out,expectedP, expectedT, tol) - + cat("Heteroscedastic TTest test cases \n") sample1 <- c(7, -4, 18, 17, -3, -5, 1, 10, 11, -2) -sample2 <- c(-1, 12, -1, -3, 3, -5, 5, 2, -11, -1, -3) +sample2 <- c(-1, 12, -1, -3, 3, -5, 5, 2, -11, -1, -3) out <- t.test(sample1,sample2,var.equal = FALSE) expectedP <- 0.128839369622 expectedT<- 1.60371728768 @@ -103,4 +103,4 @@ out <- t.test(sample1,sample2,var.equal = FALSE) expectedP <- 0.198727388935 expectedT<- -2.2360679775 verifyTest(out,expectedP, expectedT, tol) - + http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/WeibullDistributionTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/WeibullDistributionTestCases.R b/src/test/R/WeibullDistributionTestCases.R index fadc625..7228641 100644 --- a/src/test/R/WeibullDistributionTestCases.R +++ b/src/test/R/WeibullDistributionTestCases.R @@ -40,7 +40,7 @@ verifyDistribution <- function(points, expected, alpha, beta, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify density computations @@ -56,7 +56,7 @@ verifyDensity <- function(points, expected, alpha, beta, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify quantiles @@ -72,7 +72,7 @@ verifyQuantiles <- function(points, expected, alpha, beta, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -84,7 +84,7 @@ distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.95 densityValues <- c(0.180535929306, 0.262801138133, 0.301905425199, 0.330899152971, 0.353441418887, 0.000788590320203, 0.00737060094841, 0.0177576041516, 0.0343043442574, 0.065664589369) distributionPoints <- c(0.00664355180993, 0.0454328283309, 0.0981162737374, 0.176713524579, 0.321946865392, - 10.5115496887, 7.4976304671, 6.23205600701, 5.23968436955, 4.20790282578) + 10.5115496887, 7.4976304671, 6.23205600701, 5.23968436955, 4.20790282578) verifyQuantiles(distributionValues, distributionPoints, shape, scale, tol) verifyDistribution(distributionPoints, distributionValues, shape, scale, tol) verifyDensity(distributionPoints, densityValues, shape, scale, tol) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/anovaTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/anovaTestCases b/src/test/R/anovaTestCases index 077ba09..1c1dd7c 100644 --- a/src/test/R/anovaTestCases +++ b/src/test/R/anovaTestCases @@ -43,13 +43,13 @@ verifyAnova <- function(frame, expectedP, expectedF, frameName) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } output <- c("F-value test frame = ", frameName) if (assertEquals(expectedF,f,tol,"F value")) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -63,10 +63,10 @@ class=c(rep("classA", length(classA)), rep("classB", length(classB)), rep("classC", length(classC)))) -verifyAnova(threeClasses,6.959446e-06, 24.67361709460624, "Three classes") +verifyAnova(threeClasses,6.959446e-06, 24.67361709460624, "Three classes") twoClasses = data.frame(val = c(classA, classB), class=c(rep("classA", length(classA)), rep("classB", length(classB)))) verifyAnova(twoClasses, 0.904212960464, 0.0150579150579, "Two classes") -displayDashes(WIDTH) \ No newline at end of file +displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/binomialTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/binomialTestCases b/src/test/R/binomialTestCases index 6b1871c..144a221 100644 --- a/src/test/R/binomialTestCases +++ b/src/test/R/binomialTestCases @@ -46,7 +46,7 @@ verifyDensity <- function(points, expected, n, p, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify distribution computations @@ -63,7 +63,7 @@ verifyDistribution <- function(points, expected, n, p, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -73,7 +73,7 @@ size <- 10.0 probability <- 0.70 densityPoints <- c(-1,0,1,2,3,4,5,6,7,8,9,10,11) -densityValues <- c(0, 0.0000, 0.0001, 0.0014, 0.0090, 0.0368, 0.1029, +densityValues <- c(0, 0.0000, 0.0001, 0.0014, 0.0090, 0.0368, 0.1029, 0.2001, 0.2668, 0.2335, 0.1211, 0.0282, 0) distributionValues <- c(0, 0.0000, 0.0001, 0.0016, 0.0106, 0.0473, 0.1503, 0.3504, 0.6172, 0.8507, 0.9718, 1, 1) @@ -98,7 +98,7 @@ if (assertEquals(inverseCumValues, rInverseCumValues-1, tol, displayPadded(output, SUCCEEDED, 80) } else { displayPadded(output, FAILED, 80) -} +} # Degenerate cases http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/cauchyTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/cauchyTestCases.R b/src/test/R/cauchyTestCases.R index b046ca5..d0fe442 100644 --- a/src/test/R/cauchyTestCases.R +++ b/src/test/R/cauchyTestCases.R @@ -42,7 +42,7 @@ verifyDistribution <- function(points, expected, median, scale, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify density computations @@ -59,7 +59,7 @@ verifyDensity <- function(points, expected, median, scale, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify quantiles @@ -76,7 +76,7 @@ verifyQuantiles <- function(points, expected, median, scale, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/chiSquareTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/chiSquareTestCases b/src/test/R/chiSquareTestCases index 747b5e8..be6eb84 100644 --- a/src/test/R/chiSquareTestCases +++ b/src/test/R/chiSquareTestCases @@ -38,16 +38,16 @@ verifyTable <- function(counts, expectedP, expectedStat, tol, desc) { displayPadded(c(desc," p-value test"), SUCCEEDED, WIDTH) } else { displayPadded(c(desc, " p-value test"), FAILED, WIDTH) - } + } if (assertEquals(expectedStat, results$statistic, tol, "ChiSquare Statistic")) { displayPadded(c(desc, " chi-square statistic test"), SUCCEEDED, WIDTH) } else { displayPadded(c(desc, " chi-square statistic test"), FAILED, WIDTH) - } + } } -verifyHomogeneity <- function(obs, exp, expectedP, expectedStat, +verifyHomogeneity <- function(obs, exp, expectedP, expectedStat, tol, desc) { results <- chisq.test(obs,p=exp,rescale.p=TRUE) chi <- results$statistic @@ -56,13 +56,13 @@ verifyHomogeneity <- function(obs, exp, expectedP, expectedStat, displayPadded(c(desc, " p-value test"), SUCCEEDED, WIDTH) } else { displayPadded(c(desc, " p-value test"), FAILED, WIDTH) - } + } if (assertEquals(expectedStat, chi, tol, "ChiSquare Statistic")) { displayPadded(c(desc, " chi-square statistic test"), SUCCEEDED, WIDTH) } else { displayPadded(c(desc, " chi-square statistic test"), FAILED, WIDTH) - } + } } cat("ChiSquareTest test cases\n") @@ -85,17 +85,17 @@ verifyHomogeneity(observed, expected, 0, 114875.90421929007, tol, "testChiSquareLargeTestStatistic") counts <- matrix(c(40, 22, 43, 91, 21, 28, 60, 10, 22), nc = 3); -verifyTable(counts, 0.000144751460134, 22.709027688, tol, +verifyTable(counts, 0.000144751460134, 22.709027688, tol, "testChiSquareIndependence1") counts <- matrix(c(10, 15, 30, 40, 60, 90), nc = 3); -verifyTable(counts, 0.918987499852, 0.168965517241, tol, +verifyTable(counts, 0.918987499852, 0.168965517241, tol, "testChiSquareIndependence2") - + counts <- matrix(c(40, 0, 4, 91, 1, 2, 60, 2, 0), nc = 3); -verifyTable(counts, 0.0462835770603, 9.67444662263, tol, +verifyTable(counts, 0.0462835770603, 9.67444662263, tol, "testChiSquareZeroCount") displayDashes(WIDTH) - + http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/correlationTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/correlationTestCases b/src/test/R/correlationTestCases index caacd5f..07fdb27 100644 --- a/src/test/R/correlationTestCases +++ b/src/test/R/correlationTestCases @@ -37,7 +37,7 @@ verifyPearsonsCorrelation <- function(matrix, expectedCorrelation, name) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # Verify Spearman's correlation @@ -48,7 +48,7 @@ verifySpearmansCorrelation <- function(matrix, expectedCorrelation, name) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # Verify Kendall's correlation @@ -59,7 +59,7 @@ verifyKendallsCorrelation <- function(matrix, expectedCorrelation, name) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify p-values @@ -133,16 +133,16 @@ expectedCorrelation <- matrix(c( 0.4172451498349454, 0.993952846232926, 1.0000000000000000), nrow = 7, ncol = 7, byrow = TRUE) verifyPearsonsCorrelation(longley, expectedCorrelation, "longley") - + expectedPValues <- c( 4.38904690369668e-10, 8.36353208910623e-12, 7.8159700933611e-14, - 0.0472894097790304, 0.01030636128354301, 0.01316878049026582, + 0.0472894097790304, 0.01030636128354301, 0.01316878049026582, 0.0749178049642416, 0.06971758330341182, 0.0830166169296545, 0.510948586323452, - 3.693245043123738e-09, 4.327782576751815e-11, 1.167954621905665e-13, 0.00331028281967516, 0.1652293725106684, + 3.693245043123738e-09, 4.327782576751815e-11, 1.167954621905665e-13, 0.00331028281967516, 0.1652293725106684, 3.95834476307755e-10, 1.114663916723657e-13, 1.332267629550188e-15, 0.00466039138541463, 0.1078477071581498, 7.771561172376096e-15) verifyPValues(longley, expectedPValues, "longley") - + # Spearman's expectedCorrelation <- matrix(c( 1, 0.982352941176471, 0.985294117647059, 0.564705882352941, 0.2264705882352941, 0.976470588235294, @@ -218,7 +218,7 @@ expectedCorrelation <- matrix(c( 44.7,46.6,16,29,50.43, 42.8,27.7,22,29,58.33), nrow = 47, ncol = 5, byrow = TRUE) - + # Pearson's expectedCorrelation <- matrix(c( 1, 0.3530791836199747, -0.6458827064572875, -0.663788857035069, 0.463684700651794, http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/covarianceTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/covarianceTestCases b/src/test/R/covarianceTestCases index 3d8d603..eca5d0b 100644 --- a/src/test/R/covarianceTestCases +++ b/src/test/R/covarianceTestCases @@ -37,7 +37,7 @@ verifyCovariance <- function(matrix, expectedCovariance, name) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -79,11 +79,11 @@ expectedCovariance <- matrix(c( 16240.93333333333, 5.092333333333334e+01, 470977.900000000, 2973.033333333333, 1382.433333333333, 32917.40000000, 22.66666666666667), nrow = 7, ncol = 7, byrow = TRUE) - + verifyCovariance(longley, expectedCovariance, "longley") - + # Swiss Fertility - + fertility <- matrix(c(80.2,17.0,15,12,9.96, 83.1,45.1,6,9,84.84, 92.5,39.7,5,5,93.40, @@ -132,7 +132,7 @@ expectedCovariance <- matrix(c( 44.7,46.6,16,29,50.43, 42.8,27.7,22,29,58.33), nrow = 47, ncol = 5, byrow = TRUE) - + expectedCovariance <- matrix(c( 156.0424976873265, 100.1691489361702, -64.36692876965772, -79.7295097132285, 241.5632030527289, 100.169148936170251, 515.7994172062905, -124.39283071230344, -139.6574005550416, 379.9043755781684, @@ -140,7 +140,7 @@ expectedCovariance <- matrix(c( -79.7295097132285, -139.6574005550416, 53.57585568917669, 92.4560592044403, -61.6988297872340, 241.5632030527289, 379.9043755781684, -190.56061054579092, -61.6988297872340, 1739.2945371877890), nrow = 5, ncol = 5, byrow = TRUE) - + verifyCovariance(fertility, expectedCovariance, "swiss fertility") - - displayDashes(WIDTH) \ No newline at end of file + + displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/descriptiveTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/descriptiveTestCases b/src/test/R/descriptiveTestCases index c724567..f6a6183 100644 --- a/src/test/R/descriptiveTestCases +++ b/src/test/R/descriptiveTestCases @@ -38,7 +38,7 @@ verifyMean <- function(values, expectedMean, tol, desc) { displayPadded(c(desc," mean test"), SUCCEEDED, WIDTH) } else { displayPadded(c(desc, " mean test"), FAILED, WIDTH) - } + } } verifySigma <- function(values, expectedSigma, tol, desc) { @@ -47,7 +47,7 @@ verifySigma <- function(values, expectedSigma, tol, desc) { displayPadded(c(desc," std test"), SUCCEEDED, WIDTH) } else { displayPadded(c(desc, " std test"), FAILED, WIDTH) - } + } } cat("Descriptive test cases\n") @@ -80,4 +80,4 @@ expectedSigma <- 0.000429123454003053 verifyMean(values, expectedMean, tol, "Mavro") verifySigma(values, expectedSigma, tol, "Mavro") -displayDashes(WIDTH) +displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/exponentialTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/exponentialTestCases b/src/test/R/exponentialTestCases index 25f801a..c73e6dd 100644 --- a/src/test/R/exponentialTestCases +++ b/src/test/R/exponentialTestCases @@ -42,7 +42,7 @@ verifyDistribution <- function(points, expected, mean, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify density computations @@ -58,7 +58,7 @@ verifyDensity <- function(points, expected, mean, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify quantiles @@ -74,7 +74,7 @@ verifyQuantiles <- function(points, expected, mean, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } @@ -98,6 +98,6 @@ if (assertEquals(0.0905214480757, pexp(.75, 1/mean) - pexp(.25, 1/mean), tol, "P displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) -} +} displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/geometricTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/geometricTestCases b/src/test/R/geometricTestCases index 0c2293f..96ca82e 100644 --- a/src/test/R/geometricTestCases +++ b/src/test/R/geometricTestCases @@ -22,7 +22,7 @@ # source("") # # R functions used -# dgeom(x, prob, log = FALSE) <- density +# dgeom(x, prob, log = FALSE) <- density # pgeom(q, prob, lower.tail = TRUE, log.p = FALSE) <- distribution # qgeom(p, prob, lower.tail = TRUE, log.p = FALSE) <- quantiles #------------------------------------------------------------------------------ @@ -46,7 +46,7 @@ verifyDensity <- function(points, expected, prob, tol, log = FALSE) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify distribution computations @@ -63,7 +63,7 @@ verifyDistribution <- function(points, expected, prob, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -79,7 +79,7 @@ densityValues <- c(0, 0.4, 0.24, 0.144, 0.0864, 0.05184, 0.031104, 0.0186624, 0. 0.000313456656384, 0.0001880739938304, 0.00011284439629824, 6.7706637778944e-05, 4.06239826673664e-05, 2.43743896004198e-05, 1.46246337602519e-05, 8.77478025615113e-06, 5.26486815369068e-06, 3.15892089221441e-06, 1.89535253532865e-06, 1.13721152119719e-06, - 6.82326912718312e-07, 4.09396147630988e-07, 2.45637688578593e-07) + 6.82326912718312e-07, 4.09396147630988e-07, 2.45637688578593e-07) logDensityValues <- c(-Inf, -0.916290731874155, -1.42711635564015, -1.93794197940614, -2.44876760317213, -2.95959322693812, -3.47041885070411, -3.9812444744701, -4.49207009823609, -5.00289572200208, -5.51372134576807, -6.02454696953406, -6.53537259330005, @@ -116,6 +116,6 @@ if (assertEquals(inverseCumValues, rInverseCumValues-1, tol, displayPadded(output, SUCCEEDED, 80) } else { displayPadded(output, FAILED, 80) -} +} displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/hypergeometricTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/hypergeometricTestCases b/src/test/R/hypergeometricTestCases index a1d4ee9..04bc8a0 100644 --- a/src/test/R/hypergeometricTestCases +++ b/src/test/R/hypergeometricTestCases @@ -22,7 +22,7 @@ # source("") # # R functions used -# dhyper(x, m, n, k, log = FALSE) <- density +# dhyper(x, m, n, k, log = FALSE) <- density # phyper(q, m, n, k, lower.tail = TRUE, log.p = FALSE) <- distribution # qhyper(p, m, n, k, lower.tail = TRUE, log.p = FALSE) <- quantiles #------------------------------------------------------------------------------ @@ -41,13 +41,13 @@ verifyDensity <- function(points, expected, good, bad, selected, tol, log = FALS i <- i + 1 rDensityValues[i] <- dhyper(point, good, bad, selected, log) } - output <- c("Density test good = ", good, ", bad = ", bad, + output <- c("Density test good = ", good, ", bad = ", bad, ", selected = ",selected) if (assertEquals(expected,rDensityValues,tol,"Density Values")) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify distribution computations @@ -65,7 +65,7 @@ verifyDistribution <- function(points, expected, good, bad, selected, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -98,7 +98,7 @@ for (point in inverseCumPoints) { rInverseCumValues[i] <- qhyper(point, good, bad, selected) } -output <- c("Inverse Distribution test good = ", good, ", bad = ", bad, +output <- c("Inverse Distribution test good = ", good, ", bad = ", bad, ", selected = ", selected) # R defines quantiles from the right, need to subtract one if (assertEquals(inverseCumValues, rInverseCumValues-1, tol, @@ -106,7 +106,7 @@ if (assertEquals(inverseCumValues, rInverseCumValues-1, tol, displayPadded(output, SUCCEEDED, 80) } else { displayPadded(output, FAILED, 80) -} +} # Degenerate cases good <- 5 http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/multipleOLSRegressionTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/multipleOLSRegressionTestCases b/src/test/R/multipleOLSRegressionTestCases index 1fe983d..458426f 100644 --- a/src/test/R/multipleOLSRegressionTestCases +++ b/src/test/R/multipleOLSRegressionTestCases @@ -44,13 +44,13 @@ verifyRegression <- function(model, expectedBeta, expectedResiduals, displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } output <- c("Residuals test dataset = ", modelName) if (assertEquals(expectedResiduals,residuals,tol,"Residuals")) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } output <- c("Errors test dataset = ", modelName) if (assertEquals(expectedErrors,errors,tol,"Errors")) { displayPadded(output, SUCCEEDED, WIDTH) @@ -95,13 +95,13 @@ expectedStdError <- NaN expectedRSquare <- 1 expectedAdjRSquare <- NaN verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors, - expectedStdError, expectedRSquare, expectedAdjRSquare, "perfect fit") + expectedStdError, expectedRSquare, expectedAdjRSquare, "perfect fit") # Longley # # Data Source: J. Longley (1967) "An Appraisal of Least Squares Programs for the -# Electronic Computer from the Point of View of the User", -# Journal of the American Statistical Association, +# Electronic Computer from the Point of View of the User", +# Journal of the American Statistical Association, # vol. 62. September, pp. 819-841. # # Certified values (and data) are from NIST: @@ -154,16 +154,16 @@ expectedRSquare <- 0.995479004577296 expectedAdjRSquare <- 0.992465007628826 verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors, -expectedStdError, expectedRSquare, expectedAdjRSquare, "Longley") +expectedStdError, expectedRSquare, expectedAdjRSquare, "Longley") # Model with no intercept model <- lm(y ~ 0 + x1 + x2 + x3 + x4 + x5 + x6) -estimates <- matrix(c(-52.99357013868291, 129.54486693117232, +estimates <- matrix(c(-52.99357013868291, 129.54486693117232, 0.07107319907358, 0.03016640003786, - -0.42346585566399, 0.41773654056612, + -0.42346585566399, 0.41773654056612, -0.57256866841929, 0.27899087467676, - -0.41420358884978, 0.32128496193363, + -0.41420358884978, 0.32128496193363, 48.41786562001326, 17.68948737819961), nrow = 6, ncol = 2, byrow = TRUE) @@ -171,7 +171,7 @@ expectedBeta <- estimates[,1] expectedErrors <- estimates[,2] expectedResiduals <- c(279.90274927293092, -130.32465380836874, 90.73228661967445, -401.31252201634948, -440.46768772620027, -543.54512853774793, 201.32111639536299, - 215.90889365977932, 73.09368242049943, 913.21694494481869, 424.82484953610174, + 215.90889365977932, 73.09368242049943, 913.21694494481869, 424.82484953610174, -8.56475876776709, -361.32974610842876, 27.34560497213464, 151.28955976355002, -492.49937355336846) expectedStdError <- 475.1655079819517 @@ -179,7 +179,7 @@ expectedRSquare <- 0.9999670130706 expectedAdjRSquare <- 0.999947220913 verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors, -expectedStdError, expectedRSquare, expectedAdjRSquare, "Longley No Intercept") +expectedStdError, expectedRSquare, expectedAdjRSquare, "Longley No Intercept") # Swiss Fertility (R dataset named "swiss") @@ -272,23 +272,23 @@ expectedRSquare <- 0.649789742860228 expectedAdjRSquare <- 0.6164363850373927 verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors, -expectedStdError, expectedRSquare, expectedAdjRSquare, "Swiss Fertility") +expectedStdError, expectedRSquare, expectedAdjRSquare, "Swiss Fertility") # model with no intercept model <- lm(y ~ 0 + x1 + x2 + x3 + x4) estimates <- matrix(c(0.52191832900513, 0.10470063765677, 2.36588087917963, 0.41684100584290, - -0.94770353802795, 0.43370143099691, + -0.94770353802795, 0.43370143099691, 0.30851985863609, 0.07694953606522), nrow = 4, ncol = 2, byrow = TRUE) expectedBeta <- estimates[,1] expectedErrors <- estimates[,2] -expectedResiduals <- c(44.138759883538249, 27.720705122356215, 35.873200836126799, +expectedResiduals <- c(44.138759883538249, 27.720705122356215, 35.873200836126799, 34.574619581211977, 26.600168342080213, 15.074636243026923, -12.704904871199814, - 1.497443824078134, 2.691972687079431, 5.582798774291231, -4.422986561283165, + 1.497443824078134, 2.691972687079431, 5.582798774291231, -4.422986561283165, -9.198581600334345, 4.481765170730647, 2.273520207553216, -22.649827853221336, -17.747900013943308, 20.298314638496436, 6.861405135329779, -8.684712790954924, -10.298639278062371, -9.896618896845819, 4.568568616351242, -15.313570491727944, @@ -304,6 +304,6 @@ expectedRSquare <- 0.946350722085 expectedAdjRSquare <- 0.9413600915813 verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors, -expectedStdError, expectedRSquare, expectedAdjRSquare, "Swiss Fertility No Intercept") +expectedStdError, expectedRSquare, expectedAdjRSquare, "Swiss Fertility No Intercept") displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/normalTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/normalTestCases b/src/test/R/normalTestCases index ae54a96..7be2e75 100644 --- a/src/test/R/normalTestCases +++ b/src/test/R/normalTestCases @@ -44,7 +44,7 @@ verifyDistribution <- function(points, expected, mu, sigma, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify density computations @@ -61,7 +61,7 @@ verifyDensity <- function(points, expected, mu, sigma, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -94,7 +94,7 @@ distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma, mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma, mu + 5 * sigma) densityValues <- c(0.0539909665132, 0.241970724519, 0.398942280401, 0.241970724519, 0.0539909665132, - 0.00443184841194, 0.000133830225765, 1.48671951473e-06) + 0.00443184841194, 0.000133830225765, 1.48671951473e-06) verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) verifyDensity(distributionPoints, densityValues, mu, sigma, tol) @@ -104,7 +104,7 @@ distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma, mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma, mu + 5 * sigma) densityValues <- c(0.539909665132, 2.41970724519, 3.98942280401, 2.41970724519, - 0.539909665132, 0.0443184841194, 0.00133830225765, 1.48671951473e-05) + 0.539909665132, 0.0443184841194, 0.00133830225765, 1.48671951473e-05) verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) verifyDensity(distributionPoints, densityValues, mu, sigma, tol) http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/pascalTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/pascalTestCases b/src/test/R/pascalTestCases index a8c6c31..0e7e68e 100644 --- a/src/test/R/pascalTestCases +++ b/src/test/R/pascalTestCases @@ -46,7 +46,7 @@ verifyDensity <- function(points, expected, size, p, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify distribution computations @@ -63,7 +63,7 @@ verifyDistribution <- function(points, expected, size, p, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #-------------------------------------------------------------------------- @@ -100,7 +100,7 @@ if (assertEquals(inverseCumValues, rInverseCumValues-1, tol, displayPadded(output, SUCCEEDED, 80) } else { displayPadded(output, FAILED, 80) -} +} # Degenerate cases http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/poissonTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/poissonTestCases b/src/test/R/poissonTestCases index 200aa75..2b5bbb7 100644 --- a/src/test/R/poissonTestCases +++ b/src/test/R/poissonTestCases @@ -46,7 +46,7 @@ verifyDensity <- function(points, expected, lambda, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify distribution computations @@ -63,14 +63,14 @@ verifyDistribution <- function(points, expected, lambda, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify normal approximation verifyNormalApproximation <- function(expected, lambda, lower, upper, tol) { rValue <- pnorm(upper, mean=lambda, sd=sqrt(lambda), lower.tail = TRUE, - log.p = FALSE) - + log.p = FALSE) - pnorm(lower, mean=lambda, sd=sqrt(lambda), lower.tail = TRUE, log.p = FALSE) output <- c("Normal approx. test lambda = ", lambda, " upper = ", @@ -79,7 +79,7 @@ verifyNormalApproximation <- function(expected, lambda, lower, upper, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } cat("Poisson distribution test cases\n") @@ -112,5 +112,5 @@ displayDashes(WIDTH) - - + + http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/regressionTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/regressionTestCases b/src/test/R/regressionTestCases index c4465ca..d8b3c73 100644 --- a/src/test/R/regressionTestCases +++ b/src/test/R/regressionTestCases @@ -58,19 +58,19 @@ if (assertEquals(4.596e-07, significance, tol, "Significance")) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) -} - +} + output <- "InfData conf interval test" ci<-confint(model) # ci[1,1] = lower 2.5% bound for intercept, ci[1,2] = upper 97.5% for intercept # ci[2,1] = lower 2.5% bound for slope, ci[2,2] = upper 97.5% for slope halfWidth <- ci[2,2] - slope -if (assertEquals(0.0270713794287, halfWidth, tol, +if (assertEquals(0.0270713794287, halfWidth, tol, "Slope conf. interval half-width")) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) -} +} #------------------------------------------------------------------------------ # Norris dataset from NIST examples @@ -123,37 +123,37 @@ if (assertEquals(0.261829133982, significance, tol, "Significance")) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) -} +} output <- "InfData2 conf interval test" ci<-confint(model) # ci[1,1] = lower 2.5% bound for intercept, ci[1,2] = upper 97.5% for intercept # ci[2,1] = lower 2.5% bound for slope, ci[2,2] = upper 97.5% for slope halfWidth <- ci[2,2] - slope -if (assertEquals(2.97802204827, halfWidth, tol, +if (assertEquals(2.97802204827, halfWidth, tol, "Slope conf. interval half-width")) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) -} +} #------------------------------------------------------------------------------ # Correlation example x <- c(101.0, 100.1, 100.0, 90.6, 86.5, 89.7, 90.6, 82.8, 70.1, 65.4, 61.3, 62.5, 63.6, 52.6, 59.7, 59.5, 61.3) y <- c(99.2, 99.0, 100.0, 111.6, 122.2, 117.6, 121.1, 136.0, 154.2, 153.6, - 158.5, 140.6, 136.2, 168.0, 154.3, 149.0, 165.5) + 158.5, 140.6, 136.2, 168.0, 154.3, 149.0, 165.5) output <- "Correlation test" -if (assertEquals(-0.94663767742, cor(x,y, method="pearson"), tol, +if (assertEquals(-0.94663767742, cor(x,y, method="pearson"), tol, "Correlation coefficient")) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) } - + displayDashes(WIDTH) - - + + http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/testAll ---------------------------------------------------------------------- diff --git a/src/test/R/testAll b/src/test/R/testAll index bf77f6d..9af417b 100644 --- a/src/test/R/testAll +++ b/src/test/R/testAll @@ -15,7 +15,7 @@ # #------------------------------------------------------------------------------ # R source file to run all commons-math R verification tests -# +# # To run the test, install R, put this file and all other o.a.c.math R # verification tests and the testfunctions utilities file into the same # directory, launch R from this directory and then enter http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/testFunctions ---------------------------------------------------------------------- diff --git a/src/test/R/testFunctions b/src/test/R/testFunctions index 92f62ea..744b554 100644 --- a/src/test/R/testFunctions +++ b/src/test/R/testFunctions @@ -60,7 +60,7 @@ assertEquals <- function(expected, observed, tol, message) { cat("OBSERVED: ",observed,"\n") cat("DIFF: ",observed - expected,"\n") cat("TOLERANCE: ",tol,"\n") - } + } return(!failed) } #------------------------------------------------------------------------------ @@ -73,12 +73,12 @@ displayDashes <- function(n) { return(1) } #------------------------------------------------------------------------------ -# Displays ...... with enough dots in between to make cols, +# Displays ...... with enough dots in between to make cols, # followed by a new line character. Blows up if is longer than # cols by itself. # # Expects and to be strings (character vectors). -# +# displayPadded <- function(start, end, n) { len = sum(nchar(start)) + sum(nchar(end)) cat(start, rep(".", n - len), end, "\n",sep='') http://git-wip-us.apache.org/repos/asf/commons-math/blob/23b351c8/src/test/R/zipfTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/zipfTestCases b/src/test/R/zipfTestCases index f198548..318fffa 100644 --- a/src/test/R/zipfTestCases +++ b/src/test/R/zipfTestCases @@ -22,7 +22,7 @@ # source("") # # R functions used -# dzipf(x, N, s, log = FALSE) <- density +# dzipf(x, N, s, log = FALSE) <- density # pzipf(q, N, s) <- distribution #------------------------------------------------------------------------------ tol <- 1E-6 # error tolerance for tests @@ -46,7 +46,7 @@ verifyDensity <- function(points, expected, N, s, tol, log = FALSE) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } # function to verify distribution computations @@ -63,7 +63,7 @@ verifyDistribution <- function(points, expected, N, s, tol) { displayPadded(output, SUCCEEDED, WIDTH) } else { displayPadded(output, FAILED, WIDTH) - } + } } #--------------------------------------------------------------------------