Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: dMod2
Type: Package
Title: Parameter Estimation in Dynamical Models
Version: 0.17.0
Date: 2026-11-16
Version: 0.17.1
Date: 2026-11-25
Authors@R: c(
person("Simon", "Beyer", email = "simon.beyer@fdm.uni-freiburg.de",
role = c("aut", "cre")),
Expand All @@ -27,7 +27,7 @@ Imports:
cOde,
methods,
tools,
cppDE (>= 0.13.12),
cppDE (>= 0.13.16),
ggplot2 (>= 3.5.0),
parallel,
parallelly,
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# dMod2 0.17.1

* Requires cppDE >= 0.13.16, whose derivatives of `exp10()` are finite at a spike of `-Inf`.
* `em()` with spike-and-slab random effects stops when the inner search of a subset fails, instead
of leaving the subset out of the sum over subsets.

# dMod2 0.17.0

* Requires symident >= 0.18.1. The global analysis of symident stops on work limits instead of time
Expand Down
7 changes: 5 additions & 2 deletions R/nlmeSpikeSubsets.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@
if (!is.null(out$hessian)) H <- H + as.matrix(out$hessian)[names(p), names(p)]
objlist(value = out$value + prior$value, gradient = gr, hessian = H)
}
# a failed inner search stops the fit: every subset stays in the sum over subsets
fit <- tryCatch(.innerTrust(list(objfun = objfun, parinit = start[on], fixed = fx, rinit = 1, rmax = 10,
iterlim = 100L)),
error = function(e) NULL)
if (is.null(fit) || !is.finite(fit$value)) return(NULL)
error = function(e) stop("em: the inner search of group ", g, " with the slab etas ",
paste(on, collapse = ", "), " and the others at the spike failed: ",
conditionMessage(e), call. = FALSE))
if (!is.finite(fit$value)) return(NULL)
at <- objfun(fit$argument, fixed = fx)
H <- (at$hessian + t(at$hessian)) / 2
ch <- tryCatch(chol(H / 2), error = function(e) NULL)
Expand Down
19 changes: 16 additions & 3 deletions tests/testthat/test-spikeSlabSubsets.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ dir.create(.spkDir, showWarnings = FALSE)
pMixOff <- P(mixOff, modelname = "spk_pmixoff", derivMode = ff, compile = FALSE)
pNorm <- P(norm, modelname = "spk_pnorm", derivMode = ff, compile = FALSE)
pLin <- P(linear, modelname = "spk_plin", compile = FALSE)
ten <- insert(branch(define(NULL, "p <- p", p = c("x", "k0", "k1")), table = data.frame(row.names = "C1", one = 1)),
"k <- exp10(k)", k = c("k0", "k1"))
ten <- insert(ten, k ~ 0 + (1 | gr(dist = spikeSlab(prob = 0.5, mean = log10(0.5), tau = 1 / log(10), spike = -Inf))),
k = c("k0", "k1"))
pTen <- P(ten, modelname = "spk_pten", compile = FALSE)
# two independent species with four candidate rates in one group
ks <- c("a0", "a1", "b0", "b1")
x2 <- Xs(odemodel(eqnvec(x = "a0 - a1*x", y = "b0 - b1*y"), modelname = "spk_x2", compile = FALSE))
Expand All @@ -58,11 +63,11 @@ dir.create(.spkDir, showWarnings = FALSE)
"k <- exp(k)", k = ks)
ec <- insert(ec, k ~ 0 + (1 | gr(dist = slab(prob = 0.5, mean = log(0.5)))), k = ks)
pEC <- P(ec, modelname = "spk_pec", compile = FALSE)
compile(g, x, err, xFF, gFF, pSel, pProb, pGrp, pDef, pDefFF, pMix, pMixOff, pNorm, pLin, g2, x2, pEC,
compile(g, x, err, xFF, gFF, pSel, pProb, pGrp, pDef, pDefFF, pMix, pMixOff, pNorm, pLin, pTen, g2, x2, pEC,
output = "spk_all", cores = test_cores())
list(one = one, two = two, counts = counts, shift = shift, mixed = mixed, pure = pure, x = x, g = g, err = err,
xFF = xFF, gFF = gFF, pSel = pSel, pProb = pProb, pGrp = pGrp, pDef = pDef, pDefFF = pDefFF, pMix = pMix,
pMixOff = pMixOff, pNorm = pNorm, pLin = pLin, x2 = x2, g2 = g2, pEC = pEC, dir = .spkDir)
pMixOff = pMixOff, pNorm = pNorm, pLin = pLin, pTen = pTen, x2 = x2, g2 = g2, pEC = pEC, dir = .spkDir)
})

.spkFit <- function(data, p, ..., errmodel = NULL, method = "focei") {
Expand All @@ -86,7 +91,7 @@ dir.create(.spkDir, showWarnings = FALSE)
}))

test_that("a production term the data do not need is switched off, the decay rate stays", {
r <- .spkFit(.spk$one, .spk$pSel, init = c(x = 1))
r <- .spkShared("one_sel", .spkFit(.spk$one, .spk$pSel, init = c(x = 1)))
fit <- r$fit
expect_true(fit$converged)
p0 <- setNames(fit$random$p0, fit$random$eta)
Expand Down Expand Up @@ -114,6 +119,14 @@ test_that("a production term the data do not need is switched off, the decay rat
expect_equal(p0[["k0"]], 1 / (1 + exp(-(z2 - z1) / 2)), tolerance = 1e-4)
})

test_that("exp10() with the slab scaled by 1 / log(10) gives the fit of exp()", {
ten <- .spkFit(.spk$one, .spk$pTen, init = c(x = 1))$fit
e <- .spkShared("one_sel", .spkFit(.spk$one, .spk$pSel, init = c(x = 1)))$fit
expect_equal(ten$random$p0, e$random$p0, tolerance = 1e-4)
expect_equal(ten$value, e$value, tolerance = 1e-6)
expect_equal(10^ten$random$mode, exp(e$random$mode), tolerance = 1e-4)
})

test_that("with counts and an error model of the prediction the production term is switched off as well", {
fit <- .spkCounts("focei")$fit
expect_true(fit$converged)
Expand Down
Loading