R/everything_from_model.R
everything_from_model.Rd
Some rbi.helper
functions require all variables to have outputs. This function modifies a LibBi model
so that this is the case.
everything_from_model(model)
model | A LibBi model, loaded using |
---|
A LibBi model.
library(rbi)#> #>#>#> #>#>#> #>#>#> #>#>#> #>model <- system.file(package="rbi", "SIR.bi") # get full file name from package model <- bi_model(model) # load model model <- replace_all(model, "noise n_recovery", "noise n_recovery\\(has_output = 0\\)") model#> bi_model: #> ========= #> 1: model SIR { #> 2: const h = 7 #> 3: const N = 1000 #> 4: const d_infection = 14 #> 5: noise n_transmission #> 6: noise n_recovery(has_output = 0) #> 7: state S #> 8: state I #> 9: state R #> 10: state Z #> 11: obs Incidence #> 12: param p_rep #> 13: param p_R0 #> 14: sub parameter { #> 15: p_rep ~ uniform(0,1) #> 16: p_R0 ~ uniform(1,3) #> 17: } #> 18: sub initial { #> 19: S <- N - 1 #> 20: I <- 1 #> 21: R <- 0 #> 22: Z <- 1 #> 23: } #> 24: sub transition { #> 25: n_transmission ~ wiener() #> 26: n_recovery ~ wiener() #> 27: Z <- (t_now % 7 == 0 ? 0 : Z) #> 28: inline i_beta = p_R0 / d_infection * exp(n_transmission) #> 29: inline i_gamma = 1 / d_infection * exp(n_recovery) #> 30: ode (alg='RK4(3)', h=1e-1, atoler=1e-2, rtoler=1e-5) { #> 31: dS/dt = - i_beta * S * I / N #> 32: dI/dt = i_beta * S * I / N - i_gamma * I #> 33: dR/dt = i_gamma * I #> 34: dZ/dt = i_beta * S * I / N #> 35: } #> 36: } #> 37: sub observation { #> 38: Incidence ~ poisson(p_rep * Z) #> 39: } #> 40: sub proposal_initial { #> 41: S <- N - 1 #> 42: I <- 1 #> 43: R <- 0 #> 44: Z <- 1 #> 45: } #> 46: sub proposal_parameter { #> 47: p_rep ~ truncated_gaussian(mean = p_rep, std = 0.03, lower = 0, upper = 1) #> 48: p_R0 ~ truncated_gaussian(mean = p_R0, std = 0.2, lower = 1, upper = 3) #> 49: } #> 50: }everything_from_model(model)#> bi_model: #> ========= #> 1: model SIR { #> 2: const h = 7 #> 3: const N = 1000 #> 4: const d_infection = 14 #> 5: noise n_transmission #> 6: noise n_recovery #> 7: state S #> 8: state I #> 9: state R #> 10: state Z #> 11: obs Incidence #> 12: param p_rep #> 13: param p_R0 #> 14: sub parameter { #> 15: p_rep ~ uniform(0,1) #> 16: p_R0 ~ uniform(1,3) #> 17: } #> 18: sub initial { #> 19: S <- N - 1 #> 20: I <- 1 #> 21: R <- 0 #> 22: Z <- 1 #> 23: } #> 24: sub transition { #> 25: n_transmission ~ wiener() #> 26: n_recovery ~ wiener() #> 27: Z <- (t_now % 7 == 0 ? 0 : Z) #> 28: inline i_beta = p_R0 / d_infection * exp(n_transmission) #> 29: inline i_gamma = 1 / d_infection * exp(n_recovery) #> 30: ode (alg='RK4(3)', h=1e-1, atoler=1e-2, rtoler=1e-5) { #> 31: dS/dt = - i_beta * S * I / N #> 32: dI/dt = i_beta * S * I / N - i_gamma * I #> 33: dR/dt = i_gamma * I #> 34: dZ/dt = i_beta * S * I / N #> 35: } #> 36: } #> 37: sub observation { #> 38: Incidence ~ poisson(p_rep * Z) #> 39: } #> 40: sub proposal_initial { #> 41: S <- N - 1 #> 42: I <- 1 #> 43: R <- 0 #> 44: Z <- 1 #> 45: } #> 46: sub proposal_parameter { #> 47: p_rep ~ truncated_gaussian(mean = p_rep, std = 0.03, lower = 0, upper = 1) #> 48: p_R0 ~ truncated_gaussian(mean = p_R0, std = 0.2, lower = 1, upper = 3) #> 49: } #> 50: }