http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/chiSquareTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/chiSquareTestCases b/src/test/R/chiSquareTestCases deleted file mode 100644 index be6eb84..0000000 --- a/src/test/R/chiSquareTestCases +++ /dev/null @@ -1,101 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate ChiSquare tests in -# org.apache.commons.math.stat.inference.ChiSquareTestTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -# R functions used -#chisq.test(x, y = NULL, correct = TRUE, -# p = rep(1/length(x), length(x)), -# simulate.p.value = FALSE, B = 2000) -#------------------------------------------------------------------------------ -tol <- 1E-9 # error tolerance for tests -#------------------------------------------------------------------------------ -# Function definitions - -source("testFunctions") # utility test functions - -verifyTable <- function(counts, expectedP, expectedStat, tol, desc) { - results <- chisq.test(counts) - if (assertEquals(expectedP, results$p.value, tol, "p-value")) { - 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, - tol, desc) { - results <- chisq.test(obs,p=exp,rescale.p=TRUE) - chi <- results$statistic - p <- results$p.value - if (assertEquals(expectedP, p, tol, "p-value")) { - 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") - -observed <- c(10, 9, 11) -expected <- c(10, 10, 10) -verifyHomogeneity(observed, expected, 0.904837418036, 0.2, tol, - "testChiSquare1") - -observed <- c(500, 623, 72, 70, 31) -expected <- c(485, 541, 82, 61, 37) -verifyHomogeneity(observed, expected, 0.06051952647453607, 9.023307936427388, - tol, "testChiSquare2") - -observed <- c(2372383, 584222, 257170, 17750155, 7903832, 489265, - 209628, 393899) -expected <- c(3389119.5, 649136.6, 285745.4, 25357364.76, 11291189.78, - 543628.0, 232921.0, 437665.75) -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, - "testChiSquareIndependence1") - -counts <- matrix(c(10, 15, 30, 40, 60, 90), nc = 3); -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, - "testChiSquareZeroCount") - -displayDashes(WIDTH) - -
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/correlationTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/correlationTestCases b/src/test/R/correlationTestCases deleted file mode 100644 index 07fdb27..0000000 --- a/src/test/R/correlationTestCases +++ /dev/null @@ -1,259 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate Pearson's correlation tests in -# org.apache.commons.math.stat.correlation.PearsonsCorrelationTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -#------------------------------------------------------------------------------ -tol <- 1E-15 # error tolerance for tests -#------------------------------------------------------------------------------ -# Function definitions - -source("testFunctions") # utility test functions -options(digits=16) # override number of digits displayed - -# Verify Pearson's correlation -verifyPearsonsCorrelation <- function(matrix, expectedCorrelation, name) { - correlation <- cor(matrix) - output <- c("Pearson's Correlation matrix test dataset = ", name) - if (assertEquals(expectedCorrelation, correlation,tol,"Pearson's Correlations")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# Verify Spearman's correlation -verifySpearmansCorrelation <- function(matrix, expectedCorrelation, name) { - correlation <- cor(matrix, method="spearman") - output <- c("Spearman's Correlation matrix test dataset = ", name) - if (assertEquals(expectedCorrelation, correlation,tol,"Spearman's Correlations")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# 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 -verifyPValues <- function(matrix, pValues, name) { - dimension <- dim(matrix)[2] - corValues <- matrix(nrow=dimension,ncol=dimension) - expectedValues <- matrix(nrow=dimension,ncol=dimension) - for (i in 2:dimension) { - for (j in 1:(i-1)) { - corValues[i,j]<-cor.test(matrix[,i], matrix[,j])$p.value - corValues[j,i]<-corValues[i,j] - } - } - for (i in 1:dimension) { - corValues[i,i] <- 1 - expectedValues[i,i] <- 1 - } - ptr <- 1 - for (i in 2:dimension) { - for (j in 1:(i-1)) { - expectedValues[i,j] <- pValues[ptr] - expectedValues[j,i] <- expectedValues[i,j] - ptr <- ptr + 1 - } - } - output <- c("Correlation p-values test dataset = ", name) - if (assertEquals(expectedValues, corValues,tol,"p-values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } - } - -#-------------------------------------------------------------------------- -cat("Correlation test cases\n") - -# Longley ----------------------------------------------------------------- -longley <- matrix(c(60323,83.0,234289,2356,1590,107608,1947, - 61122,88.5,259426,2325,1456,108632,1948, - 60171,88.2,258054,3682,1616,109773,1949, - 61187,89.5,284599,3351,1650,110929,1950, - 63221,96.2,328975,2099,3099,112075,1951, - 63639,98.1,346999,1932,3594,113270,1952, - 64989,99.0,365385,1870,3547,115094,1953, - 63761,100.0,363112,3578,3350,116219,1954, - 66019,101.2,397469,2904,3048,117388,1955, - 67857,104.6,419180,2822,2857,118734,1956, - 68169,108.4,442769,2936,2798,120445,1957, - 66513,110.8,444546,4681,2637,121950,1958, - 68655,112.6,482704,3813,2552,123366,1959, - 69564,114.2,502601,3931,2514,125368,1960, - 69331,115.7,518173,4806,2572,127852,1961, - 70551,116.9,554894,4007,2827,130081,1962), - nrow = 16, ncol = 7, byrow = TRUE) - -# Pearson's -expectedCorrelation <- matrix(c( - 1.000000000000000, 0.9708985250610560, 0.9835516111796693, 0.5024980838759942, - 0.4573073999764817, 0.960390571594376, 0.9713294591921188, - 0.970898525061056, 1.0000000000000000, 0.9915891780247822, 0.6206333925590966, - 0.4647441876006747, 0.979163432977498, 0.9911491900672053, - 0.983551611179669, 0.9915891780247822, 1.0000000000000000, 0.6042609398895580, - 0.4464367918926265, 0.991090069458478, 0.9952734837647849, - 0.502498083875994, 0.6206333925590966, 0.6042609398895580, 1.0000000000000000, - -0.1774206295018783, 0.686551516365312, 0.6682566045621746, - 0.457307399976482, 0.4647441876006747, 0.4464367918926265, -0.1774206295018783, - 1.0000000000000000, 0.364416267189032, 0.4172451498349454, - 0.960390571594376, 0.9791634329774981, 0.9910900694584777, 0.6865515163653120, - 0.3644162671890320, 1.000000000000000, 0.9939528462329257, - 0.971329459192119, 0.9911491900672053, 0.9952734837647849, 0.6682566045621746, - 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.0749178049642416, 0.06971758330341182, 0.0830166169296545, 0.510948586323452, - 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, - 0.976470588235294, 0.982352941176471, 1, 0.997058823529412, 0.664705882352941, 0.2205882352941176, - 0.997058823529412, 0.997058823529412, 0.985294117647059, 0.997058823529412, 1, 0.638235294117647, - 0.2235294117647059, 0.9941176470588236, 0.9941176470588236, 0.564705882352941, 0.664705882352941, - 0.638235294117647, 1, -0.3411764705882353, 0.685294117647059, 0.685294117647059, 0.2264705882352941, - 0.2205882352941176, 0.2235294117647059, -0.3411764705882353, 1, 0.2264705882352941, 0.2264705882352941, - 0.976470588235294, 0.997058823529412, 0.9941176470588236, 0.685294117647059, 0.2264705882352941, 1, 1, - 0.976470588235294, 0.997058823529412, 0.9941176470588236, 0.685294117647059, 0.2264705882352941, 1, 1), - nrow = 7, ncol = 7, byrow = TRUE) - 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 --------------------------------------------------------- - 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, - 85.8,36.5,12,7,33.77, - 76.9,43.5,17,15,5.16, - 76.1,35.3,9,7,90.57, - 83.8,70.2,16,7,92.85, - 92.4,67.8,14,8,97.16, - 82.4,53.3,12,7,97.67, - 82.9,45.2,16,13,91.38, - 87.1,64.5,14,6,98.61, - 64.1,62.0,21,12,8.52, - 66.9,67.5,14,7,2.27, - 68.9,60.7,19,12,4.43, - 61.7,69.3,22,5,2.82, - 68.3,72.6,18,2,24.20, - 71.7,34.0,17,8,3.30, - 55.7,19.4,26,28,12.11, - 54.3,15.2,31,20,2.15, - 65.1,73.0,19,9,2.84, - 65.5,59.8,22,10,5.23, - 65.0,55.1,14,3,4.52, - 56.6,50.9,22,12,15.14, - 57.4,54.1,20,6,4.20, - 72.5,71.2,12,1,2.40, - 74.2,58.1,14,8,5.23, - 72.0,63.5,6,3,2.56, - 60.5,60.8,16,10,7.72, - 58.3,26.8,25,19,18.46, - 65.4,49.5,15,8,6.10, - 75.5,85.9,3,2,99.71, - 69.3,84.9,7,6,99.68, - 77.3,89.7,5,2,100.00, - 70.5,78.2,12,6,98.96, - 79.4,64.9,7,3,98.22, - 65.0,75.9,9,9,99.06, - 92.2,84.6,3,3,99.46, - 79.3,63.1,13,13,96.83, - 70.4,38.4,26,12,5.62, - 65.7,7.7,29,11,13.79, - 72.7,16.7,22,13,11.22, - 64.4,17.6,35,32,16.92, - 77.6,37.6,15,7,4.97, - 67.6,18.7,25,7,8.65, - 35.0,1.2,37,53,42.34, - 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, - 0.3530791836199747, 1, -0.6865422086171366, -0.63952251894832, 0.4010950530487398, - -0.6458827064572875, -0.6865422086171366, 1, 0.698415296288483, -0.572741806064167, - -0.663788857035069, -0.63952251894832, 0.698415296288483, 1, -0.1538589170909148, - 0.463684700651794, 0.4010950530487398, -0.572741806064167, -0.1538589170909148, 1), - nrow = 5, ncol = 5, byrow = TRUE) -verifyPearsonsCorrelation(fertility, expectedCorrelation, "swiss fertility") - -expectedPValues <- c( - 0.01491720061472623, - 9.45043734069043e-07, 9.95151527133974e-08, - 3.658616965962355e-07, 1.304590105694471e-06, 4.811397236181847e-08, - 0.001028523190118147, 0.005204433539191644, 2.588307925380906e-05, 0.301807756132683) -verifyPValues(fertility, expectedPValues, "swiss fertility") - -# Spearman's -expectedCorrelation <- matrix(c( - 1, 0.2426642769364176, -0.660902996352354, -0.443257690360988, 0.4136455623012432, - 0.2426642769364176, 1, -0.598859938748963, -0.650463814145816, 0.2886878090882852, - -0.660902996352354, -0.598859938748963, 1, 0.674603831406147, -0.4750575257171745, - -0.443257690360988, -0.650463814145816, 0.674603831406147, 1, -0.1444163088302244, - 0.4136455623012432, 0.2886878090882852, -0.4750575257171745, -0.1444163088302244, 1), - nrow = 5, ncol = 5, byrow = TRUE) - 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) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/covarianceTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/covarianceTestCases b/src/test/R/covarianceTestCases deleted file mode 100644 index eca5d0b..0000000 --- a/src/test/R/covarianceTestCases +++ /dev/null @@ -1,146 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate covariance tests in -# org.apache.commons.math.stat.correlation.CovarianceTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -#------------------------------------------------------------------------------ -tol <- 1E-9 # error tolerance for tests -#------------------------------------------------------------------------------ -# Function definitions - -source("testFunctions") # utility test functions -options(digits=16) # override number of digits displayed - -# function to verify covariance computations -verifyCovariance <- function(matrix, expectedCovariance, name) { - covariance <- cov(matrix) - output <- c("Covariance test dataset = ", name) - if (assertEquals(expectedCovariance,covariance,tol,"Covariances")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Covariance test cases\n") - -# Longley - -longley <- matrix(c(60323,83.0,234289,2356,1590,107608,1947, - 61122,88.5,259426,2325,1456,108632,1948, - 60171,88.2,258054,3682,1616,109773,1949, - 61187,89.5,284599,3351,1650,110929,1950, - 63221,96.2,328975,2099,3099,112075,1951, - 63639,98.1,346999,1932,3594,113270,1952, - 64989,99.0,365385,1870,3547,115094,1953, - 63761,100.0,363112,3578,3350,116219,1954, - 66019,101.2,397469,2904,3048,117388,1955, - 67857,104.6,419180,2822,2857,118734,1956, - 68169,108.4,442769,2936,2798,120445,1957, - 66513,110.8,444546,4681,2637,121950,1958, - 68655,112.6,482704,3813,2552,123366,1959, - 69564,114.2,502601,3931,2514,125368,1960, - 69331,115.7,518173,4806,2572,127852,1961, - 70551,116.9,554894,4007,2827,130081,1962), - nrow = 16, ncol = 7, byrow = TRUE) - -expectedCovariance <- matrix(c( - 12333921.73333333246, 3.679666000000000e+04, 343330206.333333313, - 1649102.666666666744, 1117681.066666666651, 23461965.733333334, 16240.93333333333248, - 36796.66000000000, 1.164576250000000e+02, 1063604.115416667, - 6258.666250000000, 3490.253750000000, 73503.000000000, 50.92333333333334, - 343330206.33333331347, 1.063604115416667e+06, 9879353659.329166412, - 56124369.854166664183, 30880428.345833335072, 685240944.600000024, 470977.90000000002328, - 1649102.66666666674, 6.258666250000000e+03, 56124369.854166664, - 873223.429166666698, -115378.762499999997, 4462741.533333333, 2973.03333333333330, - 1117681.06666666665, 3.490253750000000e+03, 30880428.345833335, - -115378.762499999997, 484304.095833333326, 1764098.133333333, 1382.43333333333339, - 23461965.73333333433, 7.350300000000000e+04, 685240944.600000024, - 4462741.533333333209, 1764098.133333333302, 48387348.933333330, 32917.40000000000146, - 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, - 85.8,36.5,12,7,33.77, - 76.9,43.5,17,15,5.16, - 76.1,35.3,9,7,90.57, - 83.8,70.2,16,7,92.85, - 92.4,67.8,14,8,97.16, - 82.4,53.3,12,7,97.67, - 82.9,45.2,16,13,91.38, - 87.1,64.5,14,6,98.61, - 64.1,62.0,21,12,8.52, - 66.9,67.5,14,7,2.27, - 68.9,60.7,19,12,4.43, - 61.7,69.3,22,5,2.82, - 68.3,72.6,18,2,24.20, - 71.7,34.0,17,8,3.30, - 55.7,19.4,26,28,12.11, - 54.3,15.2,31,20,2.15, - 65.1,73.0,19,9,2.84, - 65.5,59.8,22,10,5.23, - 65.0,55.1,14,3,4.52, - 56.6,50.9,22,12,15.14, - 57.4,54.1,20,6,4.20, - 72.5,71.2,12,1,2.40, - 74.2,58.1,14,8,5.23, - 72.0,63.5,6,3,2.56, - 60.5,60.8,16,10,7.72, - 58.3,26.8,25,19,18.46, - 65.4,49.5,15,8,6.10, - 75.5,85.9,3,2,99.71, - 69.3,84.9,7,6,99.68, - 77.3,89.7,5,2,100.00, - 70.5,78.2,12,6,98.96, - 79.4,64.9,7,3,98.22, - 65.0,75.9,9,9,99.06, - 92.2,84.6,3,3,99.46, - 79.3,63.1,13,13,96.83, - 70.4,38.4,26,12,5.62, - 65.7,7.7,29,11,13.79, - 72.7,16.7,22,13,11.22, - 64.4,17.6,35,32,16.92, - 77.6,37.6,15,7,4.97, - 67.6,18.7,25,7,8.65, - 35.0,1.2,37,53,42.34, - 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, - -64.3669287696577, -124.3928307123034, 63.64662349676226, 53.5758556891767, -190.5606105457909, - -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) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/descriptiveTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/descriptiveTestCases b/src/test/R/descriptiveTestCases deleted file mode 100644 index f6a6183..0000000 --- a/src/test/R/descriptiveTestCases +++ /dev/null @@ -1,83 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate summary statistics tests in -# org.apache.commons.math.stat.CertifiedDataTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -# R functions used -# mean(x) -# sd(x) -#------------------------------------------------------------------------------ -tol <- 1E-14 # error tolerance for tests -#------------------------------------------------------------------------------ -# Function definitions - -source("testFunctions") # utility test functions -options(digits=15) # bump displayed digits to 15 - -verifyMean <- function(values, expectedMean, tol, desc) { - results <- mean(values) - if (assertEquals(expectedMean, results, tol, "mean")) { - displayPadded(c(desc," mean test"), SUCCEEDED, WIDTH) - } else { - displayPadded(c(desc, " mean test"), FAILED, WIDTH) - } -} - -verifySigma <- function(values, expectedSigma, tol, desc) { - results <- sd(values) - if (assertEquals(expectedSigma, results, tol, "std")) { - displayPadded(c(desc," std test"), SUCCEEDED, WIDTH) - } else { - displayPadded(c(desc, " std test"), FAILED, WIDTH) - } -} - -cat("Descriptive test cases\n") - -# Michelson data -values <- c(299.85,299.74,299.90,300.07,299.93,299.85,299.95,299.98,299.98, -299.88,300.00,299.98,299.93,299.65,299.76,299.81,300.00,300.00,299.96,299.96, -299.96,299.94,299.96,299.94,299.88,299.80,299.85,299.88,299.90,299.84,299.83, -299.79,299.81,299.88,299.88,299.83,299.80,299.79,299.76,299.80,299.88,299.88, -299.88,299.86,299.72,299.72,299.62,299.86,299.97,299.95,299.88,299.91,299.85, -299.87,299.84,299.84,299.85,299.84,299.84,299.84,299.89,299.81,299.81,299.82, -299.80,299.77,299.76,299.74,299.75,299.76,299.91,299.92,299.89,299.86,299.88, -299.72,299.84,299.85,299.85,299.78,299.89,299.84,299.78,299.81,299.76,299.81, -299.79,299.81,299.82,299.85,299.87,299.87,299.81,299.74,299.81,299.94,299.95, -299.80,299.81,299.87) -expectedMean <- 299.852400000000 -expectedSigma <- 0.0790105478190518 -verifyMean(values, expectedMean, tol, "Michelson") -verifySigma(values, expectedSigma, tol, "Michelson") - -# Mavro data -values <- c(2.00180,2.00170,2.00180,2.00190,2.00180,2.00170,2.00150,2.00140, -2.00150,2.00150,2.00170,2.00180,2.00180,2.00190,2.00190,2.00210,2.00200, -2.00160,2.00140,2.00130,2.00130,2.00150,2.00150,2.00160,2.00150,2.00140, -2.00130,2.00140,2.00150,2.00140,2.00150,2.00160,2.00150,2.00160,2.00190, -2.00200,2.00200,2.00210,2.00220,2.00230,2.00240,2.00250,2.00270,2.00260, -2.00260,2.00260,2.00270,2.00260,2.00250,2.00240) -expectedMean <- 2.00185600000000 -expectedSigma <- 0.000429123454003053 -verifyMean(values, expectedMean, tol, "Mavro") -verifySigma(values, expectedSigma, tol, "Mavro") - -displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/exponentialTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/exponentialTestCases b/src/test/R/exponentialTestCases deleted file mode 100644 index c73e6dd..0000000 --- a/src/test/R/exponentialTestCases +++ /dev/null @@ -1,103 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate exponential distribution tests in -# org.apache.commons.math.distribution.ExponentialDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -#------------------------------------------------------------------------------ -tol <- 1E-9 - -# Function definitions - -source("testFunctions") # utility test functions - -# function to verify distribution computations - -verifyDistribution <- function(points, expected, mean, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- pexp(point, 1/mean) - } - output <- c("Distribution test mean = ", mean) - if (assertEquals(expected, rDistValues, tol, "Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify density computations -verifyDensity <- function(points, expected, mean, tol) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dexp(point, 1/mean) - } - output <- c("Density test mean = ", mean) - if (assertEquals(expected, rDensityValues, tol, "Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify quantiles -verifyQuantiles <- function(points, expected, mean, tol) { - rQuantileValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rQuantileValues[i] <- qexp(point, 1/mean, log = FALSE) - } - output <- c("Quantile test mean = ", mean) - if (assertEquals(expected, rQuantileValues, tol, "Quantile Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - - -#-------------------------------------------------------------------------- -cat("Exponential test cases\n") - -mean <- 5 - -distributionValues <- c(0, 0, 0.001, 0.01, 0.025, 0.05, 0.1, 0.999, - 0.990, 0.975, 0.950, 0.900) -densityValues <- c(0.2, 0.2, 0.1998, 0.198, 0.195, 0.19, 0.18, 0.000200000000000, - 0.00200000000002, 0.00499999999997, 0.00999999999994, 0.0199999999999) -distributionPoints <- c(0, 0, 0.00500250166792, 0.0502516792675, 0.126589039921, 0.256466471938, - 0.526802578289, 34.5387763949, 23.0258509299, 18.4443972706, 14.9786613678, 11.5129254650) -verifyDistribution(distributionPoints, distributionValues, mean, tol) -verifyQuantiles(distributionValues, distributionPoints, mean, tol) -verifyDensity(distributionPoints, densityValues, mean, tol) - -output <- "Probability test P(.25 < X < .75)" -if (assertEquals(0.0905214480757, pexp(.75, 1/mean) - pexp(.25, 1/mean), tol, "Probability value")) { - displayPadded(output, SUCCEEDED, WIDTH) -} else { - displayPadded(output, FAILED, WIDTH) -} - -displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/geometricTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/geometricTestCases b/src/test/R/geometricTestCases deleted file mode 100644 index 96ca82e..0000000 --- a/src/test/R/geometricTestCases +++ /dev/null @@ -1,121 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate Geometric distribution tests in -# org.apache.commons.math.distribution.GeometricDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -# R functions used -# 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 -#------------------------------------------------------------------------------ -tol <- 1E-6 # error tolerance for tests -#------------------------------------------------------------------------------ -# Function definitions - -source("testFunctions") # utility test functions - -# function to verify density computations - -verifyDensity <- function(points, expected, prob, tol, log = FALSE) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dgeom(point, prob, log) - } - output <- c("Density test prob = ", prob) - if (assertEquals(expected,rDensityValues,tol,"Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify distribution computations - -verifyDistribution <- function(points, expected, prob, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- pgeom(point, prob) - } - output <- c("Distribution test prob = ", prob) - if (assertEquals(expected,rDistValues,tol,"Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Geometric test cases\n") - -prob <- 0.4 - -densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28) -densityValues <- c(0, 0.4, 0.24, 0.144, 0.0864, 0.05184, 0.031104, 0.0186624, 0.01119744, 0.006718464, - 0.0040310784, 0.00241864704, 0.001451188224, 0.0008707129344, 0.00052242776064, - 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) -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, - -7.04619821706604, -7.55702384083203, -8.06784946459802, -8.57867508836402, - -9.08950071213001, -9.600326335896, -10.111151959662, -10.621977583428, - -11.132803207194, -11.64362883096, -12.154454454726, -12.6652800784919, -13.1761057022579, - -13.6869313260239, -14.1977569497899, -14.7085825735559, -15.2194081973219) -distributionValues <- c(0, 0.4, 0.64, 0.784, 0.8704, 0.92224, 0.953344, 0.9720064, 0.98320384, 0.989922304, - 0.9939533824, 0.99637202944, 0.997823217664, 0.9986939305984, 0.99921635835904, - 0.999529815015424, 0.999717889009254, 0.999830733405553, 0.999898440043332, - 0.999939064025999, 0.999963438415599, 0.99997806304936, 0.999986837829616, - 0.99999210269777, 0.999995261618662, 0.999997156971197, 0.999998294182718, - 0.999998976509631, 0.999999385905779, 0.999999631543467) -#Eliminate p=1 case because it will mess up adjustement below -inverseCumPoints <- c(0, 0.001, 0.010, 0.025, 0.050, 0.100, 0.999, - 0.990, 0.975, 0.950, 0.900) -inverseCumValues <- c(-1, -1, -1, -1, -1, -1, 12, 8, 6, 4, 3) - -verifyDensity(densityPoints, densityValues, prob, tol) -verifyDensity(densityPoints, logDensityValues, prob, tol, TRUE) -verifyDistribution(densityPoints, distributionValues, prob, tol) - -i <- 0 -rInverseCumValues <- rep(0,length(inverseCumPoints)) -for (point in inverseCumPoints) { - i <- i + 1 - rInverseCumValues[i] <- qgeom(point, prob) -} - -output <- c("Inverse Distribution test prob = ", prob) -# R defines quantiles from the right, need to subtract one -if (assertEquals(inverseCumValues, rInverseCumValues-1, tol, - "Inverse Dist Values")) { - displayPadded(output, SUCCEEDED, 80) -} else { - displayPadded(output, FAILED, 80) -} - -displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/gumbelTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/gumbelTestCases.R b/src/test/R/gumbelTestCases.R deleted file mode 100644 index e4fea7c..0000000 --- a/src/test/R/gumbelTestCases.R +++ /dev/null @@ -1,85 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate Gumbel distribution tests in -# org.apache.commons.complex.distribution.GumbelDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -# R functions used -# dgumbel(x, location = 0, scale = 1, log = FALSE, max = TRUE) -# pgumbel(q, location = 0, scale = 1, lower.tail = TRUE, max = TRUE) - -#----------------------------------------------------------------------------- -tol <- 1E-9 - -# Function definitions - -source("testFunctions") # utility test functions -library("VGAM") - -# function to verify distribution computations -verifyDistribution <- function(points, expected, m, s, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- pgumbel(point, m, s) - } - output <- c("Distribution test m = ",m,", s = ", s) - if (assertEquals(expected, rDistValues, tol, "Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify density computations -verifyDensity <- function(points, expected, m, s, tol) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dgumbel(point, m, s) - } - output <- c("Density test m = ",m,", s = ", s) - if (assertEquals(expected, rDensityValues, tol, "Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Gumbel test cases\n") - -m <- 0.5 -s <- 2 -distributionPoints <- c(-5:5) -densityValues <- c(1.2582621126545528E-6,3.5946885566568164E-4,0.009115765822384943,0.05321099995044945,0.12743521041151834,0.17778637369097208,0.17871767308609124,0.14726615762017733,0.10756585897012155,0.07302735923472656,0.047427815138561126) -distributionValues <- c(1.6087601139887782E-7,7.577547728260715E-5,0.003168165149053243,0.03049041346306221,0.12039226207982957,0.27692033409990896,0.4589560693076638,0.6235249162568004,0.7508834766393948,0.8404868737475784,0.8999651626606278) -verifyDistribution(distributionPoints, distributionValues, m, s, tol) -verifyDensity(distributionPoints, densityValues, m, s, tol) - -m <- 1.5 -s <- 3 -distributionPoints <- c(-5:5) -densityValues <- c(4.707967970909721E-4,0.004005928431315734,0.01690237120332691,0.04314381688828758,0.07682272023182242,0.10568064035931406,0.12083781131699158,0.12102469295161239,0.11023476629680602,0.09380437047469757,0.07602582610501195) -distributionValues <- c(1.6180181049060529E-4,0.0019214004612365587,0.011314286380459627,0.04030537101298144,0.10016104975617146,0.1922956455479649,0.30686099686684076,0.42892134369676455,0.545239211892605,0.6475247847679736,0.7324184876698198) -verifyDistribution(distributionPoints, distributionValues, m, s, tol) -verifyDensity(distributionPoints, densityValues, m, s, tol) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/hypergeometricTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/hypergeometricTestCases b/src/test/R/hypergeometricTestCases deleted file mode 100644 index 04bc8a0..0000000 --- a/src/test/R/hypergeometricTestCases +++ /dev/null @@ -1,139 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate Hypergeometric distribution tests in -# org.apache.commons.math.distribution.HypergeometricDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -# R functions used -# 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 -#------------------------------------------------------------------------------ -tol <- 1E-6 # error tolerance for tests -#------------------------------------------------------------------------------ -# Function definitions - -source("testFunctions") # utility test functions - -# function to verify density computations - -verifyDensity <- function(points, expected, good, bad, selected, tol, log = FALSE) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dhyper(point, good, bad, selected, log) - } - 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 - -verifyDistribution <- function(points, expected, good, bad, selected, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- phyper(point, good, bad, selected) - } - output <- c("Distribution test good = ", good, ", bad = ", - bad, ", selected = ",selected) - if (assertEquals(expected,rDistValues,tol,"Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Hypergeometric test cases\n") - -good <- 5 -bad <- 5 -selected <- 5 - -densityPoints <- c(-1, 0, 1, 2, 3, 4, 5, 10) -densityValues <- c(0, 0.00396825396825397, 0.0992063492063492, 0.396825396825397, 0.396825396825397, - 0.0992063492063492, 0.00396825396825397, 0) -logDensityValues <- c(-Inf, -5.52942908751142, -2.31055326264322, -0.924258901523332, - -0.924258901523332, -2.31055326264322, -5.52942908751142, -Inf) -distributionValues <- c(0, .003968, .103175, .50000, .896825, .996032, - 1.00000, 1) -#Eliminate p=1 case because it will mess up adjustement below -inverseCumPoints <- c(0, 0.001, 0.010, 0.025, 0.050, 0.100, 0.999, - 0.990, 0.975, 0.950, 0.900) -inverseCumValues <- c(-1, -1, 0, 0, 0, 0, 4, 3, 3, 3, 3) - -verifyDensity(densityPoints, densityValues, good, bad, selected, tol) -verifyDensity(densityPoints, logDensityValues, good, bad, selected, tol, TRUE) -verifyDistribution(densityPoints, distributionValues, good, bad, selected, tol) - -i <- 0 -rInverseCumValues <- rep(0,length(inverseCumPoints)) -for (point in inverseCumPoints) { - i <- i + 1 - rInverseCumValues[i] <- qhyper(point, good, bad, selected) -} - -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, - "Inverse Dist Values")) { - displayPadded(output, SUCCEEDED, 80) -} else { - displayPadded(output, FAILED, 80) -} - -# Degenerate cases -good <- 5 -bad <- 0 -selected <- 3 -densityPoints <- c(-1, 0, 1, 3, 10) -densityValues <- c(0, 0, 0, 1, 0) -distributionValues <- c(0, 0, 0, 1, 1) -verifyDensity(densityPoints, densityValues, good, bad, selected, tol) -verifyDistribution(densityPoints, distributionValues, good, bad, selected, tol) - -good <- 0 -bad <- 5 -selected <- 3 -densityPoints <- c(-1, 0, 1, 3, 10) -densityValues <- c(0, 1, 0, 0, 0) -distributionValues <- c(0, 1, 1, 1, 1) -verifyDensity(densityPoints, densityValues, good, bad, selected, tol) -verifyDistribution(densityPoints, distributionValues, good, bad, selected, tol) - -good <- 3 -bad <- 2 -selected <- 5 -densityPoints <- c(-1, 0, 1, 3, 10) -densityValues <- c(0, 0, 0, 1, 0) -distributionValues <- c(0, 0, 0, 1, 1) -verifyDensity(densityPoints, densityValues, good, bad, selected, tol) -verifyDistribution(densityPoints, distributionValues, good, bad, selected, tol) - -displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/laplaceTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/laplaceTestCases.R b/src/test/R/laplaceTestCases.R deleted file mode 100644 index 0229787..0000000 --- a/src/test/R/laplaceTestCases.R +++ /dev/null @@ -1,85 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate Laplace distribution tests in -# org.apache.commons.complex.distribution.LaplaceDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -# R functions used -# dlaplace(x, location = 0, scale = 1, log = FALSE, max = TRUE) -# plaplace(q, location = 0, scale = 1, lower.tail = TRUE, max = TRUE) - -#----------------------------------------------------------------------------- -tol <- 1E-9 - -# Function definitions - -source("testFunctions") # utility test functions -library("VGAM") - -# function to verify distribution computations -verifyDistribution <- function(points, expected, m, s, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- plaplace(point, m, s) - } - output <- c("Distribution test m = ",m,", s = ", s) - if (assertEquals(expected, rDistValues, tol, "Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify density computations -verifyDensity <- function(points, expected, m, s, tol) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dlaplace(point, m, s) - } - output <- c("Density test m = ",m,", s = ", s) - if (assertEquals(expected, rDensityValues, tol, "Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Laplace test cases\n") - -m <- 0 -s <- 1 -distributionPoints <- c(-5:5) -densityValues <- c(0.0033689734995427335,0.00915781944436709,0.024893534183931972,0.06766764161830635,0.18393972058572117,0.5,0.18393972058572117,0.06766764161830635,0.024893534183931972,0.00915781944436709,0.0033689734995427335) -distributionValues <- c(0.0033689734995427335,0.00915781944436709,0.024893534183931972,0.06766764161830635,0.18393972058572117,0.5,0.8160602794142788,0.9323323583816936,0.9751064658160681,0.9908421805556329,0.9966310265004573) -verifyDistribution(distributionPoints, distributionValues, m, s, tol) -verifyDensity(distributionPoints, densityValues, m, s, tol) - -m <- -5 -s <- 4 -distributionPoints <- c(-5:5) -densityValues <- c(0.125,0.09735009788392561,0.07581633246407918,0.059045819092626836,0.04598493014643029,0.03581309960752376,0.027891270018553727,0.021721742931305642,0.016916910404576588,0.013174903070233042,0.01026062482798735) -distributionValues <- c(0.5,0.6105996084642975,0.6967346701436833,0.7638167236294926,0.8160602794142788,0.8567476015699049,0.888434919925785,0.9131130282747775,0.9323323583816936,0.9473003877190679,0.9589575006880506) -verifyDistribution(distributionPoints, distributionValues, m, s, tol) -verifyDensity(distributionPoints, densityValues, m, s, tol) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/logNormalTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/logNormalTestCases b/src/test/R/logNormalTestCases deleted file mode 100644 index ac0ca30..0000000 --- a/src/test/R/logNormalTestCases +++ /dev/null @@ -1,107 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate LogNormal distribution tests in -# org.apache.commons.math.distribution.LogNormalDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -# R functions used -# plnorm(q, mean=0, sd=1, lower.tail = TRUE, log.p = FALSE) <-- distribution -#----------------------------------------------------------------------------- -tol <- 1E-9 - -# Function definitions - -source("testFunctions") # utility test functions - -# function to verify distribution computations - -verifyDistribution <- function(points, expected, mu, sigma, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- plnorm(point, mu, sigma, log = FALSE) - } - output <- c("Distribution test mu = ",mu,", sigma = ", sigma) - if (assertEquals(expected, rDistValues, tol, "Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify density computations - -verifyDensity <- function(points, expected, mu, sigma, tol) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dlnorm(point, mu, sigma, log = FALSE) - } - output <- c("Density test mu = ",mu,", sigma = ", sigma) - if (assertEquals(expected, rDensityValues, tol, "Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("LogNormal test cases\n") - -mu <- 2.1 -sigma <- 1.4 -distributionValues <- c(0, 0, 0, 0, 0.00948199951485, 0.432056525076, 0.381648158697, 0.354555726206, 0.329513316888, 0.298422824228) -densityValues <- c(0, 0, 0, 0, 0.0594218160072, 0.0436977691036, 0.0508364857798, 0.054873528325, 0.0587182664085, 0.0636229042785) -distributionPoints <- c(-2.226325228634938, -1.156887023657177, -0.643949578356075, -0.2027950777320613, 0.305827808237559, - 6.42632522863494, 5.35688702365718, 4.843949578356074, 4.40279507773206, 3.89417219176244) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -distributionValues <- c(0, 0.0396495152787, 0.16601209243, 0.272533253269, 0.357618409638, 0.426488363093, 0.483255136841, 0.530823013877) -densityValues <- c(0, 0.0873055825147, 0.0847676303432, 0.0677935186237, 0.0544105523058, 0.0444614628804, 0.0369750288945, 0.0312206409653) -distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma, - mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma, - mu + 5 * sigma) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -mu <- 0 -sigma <- 1 -distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma, - mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma, - mu + 5 * sigma) -distributionValues <- c(0, 0, 0, 0.5, 0.755891404214, 0.864031392359, 0.917171480998, 0.946239689548) -densityValues <- c(0, 0, 0, 0.398942280401, 0.156874019279, 0.07272825614, 0.0381534565119, 0.0218507148303) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -mu <- 0 -sigma <- 0.1 -distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma, - mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma, - mu + 5 * sigma) -distributionValues <- c(0, 0, 0, 1.28417563064e-117, 1.39679883412e-58, 1.09839325447e-33, 2.52587961726e-20, 2.0824223487e-12) -densityValues <- c(0, 0, 0, 2.96247992535e-114, 1.1283370232e-55, 4.43812313223e-31, 5.85346445002e-18, 2.9446618076e-10) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/logisticsTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/logisticsTestCases.R b/src/test/R/logisticsTestCases.R deleted file mode 100644 index ff40d73..0000000 --- a/src/test/R/logisticsTestCases.R +++ /dev/null @@ -1,85 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate Logistics distribution tests in -# org.apache.commons.complex.distribution.LogisticsDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -# R functions used -# dlogis(x, location = 0, scale = 1, log = FALSE, max = TRUE) -# plogis(q, location = 0, scale = 1, lower.tail = TRUE, max = TRUE) - -#----------------------------------------------------------------------------- -tol <- 1E-9 - -# Function definitions - -source("testFunctions") # utility test functions -library("VGAM") - -# function to verify distribution computations -verifyDistribution <- function(points, expected, m, s, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- plogis(point, m, s) - } - output <- c("Distribution test m = ",m,", s = ", s) - if (assertEquals(expected, rDistValues, tol, "Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify density computations -verifyDensity <- function(points, expected, m, s, tol) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dlogis(point, m, s) - } - output <- c("Density test m = ",m,", s = ", s) - if (assertEquals(expected, rDensityValues, tol, "Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Logistics test cases\n") - -m <- 5 -s <- 2 -distributionPoints <- c(-5:5) -densityValues <- c(0.0033240283353950773,0.005433114861112618,0.008831353106645559,0.014226511939867782,0.022588329865456065,0.03505185827255408,0.05249679270175326,0.07457322603516643,0.09830596662074093,0.11750185610079725,0.125) -distributionValues <- c(0.0066928509242848554,0.01098694263059318,0.01798620996209156,0.02931223075135632,0.04742587317756678,0.07585818002124355,0.11920292202211755,0.18242552380635635,0.2689414213699951,0.3775406687981454,0.5) -verifyDistribution(distributionPoints, distributionValues, m, s, tol) -verifyDensity(distributionPoints, densityValues, m, s, tol) - -m <- 9 -s <- 3 -distributionPoints <- c(-5:5) -densityValues <- c(0.0030763907488492496,0.004261976157918787,0.005887568737763705,0.008101066534475556,0.01108624138724253,0.01505888657697071,0.020249392063798367,0.026861724758915424,0.03499786180116884,0.04454323746508397,0.0550303365509679) -distributionValues <- c(0.009315959345066693,0.012953727530695871,0.01798620996209156,0.02492442664711404,0.03444519566621118,0.04742587317756678,0.06496916912866407,0.08839967720705845,0.11920292202211755,0.15886910488091516,0.20860852732604496) -verifyDistribution(distributionPoints, distributionValues, m, s, tol) -verifyDensity(distributionPoints, densityValues, m, s, tol) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/multipleOLSRegressionTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/multipleOLSRegressionTestCases b/src/test/R/multipleOLSRegressionTestCases deleted file mode 100644 index 458426f..0000000 --- a/src/test/R/multipleOLSRegressionTestCases +++ /dev/null @@ -1,309 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate OLS multiple regression tests in -# org.apache.commons.math.stat.regression.OLSMultipleLinearRegressionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -#------------------------------------------------------------------------------ -tol <- 1E-8 # default error tolerance for tests -#------------------------------------------------------------------------------ -# Function definitions - -source("testFunctions") # utility test functions -options(digits=16) # override number of digits displayed - -# function to verify OLS computations - -verifyRegression <- function(model, expectedBeta, expectedResiduals, - expectedErrors, expectedStdError, expectedRSquare, expecteAdjRSquare, modelName) { - betaHat <- as.vector(coefficients(model)) - residuals <- as.vector(residuals(model)) - errors <- as.vector(as.matrix(coefficients(summary(model)))[,2]) - stdError <- summary(model)$sigma - rSquare <- summary(model)$r.squared - adjRSquare <- summary(model)$adj.r.squared - output <- c("Parameter test dataset = ", modelName) - if (assertEquals(expectedBeta,betaHat,tol,"Parameters")) { - 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) - } else { - displayPadded(output, FAILED, WIDTH) - } - output <- c("Standard Error test dataset = ", modelName) - if (assertEquals(expectedStdError,stdError,tol,"Regression Standard Error")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } - output <- c("RSquared test dataset = ", modelName) - if (assertEquals(expectedRSquare,rSquare,tol,"RSquared")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } - output <- c("Adjusted RSquared test dataset = ", modelName) - if (assertEquals(expecteAdjRSquare,adjRSquare,tol,"Adjusted RSquared")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Multiple regression OLS test cases\n") - -# Perfect fit -x1 <- c(0,2,0,0,0,0) -x2 <- c(0,0,3,0,0,0) -x3 <- c(0,0,0,4,0,0) -x4 <- c(0,0,0,0,5,0) -x5 <- c(0,0,0,0,0,6) -y <- c(11, 12, 13, 14, 15, 16) -model <- lm(y ~ x1 + x2 + x3 + x4 + x5) -expectedBeta <- c(11.0,0.5,0.666666666666667,0.75,0.8,0.8333333333333333) -expectedResiduals <- c(0,0,0,0,0,0) -expectedErrors <- c(NaN,NaN,NaN,NaN,NaN,NaN) -expectedStdError <- NaN -expectedRSquare <- 1 -expectedAdjRSquare <- NaN -verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors, - 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, -# vol. 62. September, pp. 819-841. -# -# Certified values (and data) are from NIST: -# http://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Longley.dat -# -design <- matrix(c(60323,83.0,234289,2356,1590,107608,1947, - 61122,88.5,259426,2325,1456,108632,1948, - 60171,88.2,258054,3682,1616,109773,1949, - 61187,89.5,284599,3351,1650,110929,1950, - 63221,96.2,328975,2099,3099,112075,1951, - 63639,98.1,346999,1932,3594,113270,1952, - 64989,99.0,365385,1870,3547,115094,1953, - 63761,100.0,363112,3578,3350,116219,1954, - 66019,101.2,397469,2904,3048,117388,1955, - 67857,104.6,419180,2822,2857,118734,1956, - 68169,108.4,442769,2936,2798,120445,1957, - 66513,110.8,444546,4681,2637,121950,1958, - 68655,112.6,482704,3813,2552,123366,1959, - 69564,114.2,502601,3931,2514,125368,1960, - 69331,115.7,518173,4806,2572,127852,1961, - 70551,116.9,554894,4007,2827,130081,1962), - nrow = 16, ncol = 7, byrow = TRUE) -y <- design[,1] -x1 <- design[,2] -x2 <- design[,3] -x3 <- design[,4] -x4 <- design[,5] -x5 <- design[,6] -x6 <- design[,7] -model <- lm(y ~ x1 + x2 + x3 + x4 + x5 + x6) - -estimates <- matrix(c(-3482258.63459582,890420.383607373, - 15.0618722713733,84.9149257747669, - -0.358191792925910E-01,0.334910077722432E-01, - -2.02022980381683,0.488399681651699, - -1.03322686717359,0.214274163161675, - -0.511041056535807E-01,0.226073200069370, - 1829.15146461355,455.478499142212), - nrow = 7, ncol = 2, byrow = TRUE) - -expectedBeta <- estimates[,1] -expectedErrors <- estimates[,2] -expectedResiduals <- c(267.340029759711,-94.0139423988359,46.28716775752924, - -410.114621930906,309.7145907602313,-249.3112153297231,-164.0489563956039, - -13.18035686637081,14.30477260005235,455.394094551857,-17.26892711483297, - -39.0550425226967,-155.5499735953195,-85.6713080421283,341.9315139607727, - -206.7578251937366) -expectedStdError <- 304.8540735619638 -expectedRSquare <- 0.995479004577296 -expectedAdjRSquare <- 0.992465007628826 - -verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors, -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, - 0.07107319907358, 0.03016640003786, - -0.42346585566399, 0.41773654056612, - -0.57256866841929, 0.27899087467676, - -0.41420358884978, 0.32128496193363, - 48.41786562001326, 17.68948737819961), - nrow = 6, ncol = 2, byrow = TRUE) - -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, - -8.56475876776709, -361.32974610842876, 27.34560497213464, 151.28955976355002, - -492.49937355336846) -expectedStdError <- 475.1655079819517 -expectedRSquare <- 0.9999670130706 -expectedAdjRSquare <- 0.999947220913 - -verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors, -expectedStdError, expectedRSquare, expectedAdjRSquare, "Longley No Intercept") - -# Swiss Fertility (R dataset named "swiss") - -design <- 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, - 85.8,36.5,12,7,33.77, - 76.9,43.5,17,15,5.16, - 76.1,35.3,9,7,90.57, - 83.8,70.2,16,7,92.85, - 92.4,67.8,14,8,97.16, - 82.4,53.3,12,7,97.67, - 82.9,45.2,16,13,91.38, - 87.1,64.5,14,6,98.61, - 64.1,62.0,21,12,8.52, - 66.9,67.5,14,7,2.27, - 68.9,60.7,19,12,4.43, - 61.7,69.3,22,5,2.82, - 68.3,72.6,18,2,24.20, - 71.7,34.0,17,8,3.30, - 55.7,19.4,26,28,12.11, - 54.3,15.2,31,20,2.15, - 65.1,73.0,19,9,2.84, - 65.5,59.8,22,10,5.23, - 65.0,55.1,14,3,4.52, - 56.6,50.9,22,12,15.14, - 57.4,54.1,20,6,4.20, - 72.5,71.2,12,1,2.40, - 74.2,58.1,14,8,5.23, - 72.0,63.5,6,3,2.56, - 60.5,60.8,16,10,7.72, - 58.3,26.8,25,19,18.46, - 65.4,49.5,15,8,6.10, - 75.5,85.9,3,2,99.71, - 69.3,84.9,7,6,99.68, - 77.3,89.7,5,2,100.00, - 70.5,78.2,12,6,98.96, - 79.4,64.9,7,3,98.22, - 65.0,75.9,9,9,99.06, - 92.2,84.6,3,3,99.46, - 79.3,63.1,13,13,96.83, - 70.4,38.4,26,12,5.62, - 65.7,7.7,29,11,13.79, - 72.7,16.7,22,13,11.22, - 64.4,17.6,35,32,16.92, - 77.6,37.6,15,7,4.97, - 67.6,18.7,25,7,8.65, - 35.0,1.2,37,53,42.34, - 44.7,46.6,16,29,50.43, - 42.8,27.7,22,29,58.33), - nrow = 47, ncol = 5, byrow = TRUE) - -y <- design[,1] -x1 <- design[,2] -x2 <- design[,3] -x3 <- design[,4] -x4 <- design[,5] - -model <- lm(y ~ x1 + x2 + x3 + x4) - -estimates <- matrix(c(91.05542390271397,6.94881329475087, - -0.22064551045715,0.07360008972340, - -0.26058239824328,0.27410957467466, - -0.96161238456030,0.19454551679325, - 0.12441843147162,0.03726654773803), - nrow = 5, ncol = 2, byrow = TRUE) - -expectedBeta <- estimates[,1] -expectedErrors <- estimates[,2] - -expectedResiduals <- c(7.1044267859730512,1.6580347433531366, - 4.6944952770029644,8.4548022690166160,13.6547432343186212, - -9.3586864458500774,7.5822446330520386,15.5568995563859289, - 0.8113090736598980,7.1186762732484308,7.4251378771228724, - 2.6761316873234109,0.8351584810309354,7.1769991119615177, - -3.8746753206299553,-3.1337779476387251,-0.1412575244091504, - 1.1186809170469780,-6.3588097346816594,3.4039270429434074, - 2.3374058329820175,-7.9272368576900503,-7.8361010968497959, - -11.2597369269357070,0.9445333697827101,6.6544245101380328, - -0.9146136301118665,-4.3152449403848570,-4.3536932047009183, - -3.8907885169304661,-6.3027643926302188,-7.8308982189289091, - -3.1792280015332750,-6.7167298771158226,-4.8469946718041754, - -10.6335664353633685,11.1031134362036958,6.0084032641811733, - 5.4326230830188482,-7.2375578629692230,2.1671550814448222, - 15.0147574652763112,4.8625103516321015,-7.1597256413907706, - -0.4515205619767598,-10.2916870903837587,-15.7812984571900063) - -expectedStdError <- 7.73642194433223 -expectedRSquare <- 0.649789742860228 -expectedAdjRSquare <- 0.6164363850373927 - -verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors, -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.30851985863609, 0.07694953606522), - nrow = 4, ncol = 2, byrow = TRUE) - -expectedBeta <- estimates[,1] -expectedErrors <- estimates[,2] - -expectedResiduals <- c(44.138759883538249, 27.720705122356215, 35.873200836126799, - 34.574619581211977, 26.600168342080213, 15.074636243026923, -12.704904871199814, - 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, - -13.762961360873966, 7.156100301980509, 16.722282219843990, 26.716200609071898, - -1.991466398777079, -2.523342564719335, 9.776486693095093, -5.297535127628603, - -16.639070567471094, -10.302057295211819, -23.549487860816846, 1.506624392156384, - -17.939174438345930, 13.105792202765040, -1.943329906928462, -1.516005841666695, - -0.759066561832886, 20.793137744128977, -2.485236153005426, 27.588238710486976, - 2.658333257106881, -15.998337823623046, -5.550742066720694, -14.219077806826615) - -expectedStdError <- 17.24710630547 -expectedRSquare <- 0.946350722085 -expectedAdjRSquare <- 0.9413600915813 - -verifyRegression(model, expectedBeta, expectedResiduals, expectedErrors, -expectedStdError, expectedRSquare, expectedAdjRSquare, "Swiss Fertility No Intercept") - -displayDashes(WIDTH) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/nakagamiTestCases.R ---------------------------------------------------------------------- diff --git a/src/test/R/nakagamiTestCases.R b/src/test/R/nakagamiTestCases.R deleted file mode 100644 index 71c1765..0000000 --- a/src/test/R/nakagamiTestCases.R +++ /dev/null @@ -1,85 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate Nakagami distribution tests in -# org.apache.commons.complex.distribution.NakagamiDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -# R functions used -# dnaka(x, location = 0, scale = 1, log = FALSE, max = TRUE) -# pnaka(q, location = 0, scale = 1, lower.tail = TRUE, max = TRUE) - -#----------------------------------------------------------------------------- -tol <- 1E-9 - -# Function definitions - -source("testFunctions") # utility test functions -library("VGAM") - -# function to verify distribution computations -verifyDistribution <- function(points, expected, m, s, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- pnaka(point, s, m) - } - output <- c("Distribution test m = ",m,", s = ", s) - if (assertEquals(expected, rDistValues, tol, "Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify density computations -verifyDensity <- function(points, expected, m, s, tol) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dnaka(point, s, m) - } - output <- c("Density test m = ",m,", s = ", s) - if (assertEquals(expected, rDensityValues, tol, "Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Nakagami test cases\n") - -m <- 0.5 -s <- 1 -distributionPoints <- seq(from = 0, to = 2, by = 0.2) -densityValues <- c(0.0,0.7820853879509118,0.7365402806066467,0.6664492057835993,0.5793831055229655,0.48394144903828673,0.38837210996642585,0.29945493127148964,0.2218416693589111,0.1579003166017883,0.10798193302637613) -distributionValues <- c(0.0,0.15851941887820603,0.3108434832206483,0.45149376449985296,0.5762892028332065,0.6826894921370859,0.7698606595565836,0.8384866815324576,0.8904014166008841,0.9281393617741498,0.9544997361036424) -verifyDistribution(distributionPoints, distributionValues, m, s, tol) -verifyDensity(distributionPoints, densityValues, m, s, tol) - -m <- 1 -s <- 2 -distributionPoints <- seq(from = 0, to = 2, by = 0.2) -densityValues <- c(0.0,0.19603973466135105,0.36924653855465434,0.5011621268467633,0.5809192296589527,0.6065306597126334,0.584102707151966,0.5254355383919593,0.44485968072511056,0.3562176583505064,0.2706705664732254) -distributionValues <- c(0.0,0.0198013266932447,0.07688365361336423,0.16472978858872803,0.273850962926309,0.3934693402873665,0.5132477440400285,0.6246889011486005,0.7219626995468056,0.8021013009163853,0.8646647167633873) -verifyDistribution(distributionPoints, distributionValues, m, s, tol) -verifyDensity(distributionPoints, densityValues, m, s, tol) http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/a752ab8d/src/test/R/normalTestCases ---------------------------------------------------------------------- diff --git a/src/test/R/normalTestCases b/src/test/R/normalTestCases deleted file mode 100644 index 7be2e75..0000000 --- a/src/test/R/normalTestCases +++ /dev/null @@ -1,111 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#------------------------------------------------------------------------------ -# R source file to validate Normal distribution tests in -# org.apache.commons.math.distribution.NormalDistributionTest -# -# To run the test, install R, put this file and testFunctions -# into the same directory, launch R from this directory and then enter -# source("<name-of-this-file>") -# -# R functions used -# pnorm(q, mean=0, sd=1, lower.tail = TRUE, log.p = FALSE) <-- distribution -#----------------------------------------------------------------------------- -tol <- 1E-9 - -# Function definitions - -source("testFunctions") # utility test functions - -# function to verify distribution computations - -verifyDistribution <- function(points, expected, mu, sigma, tol) { - rDistValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDistValues[i] <- pnorm(point, mu, sigma, log = FALSE) - } - output <- c("Distribution test mu = ",mu,", sigma = ", sigma) - if (assertEquals(expected, rDistValues, tol, "Distribution Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -# function to verify density computations - -verifyDensity <- function(points, expected, mu, sigma, tol) { - rDensityValues <- rep(0, length(points)) - i <- 0 - for (point in points) { - i <- i + 1 - rDensityValues[i] <- dnorm(point, mu, sigma, log = FALSE) - } - output <- c("Density test mu = ",mu,", sigma = ", sigma) - if (assertEquals(expected, rDensityValues, tol, "Density Values")) { - displayPadded(output, SUCCEEDED, WIDTH) - } else { - displayPadded(output, FAILED, WIDTH) - } -} - -#-------------------------------------------------------------------------- -cat("Normal test cases\n") - -mu <- 2.1 -sigma <- 1.4 -distributionValues <- c(0.001, 0.01, 0.025, 0.05, 0.1, 0.999, - 0.990, 0.975, 0.950, 0.900) -densityValues <- c(0.00240506434076, 0.0190372444310, 0.0417464784322, 0.0736683145538, 0.125355951380, - 0.00240506434076, 0.0190372444310, 0.0417464784322, 0.0736683145538, 0.125355951380) -distributionPoints <- c(-2.226325228634938, -1.156887023657177, -0.643949578356075, -0.2027950777320613, 0.305827808237559, - 6.42632522863494, 5.35688702365718, 4.843949578356074, 4.40279507773206, 3.89417219176244) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -distributionValues <- c( 0.0227501319482, 0.158655253931, 0.5, 0.841344746069, 0.977249868052, - 0.998650101968, 0.999968328758, 0.999999713348) -densityValues <- c(0.0385649760808, 0.172836231799, 0.284958771715, 0.172836231799, 0.0385649760808, - 0.00316560600853, 9.55930184035e-05, 1.06194251052e-06) -distributionPoints <- c(mu - 2 *sigma, mu - sigma, mu, mu + sigma, - mu + 2 * sigma, mu + 3 * sigma, mu + 4 * sigma, - mu + 5 * sigma) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -mu <- 0 -sigma <- 1 -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) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -mu <- 0 -sigma <- 0.1 -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) -verifyDistribution(distributionPoints, distributionValues, mu, sigma, tol) -verifyDensity(distributionPoints, densityValues, mu, sigma, tol) - -displayDashes(WIDTH)
