read_xmile: Read an XMILE file into R

Description Usage Arguments Details Value Examples

View source: R/read_xmile.R

Description

read_xmile returns a list for constructing deSolve functions and graphs

Usage

1
read_xmile(filepath, stock_list = NULL, const_list = NULL)

Arguments

filepath

A string that indicates a path to a file with extension .stmx or .xmile. Vensim files (.mdl) are not xmile files. They must be exported from Vensim with extension .xmile

stock_list

A list in which each element's name is the name of the stock to override and the element's value correspond to the new init value.

const_list

A list in which each element's name is the name of the constant to override and the element's value correspond to the new value.

Details

This function extracts the xml from the file specified via filepath to generate a list of objects. Such a list contains a summary of the model, the inputs for simulating through deSolve, and the inputs for creating a igraph object.

Value

This function returns a list with three elements. The first element, description, is a list that contains the simulation parameters, and the names and equations (including graphical functions) for each stock or level, variable and constant. The second element, deSolve_components, is a list that contains initial values, constants and the function for simulating via deSolve. The third element, igraph contains the data.frames for creating a graph with igraph.

Examples

1
2
path <- system.file("models", "SIR.stmx", package = "readsdr")
read_xmile(path)

Example output

$description
$description$parameters
$description$parameters$start
[1] 1

$description$parameters$stop
[1] 13

$description$parameters$dt
[1] 0.125


$description$levels
$description$levels[[1]]
$description$levels[[1]]$name
[1] "Susceptible"

$description$levels[[1]]$equation
[1] "-IR"

$description$levels[[1]]$initValue
[1] 990


$description$levels[[2]]
$description$levels[[2]]$name
[1] "Infected"

$description$levels[[2]]$equation
[1] "IR-RR"

$description$levels[[2]]$initValue
[1] 10


$description$levels[[3]]
$description$levels[[3]]$name
[1] "Recovered"

$description$levels[[3]]$equation
[1] "RR"

$description$levels[[3]]$initValue
[1] 0



$description$variables
$description$variables[[1]]
$description$variables[[1]]$name
[1] "RR"

$description$variables[[1]]$equation
[1] "Infected/recoveryDelay"


$description$variables[[2]]
$description$variables[[2]]$name
[1] "e"

$description$variables[[2]]$equation
[1] "c*i"


$description$variables[[3]]
$description$variables[[3]]$name
[1] "beta_var"

$description$variables[[3]]$equation
[1] "e/population"


$description$variables[[4]]
$description$variables[[4]]$name
[1] "IR"

$description$variables[[4]]$equation
[1] "Susceptible*Infected*beta_var"



$description$constants
$description$constants[[1]]
$description$constants[[1]]$name
[1] "population"

$description$constants[[1]]$value
[1] 1000


$description$constants[[2]]
$description$constants[[2]]$name
[1] "i"

$description$constants[[2]]$value
[1] 0.25


$description$constants[[3]]
$description$constants[[3]]$name
[1] "c"

$description$constants[[3]]$value
[1] 8


$description$constants[[4]]
$description$constants[[4]]$name
[1] "recoveryDelay"

$description$constants[[4]]$value
[1] 2




$deSolve_components
$deSolve_components$stocks
Susceptible    Infected   Recovered 
        990          10           0 

$deSolve_components$consts
   population             i             c recoveryDelay 
      1000.00          0.25          8.00          2.00 

$deSolve_components$func
function (time, stocks, auxs) 
with(as.list(c(stocks, auxs)), {
    RR <- Infected/recoveryDelay
    e <- c * i
    beta_var <- e/population
    IR <- Susceptible * Infected * beta_var
    d_Susceptible_dt <- -IR
    d_Infected_dt <- IR - RR
    d_Recovered_dt <- RR
    return(list(c(d_Susceptible_dt, d_Infected_dt, d_Recovered_dt), 
        RR = RR, e = e, beta_var = beta_var, IR = IR, population = population, 
        i = i, c = c, recoveryDelay = recoveryDelay))
})
<environment: 0x55d7b181e1f8>

$deSolve_components$sim_params
$deSolve_components$sim_params$start
[1] 1

$deSolve_components$sim_params$stop
[1] 13

$deSolve_components$sim_params$dt
[1] 0.125



$graph_dfs
$graph_dfs$nodes
         name     type                      equation
1 Susceptible    stock                           -IR
2    Infected    stock                         IR-RR
3   Recovered    stock                            RR
4          RR variable                    Infected/2
5           e variable                        8*0.25
6    beta_var variable                        e/1000
7          IR variable Susceptible*Infected*beta_var

$graph_dfs$edges
         from          to      type
1          IR Susceptible      flow
2          IR    Infected      flow
3          RR    Infected      flow
4          RR   Recovered      flow
5    Infected          RR info_link
6           e    beta_var info_link
7 Susceptible          IR info_link
8    Infected          IR info_link
9    beta_var          IR info_link

readsdr documentation built on Jan. 13, 2021, 11:08 a.m.