R version 4.4.0 RC (2024-04-16 r86468 ucrt) -- "Puppy Cup" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## This file is part of SimInf, a framework for stochastic > ## disease spread simulations. > ## > ## Copyright (C) 2015 -- 2021 Stefan Widgren > ## > ## SimInf is free software: you can redistribute it and/or modify > ## it under the terms of the GNU General Public License as published by > ## the Free Software Foundation, either version 3 of the License, or > ## (at your option) any later version. > ## > ## SimInf is distributed in the hope that it will be useful, > ## but WITHOUT ANY WARRANTY; without even the implied warranty of > ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > ## GNU General Public License for more details. > ## > ## You should have received a copy of the GNU General Public License > ## along with this program. If not, see . > > library(SimInf) > library(tools) > source("util/check.R") > > ## Specify the number of threads to use. > set_num_threads(1) > > ## For debugging > sessionInfo() R version 4.4.0 RC (2024-04-16 r86468 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows Server 2022 x64 (build 20348) Matrix products: default locale: [1] LC_COLLATE=C LC_CTYPE=German_Germany.utf8 [3] LC_MONETARY=C LC_NUMERIC=C [5] LC_TIME=C time zone: Europe/Berlin tzcode source: internal attached base packages: [1] tools stats graphics grDevices utils datasets methods [8] base other attached packages: [1] SimInf_9.7.0 loaded via a namespace (and not attached): [1] MASS_7.3-60.2 compiler_4.4.0 Matrix_1.7-0 grid_4.4.0 digest_0.6.35 [6] lattice_0.22-6 > > res <- assertError(SimInf:::parse_priors(c(a + b ~ uniform(0, 5), + c ~ uniform(0, 1), 4))) > check_error(res, "'priors' must be a formula or a list with formula items.") > > res <- assertError(SimInf:::parse_priors(4)) > check_error(res, "'priors' must be a formula or a list with formula items.") > > res <- assertError(SimInf:::parse_priors(NULL)) > check_error(res, "'priors' must be a formula or a list with formula items.") > > res <- assertError(SimInf:::parse_priors(mu ~ uniform(0, 1) + normal(0, 1))) > check_error(res, "Invalid formula specification for distribution.") > > res <- assertError(SimInf:::parse_priors(mu ~ uniform[0, 1])) > check_error(res, "Invalid formula specification for distribution.") > > res <- assertError(SimInf:::parse_priors(mu ~ unknown(0, 1))) > check_error(res, "Unknown distribution: 'unknown'.") > > res <- assertError(SimInf:::parse_priors(c(muR ~ uniform(0, 1), + muR ~ uniform(0, 1)))) > check_error(res, "'priors' must have non-duplicated parameter names.") > > res <- assertError(SimInf:::parse_priors(beta ~ uniform(1))) > check_error(res, "Invalid formula specification for uniform distribution.") > > res <- assertError(SimInf:::parse_priors(beta ~ uniform(1, 0))) > check_error(res, "Invalid distribution: uniform bounds in wrong order.") > > res <- assertError(SimInf:::parse_priors(beta ~ normal(1))) > check_error(res, "Invalid formula specification for normal distribution.") > > res <- assertError(SimInf:::parse_priors(beta ~ normal(0, -1))) > check_error(res, "Invalid distribution: normal variance must be >= 0.") > > res <- assertError(SimInf:::parse_priors(beta ~ poisson(1, 2))) > check_error(res, "Invalid formula specification for poisson distribution.") > > res <- assertError(SimInf:::parse_priors(beta ~ poisson(-1))) > check_error(res, "Invalid distribution: lambda must be >= 0.") > > res <- assertError(SimInf:::parse_priors(beta ~ normal(0, gamma))) > check_error(res, "Invalid formula specification for 'priors'.") > > res <- assertError(SimInf:::parse_priors(beta ~ gamma(1))) > check_error(res, "Invalid formula specification for gamma distribution.") > > res <- assertError(SimInf:::parse_priors(beta ~ gamma(-1, 1))) > check_error(res, "Invalid distribution: gamma hyperparameters must be > 0.") > > res <- assertError(SimInf:::parse_priors(beta ~ gamma(1, -1))) > check_error(res, "Invalid distribution: gamma hyperparameters must be > 0.") > > res <- assertError(SimInf:::parse_priors(beta ~ binomial(1))) > check_error(res, "Invalid formula specification for binomial distribution.") > > res <- assertError(SimInf:::parse_priors(beta ~ binomial(1, NA))) > check_error(res, "Invalid formula specification for binomial distribution.") > > res <- assertError(SimInf:::parse_priors(beta ~ binomial(1, -1))) > check_error(res, "Invalid distribution: binomial hyperparameters must be >= 0.") > > res <- assertError(SimInf:::parse_priors(beta ~ binomial(1.1, 0.1))) > check_error(res, "Invalid distribution: binomial size must be an integer >= 0.") > > res <- assertError(SimInf:::parse_priors(beta ~ binomial(1, 1.1))) > check_error(res, "Invalid distribution: binomial probability must be <= 1.") > > res <- assertError(SimInf:::parse_priors(~ uniform(1, 5))) > check_error(res, "Invalid formula specification for distribution.") > > stopifnot(identical( + SimInf:::parse_priors(beta ~ uniform(1, 5)), + data.frame(parameter = "beta", distribution = "uniform", + p1 = 1, p2 = 5, stringsAsFactors = FALSE))) > > res <- assertError( + SimInf:::match_priors( + SIR(u0 = data.frame(S = 99, I = 1, R = 0), + tspan = 1:100, + beta = 0.16, + gamma = 0.077), + data.frame(parameter = "delta", + distribution = "uniform", + p1 = 1, + p2 = 5))) > check_error( + res, + "All parameters in 'priors' must be either in 'gdata' or 'ldata'.") > > res <- assertError( + SimInf:::match_priors( + SIR(u0 = data.frame(S = c(99, 99), I = c(1, 1), R = c(0, 0)), + tspan = 1:100, + beta = 0.16, + gamma = 0.077), + data.frame(parameter = "beta", + distribution = "uniform", + p1 = 1, + p2 = 5))) > check_error(res, "The 'model' must contain one node.") > > res <- SimInf:::match_priors( + SIR(u0 = data.frame(S = 99, I = 1, R = 0), + tspan = 1:100, + beta = 0.16, + gamma = 0.077), + data.frame(parameter = "beta", + distribution = "uniform", + p1 = 1, + p2 = 5)) > stopifnot(identical(res, list(pars = 1L, target = "ldata"))) > > res <- SimInf:::match_priors( + mparse(transitions = c("S -> beta*S*I/(S+I+R) -> I", + "I -> gamma*I -> R"), + compartments = c("S", "I", "R"), + gdata = c(beta = 0.16, gamma = 0.077), + u0 = data.frame(S = 99, I = 1, R = 0), + tspan = 1:10), + data.frame(parameter = "beta", + distribution = "uniform", + p1 = 1, + p2 = 5)) > stopifnot(identical(res, list(pars = 1L, target = "gdata"))) > > proc.time() user system elapsed 0.95 0.06 1.01