diff --git a/NEWS.md b/NEWS.md index c57f0d4..49c0385 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# fireSense_SpreadPredict (development version) + +- A fit made with fireSense_SpreadFit's `link = "logistic3pUpper"` stores `upperTail1`; prediction uses the upper-tail link for it, chosen by the parameter's name (`fireSenseUtils::logisticAll()`). Needs fireSenseUtils >= 0.2.3.9038. + # fireSense_SpreadPredict 1.0.0 First release from `development` since `master` was last updated (2021-01-27). Full history: https://github.com/PredictiveEcology/fireSense_SpreadPredict/compare/a5b41f9...v1.0.0 diff --git a/fireSense_SpreadPredict.R b/fireSense_SpreadPredict.R index ef9e09f..8caf602 100644 --- a/fireSense_SpreadPredict.R +++ b/fireSense_SpreadPredict.R @@ -10,14 +10,14 @@ defineModule(sim, list( person("Alex M.", "Chubaty", email = "achubaty@for-cast.ca", role = "ctb") ), childModules = character(), - version = list(fireSense_SpreadPredict = "1.0.0.9001", SpaDES.core = "0.1.0"), + version = list(fireSense_SpreadPredict = "1.0.0.9002", SpaDES.core = "0.1.0"), timeframe = as.POSIXlt(c(NA, NA)), timeunit = "year", citation = list("citation.bib"), documentation = list("README.txt", "fireSense_SpreadPredict.Rmd"), reqdPkgs = list("magrittr", "Matrix", "methods", "terra", "SpaDES.core (>=3.0.4)", "stats", "ggplot2", "viridis", - "PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9029)"), + "PredictiveEcology/fireSenseUtils@development (>= 0.2.3.9038)"), parameters = bindrows( defineParameter(name = "lowerSpreadProb", class = "numeric", default = 0.13, desc = "Lower asymptote of the 2- and 3-parameter logistic."), diff --git a/tests/testthat/test-spreadProb-values.R b/tests/testthat/test-spreadProb-values.R index 5e84705..573de75 100644 --- a/tests/testthat/test-spreadProb-values.R +++ b/tests/testthat/test-spreadProb-values.R @@ -195,3 +195,23 @@ test_that("a fit made on the log scale is predicted on the log scale, as before" ## (x = 1.25 -> 0.2409) but (8.517 - 3.605) / 6.395 = 0.768 on the log scale (x = 1.518 -> 0.2445) expect_gt(abs(v[3] - handLogistic3(1.25)), 0.003) }) + +test_that("a fit with upperTail1 is predicted with the upper-tail link, from the parameter's name", { + ## fireSense_SpreadFit's link "logistic3pUpper" stores one more logistic parameter, upperTail1 + ## (fireSenseUtils::logistic3pUpper(), Stukel 1988). It changes the curve only where + ## hillSlope1 * x > 0: there u = hillSlope1 * x becomes -log(1 - a * u) / a for a < 0. + v <- predVals(toyRun(toyInputs(params = toyParams(upperTail1 = -0.5)))) + handUpper <- function(x, a = -0.5) { + u <- 2 * x + u[u > 0] <- -log(1 - a * u[u > 0]) / a + 0.13 + 0.12 / (1 + exp(-u)) + } + ## cell 4: x = 2.5, u = 5 -> 2 * log(3.5) = 2.505526 -> 0.13 + 0.12 * 0.9245283 = 0.2409434 + expect_equal(v[4], 0.2409434, tolerance = 1e-6) + expect_equal(v[c(1, 3, 4, 6, 7, 8)], handUpper(c(0, 1.25, 2.5, 1, 1.125, 1.25)), tolerance = 1e-7) + ## below the inflection nothing changes: cell 2 (x = -0.125) is the logistic3p value + expect_equal(v[2], 0.1825388, tolerance = 1e-6) + ## and upperTail1 = 0 is logistic3p everywhere + v0 <- predVals(toyRun(toyInputs(params = toyParams(upperTail1 = 0)))) + expect_equal(v0, predVals(toyRun()), tolerance = 1e-12) +})