Skip to content

Commit 1fdcf20

Browse files
committed
rework initial condition specification for some models;
change argument names for `curtail()`
1 parent fd623a5 commit 1fdcf20

39 files changed

Lines changed: 367 additions & 207 deletions

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: phylopomp
22
Type: Package
33
Title: Phylodynamic Inference for POMP Models
4-
Version: 0.17.0.0
5-
Date: 2026-03-30
4+
Version: 0.17.1.0
5+
Date: 2026-04-01
66
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="kingaa@umich.edu",comment=c(ORCID="0000-0001-6159-3207")),
77
person(given=c("Qianying"),family="Lin",role=c("aut"),comment=c(ORCID="0000-0001-8620-9910"))
88
)

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ importFrom(pomp,bake)
126126
importFrom(pomp,covariate_table)
127127
importFrom(pomp,freeze)
128128
importFrom(pomp,onestep)
129+
importFrom(pomp,parameter_trans)
129130
importFrom(pomp,pomp)
130131
importFrom(pomp,stew)
131132
importFrom(scales,alpha)

R/curtail.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
##' @name curtail
66
##' @include getinfo.R
77
##' @inheritParams getInfo
8-
##' @param troot new root time for curtailed genealogy
9-
##' @return A curtailed genealogy object.
8+
##' @param t0,time numeric scalars; determine the time interval for curtailed genealogy
9+
##' @return a genealogy object: the curtailed version of the input genealogy.
1010
##' @example examples/curtail.R
1111
##' @rdname curtail
1212
##' @export
13-
curtail <- function (object, time = NA, troot = NA) {
14-
.Call(P_curtail,geneal(object),time,troot)
13+
curtail <- function (object, time = NA, t0 = NA) {
14+
.Call(P_curtail,geneal(object),time,t0)
1515
}

R/lbdp_pomp.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
lbdp_pomp <- function (x, lambda, mu, psi, chi = 0, n0 = 1)
99
{
1010
x |> gendat() -> gi
11-
n0 <- round(n0)
12-
if (n0 < 0)
13-
pStop(sQuote("n0")," must be a nonnegative integer.")
11+
if (round(n0) < 0)
12+
pStop(sQuote("n0")," must be nonnegative.")
1413
pomp(
1514
data=NULL,
1615
t0=gi$nodetime[1L],

R/seir.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
##' @param gamma recovery rate
1111
##' @param psi per capita sampling rate
1212
##' @param omega rate of waning of immunity
13-
##' @param S0,E0,I0,R0 initial sizes of S, E, I, R compartments, respectively.
1413
##' @inheritParams sir
1514
##' @return \code{runSEIR} and \code{continueSEIR} return objects of class \sQuote{gpsim} with \sQuote{model} attribute \dQuote{SEIR}.
1615
##' @references
@@ -22,13 +21,18 @@ NULL
2221
##' @export
2322
runSEIR <- function (
2423
time, t0 = 0,
25-
Beta = 4, sigma = 1, gamma = 1, psi = 1, omega = 0, S0 = 100, E0 = 5, I0 = 5, R0 = 0
24+
Beta = 4, sigma = 1, gamma = 1, psi = 1, omega = 0,
25+
S0 = 0.9, E0 = 0.05, I0 = 0.05, R0 = 0, pop = 100
2626
) {
2727
params <- c(Beta=Beta,sigma=sigma,gamma=gamma,psi=psi,omega=omega)
28-
ivps <- c(S0=S0,E0=E0,I0=I0,R0=R0)
28+
ivps <- c(S0,E0,I0,R0)
29+
ivps <- structure(
30+
as.integer(round(pop*ivps/sum(ivps))),
31+
names=c("S0","E0","I0","R0")
32+
)
2933
if (any(ivps < 0))
3034
pStop(paste(sQuote(names(ivps)),collapse=","),
31-
" must be nonnegative integers.")
35+
" must be nonnegative.")
3236
x <- .Call(P_makeSEIR,params,ivps,t0)
3337
.Call(P_runSEIR,x,time) |>
3438
structure(model="SEIR",class=c("gpsim","gpgen"))

R/seir_pomp.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
##' @rdname seir
33
##' @include lbdp.R sir.R seir.R
44
##' @param x genealogy in \pkg{phylopomp} format.
5+
##' @param S0,E0,I0,R0 initial conditions;
6+
##' non-negative numbers that specify the relative occupancies of the compartments at the inital time.
7+
##' @param pop host population size
58
##' @return
69
##' \code{seirs_pomp} returns a \sQuote{pomp} object.
710
##' @details
@@ -11,22 +14,21 @@
1114
seirs_pomp <- function (
1215
x,
1316
Beta, sigma, gamma, psi, omega = 0,
14-
S0, E0, I0, R0
17+
S0, E0, I0, R0, pop
1518
)
1619
{
1720
x |> gendat() -> gi
18-
ic <- as.integer(c(S0,E0,I0,R0))
19-
names(ic) <- c("S0","E0","I0","R0")
20-
if (any(ic < 0))
21-
pStop(paste(sQuote(names(ic)),collapse=","),
22-
" must be nonnegative integers.")
21+
ivps <- structure(c(S0,E0,I0,R0),names=c("S0","E0","I0","R0"))
22+
if (any(ivps < 0))
23+
pStop(paste(sQuote(names(ivps)),collapse=","),
24+
" must be nonnegative.")
2325
pomp(
2426
data=NULL,
2527
t0=gi$nodetime[1L],
2628
times=gi$nodetime[-1L],
2729
params=c(
2830
Beta=Beta,sigma=sigma,gamma=gamma,psi=psi,omega=omega,
29-
ic,N=sum(ic)
31+
ivps,pop=pop
3032
),
3133
userdata=gi,
3234
nstatevars=8L + gi$nsample,
@@ -39,7 +41,7 @@ seirs_pomp <- function (
3941
),
4042
paramnames=c(
4143
"Beta","sigma","gamma","psi","omega",
42-
"S0","E0","I0","R0","N"
44+
"S0","E0","I0","R0","pop"
4345
),
4446
PACKAGE="phylopomp"
4547
)

R/sir.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
##' @param gamma recovery rate.
1111
##' @param psi sampling rate.
1212
##' @param omega immunity waning rate
13-
##' @param S0,I0,R0 initial sizes of susceptible, infected, and recovered populations, respectively.
1413
##' @param time final time
1514
##' @param t0 initial time
1615
##' @return \code{runSIR} and \code{continueSIR} return objects of class \sQuote{gpsim} with \sQuote{model} attribute \dQuote{SIR}.
@@ -26,13 +25,17 @@ NULL
2625
runSIR <- function (
2726
time, t0 = 0,
2827
Beta = 2, gamma = 1, psi = 1, omega = 0,
29-
S0 = 100, I0 = 2, R0 = 0
28+
S0 = 100, I0 = 2, R0 = 0, pop = 102
3029
) {
3130
params <- c(Beta=Beta,gamma=gamma,psi=psi,omega=omega)
32-
ivps <- c(S0=S0,I0=I0,R0=R0)
31+
ivps <- c(S0,I0,R0)
32+
ivps <- structure(
33+
as.integer(round(pop*ivps/sum(ivps))),
34+
names=c("S0","I0","R0")
35+
)
3336
if (any(ivps < 0))
3437
pStop(paste(sQuote(names(ivps)),collapse=","),
35-
" must be nonnegative integers.")
38+
" must be nonnegative.")
3639
x <- .Call(P_makeSIR,params,ivps,t0)
3740
.Call(P_runSIR,x,time) |>
3841
structure(model="SIR",class=c("gpsim","gpgen"))

R/sir_pomp.R

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,36 @@
22
##' @rdname sir
33
##' @include sir.R
44
##' @param x genealogy in \pkg{phylopomp} format (i.e., an object that inherits from \sQuote{gpgen}).
5+
##' @param S0,I0,R0 initial conditions;
6+
##' non-negative numbers that specify the relative occupancies of the compartments at the inital time.
7+
##' @param pop host population size
58
##' @details
69
##' \code{sir_pomp} constructs a \sQuote{pomp} object containing a given set of data and a SIR model.
710
##' @return
811
##' \code{sir_pomp} and \code{sirs_pomp} return \sQuote{pomp} objects.
912
##' @importFrom pomp pomp onestep
1013
##' @export
1114
sir_pomp <- function (
12-
x, Beta, gamma, psi, omega = 0, S0, I0, R0
15+
x, Beta, gamma, psi, omega = 0, S0, I0, R0, pop
1316
) {
1417
x |> gendat() -> gi
15-
ic <- as.integer(c(S0,I0,R0))
16-
names(ic) <- c("S0","I0","R0")
17-
if (any(ic < 0))
18-
pStop(paste(sQuote(names(ic)),collapse=","),
19-
" must be nonnegative integers.")
18+
ivps <- structure(c(S0,I0,R0),names=c("S0","I0","R0"))
19+
if (any(ivps < 0))
20+
pStop(paste(sQuote(names(ivps)),collapse=","),
21+
" must be nonnegative.")
2022
pomp(
2123
data=NULL,
2224
t0=gi$nodetime[1L],
2325
times=gi$nodetime[-1L],
24-
params=c(Beta=Beta,gamma=gamma,psi=psi,omega=omega,ic,N=sum(ic)),
26+
params=c(Beta=Beta,gamma=gamma,psi=psi,omega=omega,ivps,pop=pop),
2527
userdata=gi,
2628
rinit="sirs_rinit",
2729
rprocess=onestep("sirs_gill"),
2830
dmeasure="sirs_dmeas",
2931
statenames=c("S","I","R","ll","ell","node"),
3032
paramnames=c(
3133
"Beta","gamma","psi","omega",
32-
"S0","I0","R0","N"
34+
names(ivps),"pop"
3335
),
3436
PACKAGE="phylopomp"
3537
)

R/strains.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
##' @param Beta1,Beta2,Beta3 transmission rate for strains 1, 2, 3, respectively
1010
##' @param gamma recovery rate
1111
##' @param psi1,psi2,psi3 sampling rates
12-
##' @param S0 initial size of susceptible population
13-
##' @param I1_0,I2_0,I3_0 initial numbers of strain-specific infections
14-
##' @param R0 initial size of immune population
1512
##' @inheritParams sir
1613
##' @return \code{runStrains} and \code{continueStrains} return objects of class \sQuote{gpsim} with \sQuote{model} attribute \dQuote{Strains}.
1714
##'
@@ -24,18 +21,22 @@ runStrains <- function (
2421
Beta1 = 5, Beta2 = 5, Beta3 = 5,
2522
gamma = 1,
2623
psi1 = 1, psi2 = 0, psi3 = 0,
27-
S0 = 10000, I1_0 = 10, I2_0 = 10, I3_0 = 10, R0 = 0
24+
S0 = 1, I1_0 = 0.01, I2_0 = 0.01, I3_0 = 0.01, R0 = 0,
25+
pop=10000
2826
) {
2927
params <- c(
3028
Beta1=Beta1,Beta2=Beta2,Beta3=Beta3,
3129
gamma=gamma,
3230
psi1=psi1,psi2=psi2,psi3=psi3
3331
)
34-
ivps <- c(
35-
S0=S0,
36-
I1_0=I1_0,I2_0=I2_0,I3_0=I3_0,
37-
R0=R0
32+
ivps <- c(S0,I1_0,I2_0,I3_0,R0)
33+
ivps <- structure(
34+
as.integer(round(pop*ivps/sum(ivps))),
35+
names=c("S0","I1_0","I2_0","I3_0","R0")
3836
)
37+
if (any(ivps < 0))
38+
pStop(paste(sQuote(names(ivps)),collapse=","),
39+
" must be nonnegative.")
3940
x <- .Call(P_makeStrains,params,ivps,t0)
4041
.Call(P_runStrains,x,time) |>
4142
structure(model="Strains",class=c("gpsim","gpgen"))

R/strains_pomp.R

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@
22
##' @rdname strains
33
##' @include strains.R
44
##' @param x genealogy in \pkg{phylopomp} format (i.e., an object that inherits from \sQuote{gpgen}).
5+
##' @param S0,I1_0,I2_0,I3_0,R0 initial conditions; non-negative numbers that specify the relative occupancies of the compartments at the inital time.
6+
##' @param pop host population size
57
##' @details
68
##' \code{strains_pomp} constructs a \sQuote{pomp} object containing a given set of data and the Strains model.
79
##' @return
810
##' \code{strains_pomp} returns a \sQuote{pomp} object.
9-
##' @importFrom pomp pomp onestep
11+
##' @importFrom pomp pomp onestep parameter_trans
1012
##' @export
1113
strains_pomp <- function (
1214
x,
1315
Beta1, Beta2, Beta3, gamma,
14-
psi1, psi2, psi3,
16+
psi1, psi2, psi3, pop,
1517
S0, I1_0, I2_0, I3_0, R0
1618
) {
1719
x |> gendat(obscure=FALSE) -> gi
18-
ic <- as.integer(c(S0,I1_0,I2_0,I3_0,R0))
19-
names(ic) <- c("S0","I1_0","I2_0","I3_0","R0")
20-
if (any(ic < 0))
21-
pStop(paste(sQuote(names(ic)),collapse=","),
22-
" must be nonnegative integers.")
20+
ivps <- structure(
21+
c(S0,I1_0,I2_0,I3_0,R0),
22+
names=c("S0","I1_0","I2_0","I3_0","R0")
23+
)
24+
if (any(ivps < 0))
25+
pStop(paste(sQuote(names(ivps)),collapse=","),
26+
" must be nonnegative.")
2327
pomp(
2428
data=NULL,
2529
t0=gi$nodetime[1L],
@@ -28,20 +32,27 @@ strains_pomp <- function (
2832
Beta1=Beta1,Beta2=Beta2,Beta3=Beta3,
2933
gamma=gamma,
3034
psi1=psi1,psi2=psi2,psi3=psi3,
31-
ic,N=sum(ic)
35+
ivps,pop=pop
3236
),
3337
userdata=gi,
3438
rinit="strains_rinit",
3539
rprocess=onestep("strains_gill"),
3640
dmeasure="strains_dmeas",
41+
partrans=parameter_trans(
42+
log=c(
43+
"Beta1","Beta2","Beta3","gamma",
44+
"psi1","psi2","psi3"
45+
),
46+
barycentric=c(names(ivps))
47+
),
3748
statenames=c(
3849
"S","I1","I2","I3","R",
3950
"ll","ell1","ell2","ell3","node"
4051
),
4152
paramnames=c(
4253
"Beta1","Beta2","Beta3","gamma",
4354
"psi1","psi2","psi3",
44-
names(ic),"N"
55+
names(ivps),"pop"
4556
),
4657
PACKAGE="phylopomp"
4758
)

0 commit comments

Comments
 (0)