Permalink
Browse files

Replaced f stat with new test from alglib and added test

  • Loading branch information...
1 parent fa23ef9 commit 50a40b08ba8ee9059f15f58a29efec7aaea28215 @guyrt committed Mar 24, 2012
View
@@ -7,3 +7,6 @@
build/*
*/QsnpgwaTest/*
+snplash/docs/doxygen.conf
+snplash/snplash
+snplash/snplashUnitTestDriver
@@ -5,6 +5,7 @@
set ( SNPLASH_TEST_CORE
${CMAKE_CURRENT_SOURCE_DIR}/LR_Engine_Test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/StringUtils_Test.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Statistics_Test.cpp
PARENT_SCOPE)
SET(INTERFACE_LIBRARIES ${SNPLASH_TEST_CORE} PARENT_SCOPE )
@@ -7,94 +7,93 @@
class LR_Engine_Test : public ::testing::Test {
- protected:
-
- vector<vector<double> > inMat;
- vector<double> phenotype;
- vector<double> ones;
- LogisticRegression lr;
-
- virtual void SetUp(){
- ones = vector<double>(6,1.0);
- vector<double> m1;
- m1.push_back(0);
- m1.push_back(2);
- m1.push_back(1);
- m1.push_back(0);
- m1.push_back(-1);
- m1.push_back(0);
-
- vector<double> m2;
- m2.push_back(1);
- m2.push_back(1);
- m2.push_back(1);
- m2.push_back(-1);
- m2.push_back(0);
- m2.push_back(1);
-
- phenotype.push_back(0);
- phenotype.push_back(1);
- phenotype.push_back(0);
- phenotype.push_back(1);
- phenotype.push_back(0);
- phenotype.push_back(1);
-
- inMat.push_back(ones);
- inMat.push_back(m1);
- inMat.push_back(m2);
-
- }
+ protected:
+
+ vector<vector<double> > inMat;
+ vector<double> phenotype;
+ vector<double> ones;
+ LogisticRegression lr;
+
+ virtual void SetUp(){
+ ones = vector<double>(6,1.0);
+ vector<double> m1;
+ m1.push_back(0);
+ m1.push_back(2);
+ m1.push_back(1);
+ m1.push_back(0);
+ m1.push_back(-1);
+ m1.push_back(0);
+
+ vector<double> m2;
+ m2.push_back(1);
+ m2.push_back(1);
+ m2.push_back(1);
+ m2.push_back(-1);
+ m2.push_back(0);
+ m2.push_back(1);
+
+ phenotype.push_back(0);
+ phenotype.push_back(1);
+ phenotype.push_back(0);
+ phenotype.push_back(1);
+ phenotype.push_back(0);
+ phenotype.push_back(1);
+
+ inMat.push_back(ones);
+ inMat.push_back(m1);
+ inMat.push_back(m2);
+
+ }
};
class LR_Separable_Test : public ::testing::Test{
- protected:
+ protected:
- vector<vector<double> > cov;
+ vector<vector<double> > cov;
vector<double> response;
- void SetUp(){
-
- for (int i=0;i < 4; i++)
- response.push_back(1.0);
- for (int i=0;i < 4; i++)
- response.push_back(0.0);
-
- for (int i=0; i < 2; i++)
- cov.push_back( vector<double>() );
- for (int i=0; i < 4; i++){
- cov[0].push_back(1.0);
- }
- for (int i=0; i < 4; i++){
- cov[0].push_back(2.0);
- }
-
- for (int i=0; i < 8; i++){
- cov[1].push_back(i);
+ void SetUp(){
+ for (int i=0;i < 4; i++)
+ response.push_back(1.0);
+ for (int i=0;i < 4; i++)
+ response.push_back(0.0);
+
+ for (int i=0; i < 2; i++)
+ cov.push_back( vector<double>() );
+ for (int i=0; i < 4; i++){
+ cov[0].push_back(1.0);
+ }
+ for (int i=0; i < 4; i++){
+ cov[0].push_back(2.0);
+ }
+
+ for (int i=0; i < 8; i++){
+ cov[1].push_back(i);
+ }
}
- }
-};
+};
-//--------------------------------------------------------------------------
+//--------------------------------------------------------------------------
TEST_F(LR_Engine_Test, test_newton_raphson) {
-
- vector<vector<double> > invInfMatrix = vecops::getDblVec(inMat.size(), inMat.size());
- vector<double> betas = lr.newtonRaphson(inMat, phenotype, invInfMatrix);
- double relErr = (0.36750847348763349-betas[0])/0.36750847348763349;
- ASSERT_NEAR(relErr,0.0,NEAR_THRESH);
- relErr = (1.4467808518431764-betas[1])/1.4467808518431764;
- ASSERT_NEAR(relErr,0.0,NEAR_THRESH);
- relErr = (-1.5618476151485159-betas[2])/-1.5618476151485159;
- ASSERT_NEAR(relErr,0.0,NEAR_THRESH);
+
+ vector<vector<double> > invInfMatrix = vecops::getDblVec(inMat.size(), inMat.size());
+ vector<double> betas = lr.newtonRaphson(inMat, phenotype, invInfMatrix);
+ double relErr = (0.36750847348763349-betas[0])/0.36750847348763349;
+ ASSERT_NEAR(relErr,0.0,NEAR_THRESH);
+ relErr = (1.4467808518431764-betas[1])/1.4467808518431764;
+ ASSERT_NEAR(relErr,0.0,NEAR_THRESH);
+ relErr = (-1.5618476151485159-betas[2])/-1.5618476151485159;
+ ASSERT_NEAR(relErr,0.0,NEAR_THRESH);
}
TEST_F(LR_Separable_Test, test_separable) {
-
- LogisticRegression lr;
+
+ LogisticRegression lr;
int separableColumn = lr.dataIsSeparable(cov, response);
- ASSERT_EQ( separableColumn, 0);
+ ASSERT_EQ( separableColumn, 0);
}
@@ -0,0 +1,19 @@
+#include <gtest/gtest.h>
+#include "../engine/linalg/specialfunctions.h"
+
+#define NEAR_THRESH 1e-7
+
+TEST(FStatToPVal, SanityCheck) {
+
+ // Test against
+ double pval = alglib::fdistribution(3000, 1, 5.0);
+ ASSERT_NEAR(pval,0.65475315127310253,NEAR_THRESH);
+
+ pval = alglib::fdistribution(1,1,5.0);
+ ASSERT_NEAR(pval,0.73227952719876888,NEAR_THRESH);
+
+ pval = alglib::fdistribution(1, 3000, 5.0);
+ ASSERT_NEAR(pval,0.97457942728192826,NEAR_THRESH);
+
+}
+
@@ -1,2 +1,2 @@
-add_library( linalg alglibinternal.cpp alglibmisc.cpp ap.cpp blas.cpp ialglib.cpp linalg.cpp)
+add_library( linalg alglibinternal.cpp alglibmisc.cpp ap.cpp blas.cpp ialglib.cpp linalg.cpp specialfunctions.cpp statistics.cpp)
@@ -16,7 +16,7 @@ A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>>
*************************************************************************/
-
+#include "stdafx.h"
#include "alglibinternal.h"
// disable some irrelevant warnings
@@ -16,7 +16,7 @@ A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>>
*************************************************************************/
-
+#include "stdafx.h"
#include "alglibmisc.h"
// disable some irrelevant warnings
@@ -16,7 +16,7 @@ A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>>
*************************************************************************/
-
+#include "stdafx.h"
#include "ap.h"
#include <limits>
#include <locale.h>
@@ -16,7 +16,7 @@ A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>>
*************************************************************************/
-
+#include "stdafx.h"
#include "linalg.h"
// disable some irrelevant warnings
@@ -24563,17 +24563,15 @@ static void rcond_cmatrixestimatenorm(ae_int_t n,
{
ae_int_t itmax;
ae_int_t i;
- // RTG updated these values with a starting value. This removes some compiler
- // warnings under g++.
- ae_int_t iter = 0;
- ae_int_t j = 0;
- ae_int_t jlast = 0;
+ ae_int_t iter;
+ ae_int_t j;
+ ae_int_t jlast;
ae_int_t jump;
- double absxi = 0.0;
- double altsgn = 0.0;
- double estold = 0.0;
- double safmin = 0.0;
- double temp = 0.0;
+ double absxi;
+ double altsgn;
+ double estold;
+ double safmin;
+ double temp;
Oops, something went wrong.

0 comments on commit 50a40b0

Please sign in to comment.