From 5077604eb4f04e8ab7129a52f1667323134c93e6 Mon Sep 17 00:00:00 2001
From: Clare <chorscroft@users.noreply.github.com>
Date: Thu, 12 Mar 2020 11:44:49 +0000
Subject: [PATCH] Add a test for when there is a missing value in the data

---
 tests/testthat/test-Zalpha.R                  | 21 +++++++++++++++++++
 tests/testthat/test-Zalpha_BetaCDF.R          | 18 ++++++++++++++++
 tests/testthat/test-Zalpha_Zscore.R           | 18 ++++++++++++++++
 tests/testthat/test-Zalpha_all.R              | 15 +++++++++++++
 .../test-Zalpha_log_rsq_over_expected.R       | 18 ++++++++++++++++
 .../testthat/test-Zalpha_rsq_over_expected.R  | 18 ++++++++++++++++
 tests/testthat/test-Zbeta.R                   | 20 ++++++++++++++++++
 tests/testthat/test-Zbeta_BetaCDF.R           | 18 ++++++++++++++++
 tests/testthat/test-Zbeta_Zscore.R            | 18 ++++++++++++++++
 .../test-Zbeta_log_rsq_over_expected.R        | 18 ++++++++++++++++
 tests/testthat/test-Zbeta_rsq_over_expected.R | 18 ++++++++++++++++
 11 files changed, 200 insertions(+)

diff --git a/tests/testthat/test-Zalpha.R b/tests/testthat/test-Zalpha.R
index 64936c9..e9f72c6 100644
--- a/tests/testthat/test-Zalpha.R
+++ b/tests/testthat/test-Zalpha.R
@@ -216,3 +216,24 @@ test_that("Zalpha warns about all NAs", {
   expect_warning(Zalpha(pos = df$POS, ws  = 3000, x = as.matrix(df[,3:7]), minRandL = 4, minRL = 50, X = NULL),
                "No Zalpha values were calculated, try reducing minRandL and minRL or increasing the window size")
 })
+
+## test that zalpha works with a missing value
+
+df1<-df
+df1$C1[15]<-NA
+test_that("Zalpha calculates Zalpha statistic correctly with missing value", {
+
+  expect_equal(Zalpha(pos = df1$POS, ws  = 3000, x = as.matrix(df1[,3:7]), minRandL = 4, minRL = 25, X = NULL),
+               list(
+                 position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
+                 Zalpha=c(NA,NA,NA,NA,
+                          0.434953703703704,
+                          0.473283179012346,
+                          0.397114748677249,
+                          0.317791005291005,
+                          0.300801917989418,
+                          0.322897376543210,
+                          0.360532407407407,
+                          NA,NA,NA,NA)
+               ))
+})
diff --git a/tests/testthat/test-Zalpha_BetaCDF.R b/tests/testthat/test-Zalpha_BetaCDF.R
index 2377ccf..a97c42e 100644
--- a/tests/testthat/test-Zalpha_BetaCDF.R
+++ b/tests/testthat/test-Zalpha_BetaCDF.R
@@ -313,4 +313,22 @@ test_that("Zalpha_BetaCDF fails when LDprofile_bins and LDprofile_Beta_b are dif
                "LDprofile_Beta_b must contain the same number of values as there are bins given in LDprofile_bins")
 })
 
+## test that Zalpha_BetaCDF works with missing value
+df1<-df
+df1$C1[15]<-NA
+test_that("Zalpha_BetaCDF calculates Zalpha_BetaCDF statistic correctly with missing value", {
 
+  expect_equal(Zalpha_BetaCDF(pos = df1$POS, ws  = 3000, x = as.matrix(df1[,3:7]), dist = df1$dist, LDprofile_bins = LDprofile$bin, LDprofile_Beta_a = LDprofile$Beta_a, LDprofile_Beta_b = LDprofile$Beta_b, minRandL = 4, minRL = 25, X = NULL),
+               list(
+                 position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
+                 Zalpha_BetaCDF=c(NA,NA,NA,NA,
+                                  0.514624827235342,
+                                  0.545771193444576,
+                                  0.479196303216273,
+                                  0.426601106081793,
+                                  0.414611369025125,
+                                  0.431252209159130,
+                                  0.453835332399716,
+                                  NA,NA,NA,NA)
+               ))
+})
diff --git a/tests/testthat/test-Zalpha_Zscore.R b/tests/testthat/test-Zalpha_Zscore.R
index 53087b3..22cddb0 100644
--- a/tests/testthat/test-Zalpha_Zscore.R
+++ b/tests/testthat/test-Zalpha_Zscore.R
@@ -332,4 +332,22 @@ test_that("Zalpha_Zscore fails when LDprofile_bins and LDprofile_sd are differen
                "LDprofile_sd must contain the same number of values as there are bins given in LDprofile_bins")
 })
 
+## test that Zalpha_Zscore works with a missing value
+df1<-df
+df1$C1[15]<-NA
+test_that("Zalpha_Zscore calculates Zalpha_Zscore statistic correctly with missing value", {
 
+  expect_equal(Zalpha_Zscore(pos = df1$POS, ws  = 3000, x = as.matrix(df1[,3:7]), dist = df1$dist, LDprofile_bins = LDprofile$bin, LDprofile_rsq = LDprofile$rsq, LDprofile_sd = LDprofile$sd, minRandL = 4, minRL = 25, X = NULL),
+               list(
+                 position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
+                 Zalpha_Zscore=c(NA,NA,NA,NA,
+                                 0.1293462762460600,
+                                 0.2214307128814780,
+                                 0.0107400139438311,
+                                 -0.1948882077777450,
+                                 -0.2427674321057070,
+                                 -0.1850465883763240,
+                                 -0.0912782685815102,
+                                 NA,NA,NA,NA)
+               ))
+})
diff --git a/tests/testthat/test-Zalpha_all.R b/tests/testthat/test-Zalpha_all.R
index 66dea98..90f6ab3 100644
--- a/tests/testthat/test-Zalpha_all.R
+++ b/tests/testthat/test-Zalpha_all.R
@@ -553,3 +553,18 @@ test_that("Zalpha_all calculates statistics correctly with LDprofile_bins not su
                  Zbeta=c(NA,NA,NA,NA,(10+5/18)/40,(10+35/36)/45,(11+103/144)/48,(12+73/144)/49,(11+83/144)/48,(11+17/48)/45,(10+65/144)/40,NA,NA,NA,NA)
                ))
 })
+
+## test that Zalpha_all works with a missing value
+df1<-df
+df1$C1[15]<-NA
+test_that("Zalpha_all calculates statistics correctly with missing value", {
+
+  expect_equal(Zalpha_all(pos = df1$POS, ws  = 3000, x = as.matrix(df1[,3:7])),
+               list(
+                 position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
+                 LR=c(NA,NA,NA,NA,40,45,48,49,48,45,40,NA,NA,NA,NA),
+                 L_plus_R=c(NA,NA,NA,NA,51,46,43,42,43,46,51,NA,NA,NA,NA),
+                 Zalpha=c(NA,NA,NA,NA,0.434953703703704,0.473283179012346,0.397114748677249,0.317791005291005,0.300801917989418,0.322897376543210,0.360532407407407,NA,NA,NA,NA),
+                 Zbeta=c(NA,NA,NA,NA,0.248611111111111,0.235185185185185,0.233651620370370,0.257794784580499,0.250144675925926,0.259413580246914,0.271354166666667,NA,NA,NA,NA)
+               ))
+})
diff --git a/tests/testthat/test-Zalpha_log_rsq_over_expected.R b/tests/testthat/test-Zalpha_log_rsq_over_expected.R
index a612ce5..5f6cb0d 100644
--- a/tests/testthat/test-Zalpha_log_rsq_over_expected.R
+++ b/tests/testthat/test-Zalpha_log_rsq_over_expected.R
@@ -306,4 +306,22 @@ test_that("Zalpha_log_rsq_over_expected fails when LDprofile_bins and LDprofile_
                "LDprofile_rsq must contain the same number of values as there are bins given in LDprofile_bins")
 })
 
+## test that Zalpha_log_rsq_over_expected works with missing value
+df1<-df
+df1$C1[15]<-NA
+test_that("Zalpha_log_rsq_over_expected calculates Zalpha_log_rsq_over_expected statistic correctly with missing value", {
 
+  expect_equal(Zalpha_log_rsq_over_expected(pos = df1$POS, ws  = 3000, x = as.matrix(df1[,3:7]), dist = df1$dist, LDprofile_bins = LDprofile$bin, LDprofile_rsq = LDprofile$rsq, minRandL = 4, minRL = 25, X = NULL),
+               list(
+                 position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
+                 Zalpha_log_rsq_over_expected=c(NA,NA,NA,NA,
+                                                -0.0962381774322340,
+                                                -0.0431319886441381,
+                                                -0.1586794755944650,
+                                                -0.2787494259051810,
+                                                -0.2969961346576940,
+                                                -0.2876978917129680,
+                                                -0.2297613495634870,
+                                                NA,NA,NA,NA)
+               ))
+})
diff --git a/tests/testthat/test-Zalpha_rsq_over_expected.R b/tests/testthat/test-Zalpha_rsq_over_expected.R
index b2e6d6a..162cc28 100644
--- a/tests/testthat/test-Zalpha_rsq_over_expected.R
+++ b/tests/testthat/test-Zalpha_rsq_over_expected.R
@@ -306,4 +306,22 @@ test_that("Zalpha_rsq_over_expected fails when LDprofile_bins and LDprofile_rsq
                "LDprofile_rsq must contain the same number of values as there are bins given in LDprofile_bins")
 })
 
+## test that Zalpha_rsq_over_expected works with a missing value
+df1<-df
+df1$C1[15]<-NA
+test_that("Zalpha_rsq_over_expected calculates Zalpha_rsq_over_expected statistic correctly with missing value", {
 
+  expect_equal(Zalpha_rsq_over_expected(pos = df1$POS, ws  = 3000, x = as.matrix(df1[,3:7]), dist = df1$dist, LDprofile_bins = LDprofile$bin, LDprofile_rsq = LDprofile$rsq, minRandL = 4, minRL = 25, X = NULL),
+               list(
+                 position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
+                 Zalpha_rsq_over_expected=c(NA,NA,NA,NA,
+                                            1.144893254873100,
+                                            1.236446352382830,
+                                            1.020556368226920,
+                                            0.810519367025429,
+                                            0.761404523358315,
+                                            0.823237169574888,
+                                            0.907695973532459,
+                                            NA,NA,NA,NA)
+               ))
+})
diff --git a/tests/testthat/test-Zbeta.R b/tests/testthat/test-Zbeta.R
index 657308f..e71bcaf 100644
--- a/tests/testthat/test-Zbeta.R
+++ b/tests/testthat/test-Zbeta.R
@@ -216,3 +216,23 @@ test_that("Zbeta warns about all NAs", {
   expect_warning(Zbeta(pos = df$POS, ws  = 3000, x = as.matrix(df[,3:7]), minRandL = 4, minRL = 50, X = NULL),
                  "No Zbeta values were calculated, try reducing minRandL and minRL or increasing the window size")
 })
+
+## test that Zbeta works with a missing value
+df1<-df
+df1$C1[15]<-NA
+test_that("Zbeta calculates Zbeta statistic correctly with missing value", {
+
+  expect_equal(Zbeta(pos = df1$POS, ws  = 3000, x = as.matrix(df1[,3:7]), minRandL = 4, minRL = 25, X = NULL),
+               list(
+                 position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
+                 Zbeta=c(NA,NA,NA,NA,
+                         0.248611111111111,
+                         0.235185185185185,
+                         0.233651620370370,
+                         0.257794784580499,
+                         0.250144675925926,
+                         0.259413580246914,
+                         0.271354166666667,
+                         NA,NA,NA,NA)
+               ))
+})
diff --git a/tests/testthat/test-Zbeta_BetaCDF.R b/tests/testthat/test-Zbeta_BetaCDF.R
index acf23eb..56de2d3 100644
--- a/tests/testthat/test-Zbeta_BetaCDF.R
+++ b/tests/testthat/test-Zbeta_BetaCDF.R
@@ -313,4 +313,22 @@ test_that("Zbeta_BetaCDF fails when LDprofile_bins and LDprofile_Beta_b are diff
                "LDprofile_Beta_b must contain the same number of values as there are bins given in LDprofile_bins")
 })
 
+## test that Zbeta_BetaCDF works with a missing value
+df1<-df
+df1$C1[15]<-NA
+test_that("Zbeta_BetaCDF calculates Zbeta_BetaCDF statistic correctly with missing value", {
 
+  expect_equal(Zbeta_BetaCDF(pos = df1$POS, ws  = 3000, x = as.matrix(df1[,3:7]), dist = df1$dist, LDprofile_bins = LDprofile$bin, LDprofile_Beta_a = LDprofile$Beta_a, LDprofile_Beta_b = LDprofile$Beta_b, minRandL = 4, minRL = 25, X = NULL),
+               list(
+                 position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
+                 Zbeta_BetaCDF=c(NA,NA,NA,NA,
+                                 0.412985057460831,
+                                 0.400927939537124,
+                                 0.395021661102834,
+                                 0.415693421938135,
+                                 0.407239348282580,
+                                 0.414765530721706,
+                                 0.422608554537899,
+                                 NA,NA,NA,NA)
+               ))
+})
diff --git a/tests/testthat/test-Zbeta_Zscore.R b/tests/testthat/test-Zbeta_Zscore.R
index ab3c6a2..9b79635 100644
--- a/tests/testthat/test-Zbeta_Zscore.R
+++ b/tests/testthat/test-Zbeta_Zscore.R
@@ -332,4 +332,22 @@ test_that("Zbeta_Zscore fails when LDprofile_bins and LDprofile_sd are different
                "LDprofile_sd must contain the same number of values as there are bins given in LDprofile_bins")
 })
 
+## test that Zbeta_Zscore works with a missing value
+df1<-df
+df1$C1[15]<-NA
+test_that("Zbeta_Zscore calculates Zbeta_Zscore statistic correctly with missing value", {
 
+  expect_equal(Zbeta_Zscore(pos = df1$POS, ws  = 3000, x = as.matrix(df1[,3:7]), dist = df1$dist, LDprofile_bins = LDprofile$bin, LDprofile_rsq = LDprofile$rsq, LDprofile_sd = LDprofile$sd, minRandL = 4, minRL = 25, X = NULL),
+               list(
+                 position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
+                 Zbeta_Zscore=c(NA,NA,NA,NA,
+                                -0.273427430734028,
+                                -0.322886149060994,
+                                -0.332297266849268,
+                                -0.272829789964421,
+                                -0.301705254123099,
+                                -0.280921980725937,
+                                -0.253883231792888,
+                                NA,NA,NA,NA)
+               ))
+})
diff --git a/tests/testthat/test-Zbeta_log_rsq_over_expected.R b/tests/testthat/test-Zbeta_log_rsq_over_expected.R
index 39ffbc4..98f67fd 100644
--- a/tests/testthat/test-Zbeta_log_rsq_over_expected.R
+++ b/tests/testthat/test-Zbeta_log_rsq_over_expected.R
@@ -306,4 +306,22 @@ test_that("Zbeta_log_rsq_over_expected fails when LDprofile_bins and LDprofile_r
                "LDprofile_rsq must contain the same number of values as there are bins given in LDprofile_bins")
 })
 
+## test that Zbeta_log_rsq_over_expected works with a missing value
+df1<-df
+df1$C1[15]<-NA
+test_that("Zbeta_log_rsq_over_expected calculates Zbeta_log_rsq_over_expected statistic correctly with missing value", {
 
+  expect_equal(Zbeta_log_rsq_over_expected(pos = df1$POS, ws  = 3000, x = as.matrix(df1[,3:7]), dist = df1$dist, LDprofile_bins = LDprofile$bin, LDprofile_rsq = LDprofile$rsq, minRandL = 4, minRL = 25, X = NULL),
+               list(
+                 position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
+                 Zbeta_log_rsq_over_expected=c(NA,NA,NA,NA,
+                                               -0.325807550270004,
+                                               -0.340625852732766,
+                                               -0.368453560916506,
+                                               -0.349354414321111,
+                                               -0.343256477178026,
+                                               -0.302866694293198,
+                                               -0.277938534964028,
+                                               NA,NA,NA,NA)
+               ))
+})
diff --git a/tests/testthat/test-Zbeta_rsq_over_expected.R b/tests/testthat/test-Zbeta_rsq_over_expected.R
index 4499845..d2c6ec0 100644
--- a/tests/testthat/test-Zbeta_rsq_over_expected.R
+++ b/tests/testthat/test-Zbeta_rsq_over_expected.R
@@ -306,4 +306,22 @@ test_that("Zbeta_rsq_over_expected fails when LDprofile_bins and LDprofile_rsq a
                "LDprofile_rsq must contain the same number of values as there are bins given in LDprofile_bins")
 })
 
+## test that Zbeta_rsq_over_expected works with a missing value
+df1<-df
+df1$C1[15]<-NA
+test_that("Zbeta_rsq_over_expected calculates Zbeta_rsq_over_expected statistic correctly with missing value", {
 
+  expect_equal(Zbeta_rsq_over_expected(pos = df1$POS, ws  = 3000, x = as.matrix(df1[,3:7]), dist = df1$dist, LDprofile_bins = LDprofile$bin, LDprofile_rsq = LDprofile$rsq, minRandL = 4, minRL = 25, X = NULL),
+               list(
+                 position=c(100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500),
+                 Zbeta_rsq_over_expected=c(NA,NA,NA,NA,
+                                           0.715016946655391,
+                                           0.667572495841203,
+                                           0.660129682796687,
+                                           0.721295428368775,
+                                           0.685694082181357,
+                                           0.708332106873554,
+                                           0.735944021838047,
+                                           NA,NA,NA,NA)
+               ))
+})
-- 
GitLab