# \dontshow{
## for R_DEFAULT_PACKAGES=NULL
library( stats, pos = "package:base", verbose = FALSE)
library(graphics, pos = "package:base", verbose = FALSE)
library( utils, pos = "package:base", verbose = FALSE)
# }
if (requireNamespace("deSolve")) withAutoprint({
data(seir.ts01, package = "fastbeta")
a <- attributes(seir.ts01); p <- length(a[["init"]])
str(seir.ts01)
plot(seir.ts01)
## We suppose that we have perfect knowledge of incidence,
## births, and the data-generating parameters, except for
## the initial state, which we "guess"
series <- cbind.ts(seir.ts01[, c("Z", "B")], mu = a[["mu"]](0))
plot(series[, "Z"])
start <- 23; end <- 231
abline(v = c(start, end), lty = 2)
set.seed(0L)
args <- c(list(series = series),
a[c("sigma", "gamma", "delta", "m", "n", "init")],
list(start = start, end = end, complete = TRUE))
init <- seir.ts01[which.min(abs(time(seir.ts01) - start)), seq_len(p)]
args[["init"]] <- init * rlnorm(p, 0, 0.1)
str(args)
L <- do.call(ptpi, args)
str(L)
S <- L[["x"]][, "S", ]
plot(S, plot.type = "single")
lines(seir.ts01[, "S"], col = "red", lwd = 4) # the "truth"
abline(h = L[["value"]]["S"], v = start, col = "blue", lwd = 4, lty = 2)
## Relative error
L[["value"]] / init - 1
})
Run the code above in your browser using DataLab