Skip to content

Commit 50be5e1

Browse files
committed
AAK edits
1 parent 1b1c6c5 commit 50be5e1

File tree

6 files changed

+87
-41
lines changed

6 files changed

+87
-41
lines changed

R/lbdp.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
##' @param time final time
1616
##' @param t0 initial time
1717
##' @return \code{runLBDP} and \code{continueLBDP} return objects of class \sQuote{gpsim} with \sQuote{model} attribute \dQuote{LBDP}.
18+
##' @details
19+
##' Destructive sampling (nonzero \code{r}) is supported for simulation but not for \code{lbdp_pomp} or \code{lbdp_exact}.
1820
##' @references
1921
##' \King2024
2022
##'
@@ -28,7 +30,8 @@ NULL
2830
##' @export
2931
runLBDP <- function (
3032
time, t0 = 0,
31-
lambda = 2, mu = 1, psi = 1, r = 0,
33+
lambda = 2, mu = 1, psi = 1,
34+
r = 0,
3235
n0 = 5
3336
) {
3437
if (!is.numeric(r) || length(r) != 1L || !is.finite(r) || r < 0 || r > 1)
@@ -49,10 +52,10 @@ runLBDP <- function (
4952
continueLBDP <- function (
5053
object, time, lambda = NA, mu = NA, psi = NA, r = NA
5154
) {
52-
if (!isTRUE(is.na(r))) {
53-
if (!is.numeric(r) || length(r) != 1L || !is.finite(r) || r < 0 || r > 1)
54-
pStop(sQuote("r")," must be between 0 and 1.")
55-
}
55+
if (!is.na(r) &&
56+
(!is.numeric(r) || length(r) != 1L || !is.finite(r) || r < 0 || r > 1)
57+
)
58+
pStop(sQuote("r")," must be between 0 and 1.")
5659
params <- c(lambda=lambda,mu=mu,psi=psi,r=r)
5760
x <- .Call(P_reviveLBDP,object,params)
5861
.Call(P_runLBDP,x,time) |>

man/lbdp.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lbdp.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ void lbdp_proc_t::update_params (double *p, int n) {
4444
PARAM_SET(mu);
4545
PARAM_SET(psi);
4646
PARAM_SET(r);
47-
if (!R_FINITE(params.r) || params.r < 0 || params.r > 1)
48-
err("r must be between 0 and 1.");
4947
if (m != n) err("wrong number of parameters!");
5048
}
5149

tests/lbdp4.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
options(digits=3)
2+
suppressPackageStartupMessages({
3+
library(phylopomp)
4+
})
5+
set.seed(1253219857)
6+
7+
runLBDP(time=1,lambda=0,mu=0,psi=10,r=1,n0=5) |>
8+
gendat() -> gi
9+
sample_idx <- gi$nodetype == 1L
10+
stopifnot(
11+
`no samples`=any(sample_idx),
12+
`bad saturation`=all(gi$saturation[sample_idx] == 0)
13+
)
14+
15+
runLBDP(time=1,lambda=0,mu=0,psi=100,r=0,n0=5) |>
16+
gendat() -> gi
17+
sample_idx <- gi$nodetype == 1L
18+
stopifnot(
19+
`no samples`=any(sample_idx),
20+
`bad saturation`=sum(gi$saturation[sample_idx] == 0)==5
21+
)
22+
23+
try(runLBDP(time=1,lambda=0,mu=0,psi=1,r=-0.1,n0=1))
24+
try(runLBDP(time=1,lambda=0,mu=0,psi=1,r=1.5,n0=1))
25+
try(runLBDP(time=1,lambda=0,mu=0,psi=1,r=Inf,n0=1))
26+
try(runLBDP(time=1,lambda=0,mu=0,psi=1,r=NA,n0=1))

tests/lbdp4.Rout.save

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
R version 4.5.2 (2025-10-31) -- "[Not] Part in a Rumble"
3+
Copyright (C) 2025 The R Foundation for Statistical Computing
4+
Platform: x86_64-pc-linux-gnu
5+
6+
R is free software and comes with ABSOLUTELY NO WARRANTY.
7+
You are welcome to redistribute it under certain conditions.
8+
Type 'license()' or 'licence()' for distribution details.
9+
10+
Natural language support but running in an English locale
11+
12+
R is a collaborative project with many contributors.
13+
Type 'contributors()' for more information and
14+
'citation()' on how to cite R or R packages in publications.
15+
16+
Type 'demo()' for some demos, 'help()' for on-line help, or
17+
'help.start()' for an HTML browser interface to help.
18+
Type 'q()' to quit R.
19+
20+
> options(digits=3)
21+
> suppressPackageStartupMessages({
22+
+ library(phylopomp)
23+
+ })
24+
> set.seed(1253219857)
25+
>
26+
> runLBDP(time=1,lambda=0,mu=0,psi=10,r=1,n0=5) |>
27+
+ gendat() -> gi
28+
> sample_idx <- gi$nodetype == 1L
29+
> stopifnot(
30+
+ `no samples`=any(sample_idx),
31+
+ `bad saturation`=all(gi$saturation[sample_idx] == 0)
32+
+ )
33+
>
34+
> runLBDP(time=1,lambda=0,mu=0,psi=100,r=0,n0=5) |>
35+
+ gendat() -> gi
36+
> sample_idx <- gi$nodetype == 1L
37+
> stopifnot(
38+
+ `no samples`=any(sample_idx),
39+
+ `bad saturation`=sum(gi$saturation[sample_idx] == 0)==5
40+
+ )
41+
>
42+
> try(runLBDP(time=1,lambda=0,mu=0,psi=1,r=-0.1,n0=1))
43+
Error : in 'runLBDP': 'r' must be between 0 and 1.
44+
> try(runLBDP(time=1,lambda=0,mu=0,psi=1,r=1.5,n0=1))
45+
Error : in 'runLBDP': 'r' must be between 0 and 1.
46+
> try(runLBDP(time=1,lambda=0,mu=0,psi=1,r=Inf,n0=1))
47+
Error : in 'runLBDP': 'r' must be between 0 and 1.
48+
> try(runLBDP(time=1,lambda=0,mu=0,psi=1,r=NA,n0=1))
49+
Error : in 'runLBDP': 'r' must be between 0 and 1.
50+
>

tests/lbdp_bddr.R

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)