From e5bc18a8a294388d8496c624b53a3c11ec971515 Mon Sep 17 00:00:00 2001 From: aho Date: Wed, 3 Jun 2020 15:52:51 +0200 Subject: [PATCH 1/2] Bugfix for Regression na.action. It didn't work for na.fail before. --- R/Regression.R | 5 +---- tests/testthat/test-Regression.R | 11 +++-------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/R/Regression.R b/R/Regression.R index 1e0c79b..8b0cd0f 100644 --- a/R/Regression.R +++ b/R/Regression.R @@ -200,10 +200,7 @@ Regression <- function(datay, datax, time_dim = 'sdate', formula = y ~ x, check_na <- TRUE } - # remove NAs for potential poly() - x2 <- x[!is.na(NApos)] - y2 <- y[!is.na(NApos)] - lm.out <- lm(formula, data = data.frame(x = x2, y = y2), na.action = na.action) + lm.out <- lm(formula, data = data.frame(x = x, y = y), na.action = na.action) coeff <- lm.out$coefficients if (conf) { conf.lower <- confint(lm.out, level = conf.lev)[, 1] diff --git a/tests/testthat/test-Regression.R b/tests/testthat/test-Regression.R index 69c4f9e..3e7efab 100644 --- a/tests/testthat/test-Regression.R +++ b/tests/testthat/test-Regression.R @@ -24,7 +24,7 @@ context("s2dv::Regression tests") dim = c(date = 5, ftime = 2, lon = 2, lat = 4)) set.seed(2) datax3 <- array(c(1:80) + rnorm(80), - dim = c(date = 5, lon = 2, lat = 4,ftime = 2)) + dim = c(date = 5, lon = 2, lat = 4, ftime = 2)) ############################################## @@ -162,17 +162,12 @@ test_that("3. Output checks: dat2", { 2 ) expect_equal( - length(which(is.na(Regression(datay2, datax2, na.action = na.pass)$p.val))), + length(which(is.na(Regression(datay2, datax2, na.action = na.omit)$p.val))), 0 ) expect_equal( which(is.na(Regression(datay2, datax2, na.action = 1)$p.val)), - c(3,15) - ) - expect_equal( - which(is.na(Regression(datay2, datax2, na.action = 1, - formula = y~poly(x, 2, raw = T))$p.val)), - c(3,15) + c(3, 15) ) }) -- GitLab From 6990865ca3397832f53b6fef9aad6b928ffc81e6 Mon Sep 17 00:00:00 2001 From: aho Date: Wed, 3 Jun 2020 16:19:09 +0200 Subject: [PATCH 2/2] Update NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index c3bf8ee..643c43b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # s2dv 0.0.2 (Release date: 2020-) - Change the default of Season() parameter 'time_dim' from 'sdate' to 'ftime'. +- Bugfix for Regression() na.action. 'na.action = na.fail' was not functional before. # s2dv 0.0.1 (Release date: 2020-02-07) - The package is the advanced version of package 's2dverification', adopting the regime of package 'multiApply' for all the analytic functions. Most of the other functions for plotting and data retrieval in 's2dverification' are also preserved in this package. -- GitLab