Using Simpact Cyan with R: Part I


Installing Simpact and Running a Simple Simulation


Content

  1. Installing Simpact Cyan and other packages required by Simpact
  2. Configuring a simulation
  3. Running a simple simulation
  4. Checking out the output

1. Installing Simpact Cyan and the required R packages

library(devtools)
# install from git
#install_github(repo="SimpactUtility",username='yfmeng')
library(simpact)
library(SimpactUtility)
library(EasyABC)

Setup the working directory as you wish

folder<- '/Users/feimeng/SimpactUtility/test'
setwd(folder)

2. Configuring a simulation

Parameters to be changed can be stored in a list, the name of a .csv file or input from keyboard. For example, if you want keep all parameters as default except two: “formation.hazard.agegap.baseline” and “hivseed.fraction”, and rename the output files as “event1.csv”,“persons1.csv” and “relation1.csv”:

cfg.1<-list()
cfg.1[['formation.hazard.agegap.baseline']]<-0.11
cfg.1[['hivseed.fraction']]<-0.1
cfg.1$logsystem.filename.events<-'event1'
cfg.1$logsystem.filename.persons<-'person1'
cfg.1$logsystem.filename.relations<-'relation1'

Otherwise, use keyboard to input the parameter names and values following the instruction:

# following the instruction, try type 
# >>formation.hazard.agegap.baseline
# >>0.15
# exit keyboard with an enter
cfg.2<-uni.configure()

3. Running a simple simulation A simpact simulation can be run by a single line as:

test.1<-simpact.run(uni.configure(cfg.1),folder)
test.2<-simpact.run(cfg.2,folder)

The output arguments 'test.1' and 'test.2' are lists of simulation information including names of log files.


4. Checking out the output

Several functions are implemented to:

(1) convert output to network

net.1<-simpact2network(test.1)

(2) summarise statistics of the network

test.1.network.summary<-network.summary(net.1)

(3) summarise HIV epidemical statistics

test.1.hiv.summary<-epidemic.summary(test.1)

It is also possible to summarise epiedemical statistics of a specified age group during a specified time period

# summary of specified age group during specified time period
epidemic.summary(test.1, time.range=c(5,15), age.range=c(15,50))
plot(test.1.hiv.summary$times,test.1.hiv.summary$male.positive/test.1.hiv.summary$male.alive*100,
     main="HIV prevalence (male)",ylab="%",xlab='Time (year)',type='l',
     xlim=c(0,15))