{"id":26947965,"url":"https://github.com/mclements/microsimulation","last_synced_at":"2025-04-02T20:27:29.042Z","repository":{"id":5926613,"uuid":"7146442","full_name":"mclements/microsimulation","owner":"mclements","description":"R package for microsimulation","archived":false,"fork":false,"pushed_at":"2023-10-02T14:48:54.000Z","size":17174,"stargazers_count":33,"open_issues_count":2,"forks_count":9,"subscribers_count":10,"default_branch":"master","last_synced_at":"2023-11-20T15:22:49.224Z","etag":null,"topics":["cpp","discrete-event-simulation","health-economics","r"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mclements.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-12-13T10:25:12.000Z","updated_at":"2024-08-13T21:08:04.811Z","dependencies_parsed_at":"2023-10-02T18:42:18.807Z","dependency_job_id":null,"html_url":"https://github.com/mclements/microsimulation","commit_stats":{"total_commits":428,"total_committers":7,"mean_commits":"61.142857142857146","dds":0.3200934579439252,"last_synced_commit":"f4c4fca61519f35972a49b1366d1f4270e55da20"},"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mclements%2Fmicrosimulation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mclements%2Fmicrosimulation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mclements%2Fmicrosimulation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mclements%2Fmicrosimulation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mclements","download_url":"https://codeload.github.com/mclements/microsimulation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246886885,"owners_count":20849947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","discrete-event-simulation","health-economics","r"],"created_at":"2025-04-02T20:27:28.283Z","updated_at":"2025-04-02T20:27:29.032Z","avatar_url":"https://github.com/mclements.png","language":"R","readme":"#+TITLE: Microsimulation package for R\n\n#+OPTIONS: toc:nil\n#+OPTIONS: num:nil\n#+OPTIONS: html-postamble:nil\n\n# Babel settings\n# +PROPERTY: session *R-microsimulation*\n# +PROPERTY: cache yes\n# +PROPERTY: results output graphics\n# +PROPERTY: exports both\n# +PROPERTY: tangle yes\n# +PROPERTY: exports both\n\n[[http://www.gnu.org/licenses/gpl-3.0.html][http://img.shields.io/:license-gpl3-blue.svg]]\n* News\n\n+ The *microsimulation* package now allows for *in-line use* and provides a new *SummaryReport* class. See the in-line example below for a demonstration of both of these facilities.\n+ The C++ application programming interface is now [[https://htmlpreview.github.io/?https://github.com/mclements/microsimulation/blob/master/inst/doc/html/index.html][described]] using Doxygen.\n\n* Background\n[[https://en.wikipedia.org/wiki/Microsimulation][Microsimulation]] is a form of individual-based stochastic\nsimulation. In continuous time, microsimulation is closely related to\n[[https://en.wikipedia.org/wiki/Discrete_event_simulation][discrete event simulation]], and in discrete time it is closely related\nto [[https://en.wikipedia.org/wiki/Agent-based_model][agent-based models]]. In econometrics and health care,\nmicrosimulation is often used to model policy changes. Our\nimplementation is in continuous time and uses event-based discrete\nevent simulation for the model specification.\n\nThe package provides several approaches for microsimulation and\nevent-based, discrete event simulation. The package includes an R\nimplementation of discrete event simulation, building on several R5\nclasses. This implementation is useful from a pedagogical perspective,\nbut it is slow for larger microsimulations. For speed, we also provide\nC++ classes for discrete event simulation, building on several well\nestablished libraries, including the [[http://www.inf.usi.ch/carzaniga/ssim/index.html][SSIM]] C++ discrete event\nsimulation library, the [[http://www.iro.umontreal.ca/~lecuyer/myftp/streams00/][RngStream]] C library for common random numbers,\nthe [[http://www.boost.org/][Boost]] libraries for making many C++11 tools available to C++98,\nand [[http://www.rcpp.org/][Rcpp]] for providing glue between R, R's C API and C++.\n\nWe specifically developed this package for modelling the\ncost-effectiveness of cancer screening, where there are many\n(e.g. 10^7) individuals who are followed from birth to death. Notably,\nwe provide a complete prostate cancer screening model, including tools\nfor cost-effectiveness analysis.\n* Installing the package\n+ 1 Installation through CRAN: ::\nTo install the microsimulation package from CRAN, just run the following in R:\n#+BEGIN_SRC R :session *R-microsimulation* :exports code :eval never\n  install.packages(\"microsimulation\")\n#+END_SRC\n\nFor compiling from source, use steps 2--3.\n\n+ 2 Dependencies: ::\nThe microsimulation package requires [[http://www.rcpp.org/][Rcpp]]. A convenient, but not\nrequired, way of installing github-packages in R is to use\n[[https://cran.r-project.org/web/packages/devtools/README.html][devtools]]. Since both of the dependencies and [[https://cran.r-project.org/web/packages/devtools/README.html][devtools]] are available on\n[[https://cran.r-project.org/][CRAN]] just run the following in R.\n#+BEGIN_SRC R :session *R-microsimulation* :exports code :eval never\n  install.packages(\"Rcpp\")\n  install.packages(\"devtools\")\n#+END_SRC\n\n+ 3a Installation with devtools: ::\nTo install the microsimulation using [[https://cran.r-project.org/web/packages/devtools/README.html][devtools]] just run the following in R:\n#+BEGIN_SRC R :session *R-microsimulation* :exports code :eval never\n  require(devtools)\n  install_github(\"mclements/microsimulation\")\n#+END_SRC\n+ 3b Alternative installation from shell: ::\n# Some thing OS-specific?\nIf you prefer the shell over [[https://cran.r-project.org/web/packages/devtools/README.html][devtools]], just run the following to download the\nmicrosimulation R-package:\n#+BEGIN_SRC shell :exports code :eval never\n  git clone https://github.com/mclements/microsimulation.git\n#+END_SRC\n\nTo install the microsimulation R-package run this in your shell:\n#+BEGIN_SRC shell :exports code :eval never\n  R CMD INSTALL path_to_microsimulation\n#+END_SRC\n\n* Running the simulation\n\n\n** Simple examples\n\n\n#+name: commentify\n#+begin_src emacs-lisp :var result=\"\" :exports none\n(concat \"#\u003e \"(mapconcat 'identity (split-string result \"\\n\") \"\\n#\u003e \"))\n#+end_src\n\n#+BEGIN_SRC R :session *R-microsimulation* :post commentify(*this*) :results output :exports both :eval never-export\n  require(microsimulation)\n  sim1 \u003c- callSimplePerson2(n = 1e5)\n  summary(sim1$events)\n#+END_SRC\n\n#+RESULTS:\n: #\u003e      state               event          age             number\n: #\u003e  Healthy:338   toOtherDeath :142   Min.   :  1.00   Min.   :   1.0\n: #\u003e  Cancer :  0   toCancer     :100   1st Qu.: 37.00   1st Qu.:  74.0\n: #\u003e  Death  :  0   toCancerDeath: 96   Median : 58.00   Median : 325.0\n: #\u003e                                    Mean   : 56.98   Mean   : 445.1\n: #\u003e                                    3rd Qu.: 79.00   3rd Qu.: 721.8\n: #\u003e                                    Max.   :100.00   Max.   :1722.0\n: #\u003e\n\n#+BEGIN_SRC R :session *R-microsimulation* :post commentify(*this*) :results output :exports both :eval never-export\n  sim2 \u003c- callIllnessDeath(n = 1e5, cure = 0.2)\n  summary(sim2$prev)\n#+END_SRC\n\n#+RESULTS:\n: #\u003e      state          age             number\n: #\u003e  Healthy:200   Min.   :  0.00   Min.   :     1\n: #\u003e  Cancer :  0   1st Qu.: 25.75   1st Qu.:  2030\n: #\u003e                Median : 50.50   Median :  8096\n: #\u003e                Mean   : 50.49   Mean   : 34914\n: #\u003e                3rd Qu.: 75.25   3rd Qu.: 79029\n: #\u003e                Max.   :100.00   Max.   :100000\n: #\u003e\n\n\n** In-line example: Sick-Sicker example from Krijkamp et al (2018)\n\nWe have provided a continuous-time re-implementation of the discrete-time Markov model developed by Krijkamp et al (2018).\n\nThe example demonstrates:\n+ Passing data between R and C++.\n+ Development of a =SickSicker= class in C++ that inherits from =ssim::cProcess=. This requires the specification of a =void init()= method and a =void handleMessage(const ssim::cMessage* msg)= method.\n+ Reporting using the new =SummaryReport= class, which allows for utilities, point and interval costs and discounting. The class also allows for reporting individual costs and utilities to calculate the Monte Carlo error.\n\nFor the specific example, the transformation from discrete to continuous time showed that the discrete time formulation could have been improved. In particular, the discrete time formulation assumes no transitions between Healthy and Sicker over one year, while the approximate probability of that event is the one-year probability of moving from Healthy to Sick times the probability of moving from Sick to Sicker. We have included that probability in the transition matrix and using matrix logarithms to calculate the transition probabilities.\n\n#+BEGIN_SRC R :session *R-microsimulation* :results output wrap :exports both\n# +BEGIN_SRC R :session *R-microsimulation* :results output wrap :exports both :eval never-export\nlibrary(expm) # logm\nlibrary(Rcpp) # sourceCpp\nlibrary(microsimulation) # Rcpp::depends and include files\nlibrary(ascii); options(asciiType=\"org\")\n## set up the parameters\nparam \u003c- within(list(), {\n    ## Transition probabilities (per cycle) and rates\n    p.HD = 0.005 # probability to die when healthy\n    p.HS1 = 0.15 # probability to become sick when healthy\n    p.S1H = 0.5 # probability to become healthy when sick\n    p.S1S2 = 0.105 # probability to become sicker when sick\n    rr.S1 = 3 # rate ratio of death when sick vs healthy\n    rr.S2 = 10 # rate ratio of death when sicker vs healthy\n    r.HD = -log(1-p.HD) # rate of death when healthy\n    r.S1D = rr.S1 * r.HD # rate of death when sick\n    r.S2D = rr.S2 * r.HD # rate of death when sicker\n    p.S1D = 1-exp(-r.S1D) # probability to die when sick\n    p.S2D = 1-exp(-r.S2D) # probability to die when sicker\n    ## Cost and utility inputs\n    c_H = 2000 # cost of remaining one cycle healthy\n    c_S1 = 4000 # cost of remaining one cycle sick\n    c_S2 = 15000 # cost of remaining one cycle sicker\n    c_Trt = 12000 # (additional) cost of treatment (per cycle)\n    u_H = 1 # utility when healthy\n    u_S1 = 0.75 # utility when sick\n    u_S2 = 0.5 # utility when sicker\n    u_Trt = 0.95 # utility when sick (as per the code) and being treated\n    ## new parameters\n    discountRate = 0.03 # discount rate\n    partitionBy = 1.0 # partition used in the report\n    Trt = FALSE # Treatment?\n    debug = FALSE\n})\n## For converting from discrete to continuous time: *p.HS2 should be non-zero*\nparam = within(param, { p.HS2 = p.HS1*p.S1S2 })\nPmat = with(param,\n            matrix(c(1-p.HD-p.HS1-p.HS2,p.HS1,p.HS2,p.HD,\n                     p.S1H,1-p.S1H-p.S1S2-p.S1D,p.S1S2,p.S1D,\n                     0,0,1-p.S2D,p.S2D,\n                     0,0,0,1), 4, byrow=TRUE))\nstopifnot(all(abs(rowSums(Pmat)-1)\u003c10*.Machine$double.eps))\nQmat = expm::logm(Pmat) # matrix logarithm\nstopifnot(all(abs(rowSums(Qmat))\u003c10*.Machine$double.eps))\n## update the rates in param\nparam = within(param,\n{ r_HS1 = Qmat[1,2]; r_HD = Qmat[1,4]\n    r_S1H = Qmat[2,1]; r_S1S2 = Qmat[2,3]; r_S1D = Qmat[2,4]\n    r_S2D = Qmat[3,4] })\n##\nsourceCpp(code=\"\n  // [[Rcpp::depends(BH)]]\n  // [[Rcpp::depends(RcppArmadillo)]]\n  // [[Rcpp::depends(microsimulation)]]\n  #include \u003cmicrosimulation.h\u003e\n  enum state_t {Healthy, Sick, Sicker, Dead};\n  enum event_t {toS1, toS2, toH, toD, toEOF};\n  typedef ssim::SummaryReport\u003cshort,short\u003e Report;\n  /**\n      Utility: Random exponential using rate parameterisation\n  */\n  template\u003cclass T\u003e double rexpRate(T rate) { return R::rexp(1.0/as\u003cdouble\u003e(rate)); }\n  /**\n      Utility: Run a set of simulations for a single process\n  */\n  void runSimulations(ssim::cProcess* process, int n) {\n    for (int i = 0; i \u003c n; i++) {\n      ssim::Sim::create_process(process);\n      ssim::Sim::run_simulation();\n      ssim::Sim::clear();\n    }\n  }\n  /**\n      Define a class for the process\n  */\n  class SickSicker : public ssim::cProcess\n  {\n  public:\n    int id;\n    state_t state;\n    Rcpp::List param;\n    Report *report;\n    SickSicker(Rcpp::List param, Report *report) : id(-1), param(param), report(report) {\n    }\n    void init(); // to be specified\n    void handleMessage(const ssim::cMessage* msg); // to be specified\n    void cancelEvents(); // utility function\n  };\n  /**\n      Initialise a simulation run for an individual\n  */\n  void SickSicker::init() {\n    id++;\n    state = Healthy;\n    scheduleAt(rexpRate(param[\\\"r_HS1\\\"]),toS1);\n    scheduleAt(rexpRate(param[\\\"r_HD\\\"]),toD);\n    scheduleAt(31.0,toEOF); // end of follow-up\n  }\n /**\n      Utility to cancel some events\n  */\n  void SickSicker::cancelEvents() {\n    ssim::RemoveKind(toH);\n    ssim::RemoveKind(toS1);\n    ssim::RemoveKind(toS2);\n    ssim::RemoveKind(toD);\n  }\n  /**\n      Handle receiving self-messages\n  */\n  void SickSicker::handleMessage(const ssim::cMessage* msg) {\n    if (param[\\\"debug\\\"]) Rprintf(\\\"id: %i, state: %i, kind: %i, previous: %f, now: %f\\\\n\\\",\n                       id, state, msg-\u003ekind, this-\u003epreviousEventTime, ssim::now());\n    report-\u003eadd(state, msg-\u003ekind, this-\u003epreviousEventTime, ssim::now(), id);\n    switch(msg-\u003ekind) {\n    case toH:\n      state = Healthy;\n      report-\u003esetUtility(param[\\\"u_H\\\"]);\n      report-\u003esetCost(param[\\\"c_H\\\"]);\n      cancelEvents();\n      scheduleAt(ssim::now() + rexpRate(param[\\\"r_HS1\\\"]), toS1);\n      scheduleAt(ssim::now() + rexpRate(param[\\\"r_HD\\\"]), toD);\n      break;\n    case toS1:\n      state = Sick;\n      report-\u003esetUtility(param[\\\"Trt\\\"] ? param[\\\"u_Trt\\\"] : param[\\\"u_S1\\\"]);\n      report-\u003esetCost(param[\\\"c_S1\\\"] + (param[\\\"Trt\\\"] ? param[\\\"c_Trt\\\"] : 0.0));\n      cancelEvents();\n      scheduleAt(ssim::now() + rexpRate(param[\\\"r_S1H\\\"]), toH);\n      scheduleAt(ssim::now() + rexpRate(param[\\\"r_S1S2\\\"]), toS2);\n      scheduleAt(ssim::now() + rexpRate(param[\\\"r_S1D\\\"]), toD);\n      break;\n    case toS2:\n      state = Sicker;\n      report-\u003esetUtility(param[\\\"u_S2\\\"]);\n      report-\u003esetCost(param[\\\"c_S2\\\"] + (param[\\\"Trt\\\"] ? param[\\\"c_Trt\\\"] : 0.0));\n      cancelEvents();\n      scheduleAt(ssim::now() + rexpRate(param[\\\"r_S2D\\\"]), toD);\n      break;\n    case toD:\n    case toEOF:\n      ssim::Sim::stop_simulation();\n      break;\n    default:\n      REprintf(\\\"Invalid kind of event: %i.\\\\n\\\", msg-\u003ekind);\n      break;\n    }\n    if (id % 10000 == 0) Rcpp::checkUserInterrupt(); /* be polite */\n  }\n  /**\n      Exported function: Set up the report and process, run the simulations and return a report\n  */\n  //[[Rcpp::export]]\n  Rcpp::List callSim(int n, Rcpp::List param, bool indivp = true) {\n    Report report(n,indivp);\n    report.setPartition(0.0,31.0,param[\\\"partitionBy\\\"]);\n    report.setDiscountRate(param[\\\"discountRate\\\"]);\n    SickSicker person(param,\u0026report);\n    runSimulations(\u0026person, n);\n    Rcpp::List lst = report.asList();\n    lst.push_back(param,\\\"param\\\");\n    return lst;\n  }\")\nsimulations = function(n, param, simulator=callSim, indivp=TRUE) {\n    object = simulator(n, param, indivp)\n    stateT = c(\"Healthy\",\"Sick\",\"Sicker\",\"Dead\")\n    eventT = c(\"toS1\", \"toS2\", \"toH\", \"toD\", \"toEOF\")\n    for (name in c(\"ut\",\"costs\",\"pt\",\"events\",\"prev\"))\n        object[[name]] = transform(object[[name]], state=stateT[Key+1], Key=NULL)\n    object$events = transform(object$events, event=eventT[event+1])\n    class(object) = c(\"SickSicker\",\"SummaryReport\")\n    object\n}\n## define a utility function for using system.time with ascii\nascii.proc_time = function(x, include.rownames=FALSE, include.colnames=TRUE, ...)\n    ascii(summary(x), include.rownames, include.colnames, ...)\n## run the simulations\nset.seed(12345)\nascii(system.time(sim1 \u003c- simulations(1e3,\n                                      param=modifyList(param, list(Trt = FALSE)))),header=TRUE)\nset.seed(12345)\nascii(system.time(sim2 \u003c- simulations(1e3,\n                                      param=modifyList(param, list(Trt = TRUE)))),FALSE,FALSE)\ncat(\"\\n\")\nascii(ICER(sim1,sim2), rownames=c(\"No treatment\",\"Treatment\"),\n      caption=\"Continuous-time Sick-Sicker model for n=10,000 individuals\")\n#+end_src\n\n#+RESULTS:\n:RESULTS:\n| user | system | elapsed |\n|------+--------+---------|\n| 0.10 |   0.00 |    0.10 |\n| 0.09 |   0.00 |    0.09 |\n\n#+CAPTION: Continuous-time Sick-Sicker model for n=10,000 individuals\n|              | *Total*  |        |        |       | *Incremental* |        |       |       |          |\n|              | Costs    | (se)   | QALYs  | (se)  | Costs         | (se)   | QALYs | (se)  | ICER     |\n|--------------+----------+--------+--------+-------+---------------+--------+-------+-------+----------|\n| No treatment | 117835.7 | 2263.0 | 13.101 | 0.160 |               |        |       |       |          |\n| Treatment    | 223871.9 | 4097.8 | 13.658 | 0.167 | 106036.1      | 1881.9 | 0.558 | 0.013 | 190110.5 |\n:END:\n\n+ The simulations can also be undertaken in parallel:\n \n#+BEGIN_SRC R :session *R-microsimulation* :results output wrap :exports both\n# +BEGIN_SRC R :session *R-microsimulation* :results output wrap :exports both :eval never-export\n\n  library(parallel)\n  set.seed(12345)\n  mcsimulations \u003c- function(n, simulations, ..., mc.cores = getOption(\"mc.cores\", 2L)) {\n      n.seg \u003c- diff(c((0:(mc.cores-1))*floor(n/mc.cores),n))\n      do.call(rbind, mclapply(n.seg, simulations, ..., mc.cores=mc.cores))\n  }\n  ascii(system.time(sim1 \u003c- mcsimulations(1e5, simulations, \n                                          param=modifyList(param, list(Trt = FALSE)))),\n        header=TRUE)\n  set.seed(12345)\n  ascii(system.time(sim2 \u003c- mcsimulations(1e5, simulations,\n                                          param=modifyList(param, list(Trt = TRUE)))),\n        FALSE,FALSE)\n  cat(\"\\n\")\n  ascii(ICER(sim1,sim2),caption=\"Continuous-time Sick-Sicker model for n=100,000 individuals\")\n\n#+end_src\n\n#+RESULTS:\n:RESULTS:\n| user | system | elapsed |\n|------+--------+---------|\n| 8.25 |   0.03 |    4.14 |\n| 4.18 |   0.02 |    4.20 |\n\n#+CAPTION: Continuous-time Sick-Sicker model for n=100,000 individuals\n|           | *Total*  |       |        |       | *Incremental* |       |       |       |          |\n|           | Costs    | (se)  | QALYs  | (se)  | Costs         | (se)  | QALYs | (se)  | ICER     |\n|-----------+----------+-------+--------+-------+---------------+-------+-------+-------+----------|\n| Reference | 118425.3 | 234.4 | 13.133 | 0.016 |               |       |       |       |          |\n| Treatment | 225548.4 | 424.3 | 13.720 | 0.017 | 107123.1      | 485.7 | 0.587 | 0.023 | 182387.6 |\n:END:\n\nThere was an appreciable difference in the estimates from the discrete-time case and the continuous-time case. This issue warrants further investigation, particularly given that the discrete time case ignores any transitions between Healthy and Sicker within a one-year period.\n\n#+caption: Results from Krijkamp et al (2018), Table 2 for their discrete-time microsimulation model with n=100,000 individuals\n|           | *Total* |      |       |       | *Incremental* |      |       |       |        |\n|           |   Costs | (se) | QALYs |  (se) |         Costs | (se) | QALYs |  (se) |   ICER |\n|-----------+---------+------+-------+-------+---------------+------+-------+-------+--------|\n|           |         |      |       |       |           \u003cr\u003e |      |       |       |        |\n| Reference |   75996 |  183 | 15.82 | 0.016 |               |      |       |       |        |\n| Treatment |  141644 |  343 | 16.38 | 0.016 |         65648 |  164 | 0.561 | 0.001 | 117087 |\n\n\n#+BEGIN_SRC R :session *R-microsimulation* :results output :exports both\n  set.seed(12345)\n  invisible(callSim(5, modifyList(param, list(debug=TRUE))))\n  set.seed(12345)\n  invisible(callSim(5, modifyList(param, list(Trt=TRUE, debug=TRUE))))\n#+end_src\n\n#+RESULTS:\n#+begin_example\nid: 0, state: 0, kind: 0, previous: 0.000000, now: 1.554306\nid: 0, state: 1, kind: 1, previous: 1.554306, now: 1.660357\nid: 0, state: 2, kind: 3, previous: 1.660357, now: 2.137922\nid: 1, state: 0, kind: 0, previous: 0.000000, now: 22.523279\nid: 1, state: 1, kind: 2, previous: 22.523279, now: 23.538790\nid: 1, state: 0, kind: 0, previous: 23.538790, now: 25.110528\nid: 1, state: 1, kind: 2, previous: 25.110528, now: 25.529621\nid: 1, state: 0, kind: 4, previous: 25.529621, now: 31.000000\nid: 2, state: 0, kind: 0, previous: 0.000000, now: 1.279403\nid: 2, state: 1, kind: 2, previous: 1.279403, now: 2.482209\nid: 2, state: 0, kind: 0, previous: 2.482209, now: 4.467754\nid: 2, state: 1, kind: 2, previous: 4.467754, now: 5.240185\nid: 2, state: 0, kind: 0, previous: 5.240185, now: 6.123519\nid: 2, state: 1, kind: 2, previous: 6.123519, now: 7.951863\nid: 2, state: 0, kind: 0, previous: 7.951863, now: 10.967305\nid: 2, state: 1, kind: 2, previous: 10.967305, now: 11.127479\nid: 2, state: 0, kind: 0, previous: 11.127479, now: 15.295999\nid: 2, state: 1, kind: 1, previous: 15.295999, now: 16.663526\nid: 2, state: 2, kind: 4, previous: 16.663526, now: 31.000000\nid: 3, state: 0, kind: 0, previous: 0.000000, now: 0.021088\nid: 3, state: 1, kind: 2, previous: 0.021088, now: 1.648953\nid: 3, state: 0, kind: 0, previous: 1.648953, now: 1.665451\nid: 3, state: 1, kind: 1, previous: 1.665451, now: 2.825812\nid: 3, state: 2, kind: 3, previous: 2.825812, now: 3.378253\nid: 4, state: 0, kind: 0, previous: 0.000000, now: 1.548766\nid: 4, state: 1, kind: 2, previous: 1.548766, now: 4.303079\nid: 4, state: 0, kind: 0, previous: 4.303079, now: 5.128089\nid: 4, state: 1, kind: 2, previous: 5.128089, now: 5.418233\nid: 4, state: 0, kind: 0, previous: 5.418233, now: 9.734630\nid: 4, state: 1, kind: 2, previous: 9.734630, now: 11.013894\nid: 4, state: 0, kind: 0, previous: 11.013894, now: 26.388802\nid: 4, state: 1, kind: 2, previous: 26.388802, now: 26.514306\nid: 4, state: 0, kind: 0, previous: 26.514306, now: 27.803678\nid: 4, state: 1, kind: 2, previous: 27.803678, now: 28.437418\nid: 4, state: 0, kind: 4, previous: 28.437418, now: 31.000000\nid: 0, state: 0, kind: 0, previous: 0.000000, now: 1.554306\nid: 0, state: 1, kind: 1, previous: 1.554306, now: 1.660357\nid: 0, state: 2, kind: 3, previous: 1.660357, now: 2.137922\nid: 1, state: 0, kind: 0, previous: 0.000000, now: 22.523279\nid: 1, state: 1, kind: 2, previous: 22.523279, now: 23.538790\nid: 1, state: 0, kind: 0, previous: 23.538790, now: 25.110528\nid: 1, state: 1, kind: 2, previous: 25.110528, now: 25.529621\nid: 1, state: 0, kind: 4, previous: 25.529621, now: 31.000000\nid: 2, state: 0, kind: 0, previous: 0.000000, now: 1.279403\nid: 2, state: 1, kind: 2, previous: 1.279403, now: 2.482209\nid: 2, state: 0, kind: 0, previous: 2.482209, now: 4.467754\nid: 2, state: 1, kind: 2, previous: 4.467754, now: 5.240185\nid: 2, state: 0, kind: 0, previous: 5.240185, now: 6.123519\nid: 2, state: 1, kind: 2, previous: 6.123519, now: 7.951863\nid: 2, state: 0, kind: 0, previous: 7.951863, now: 10.967305\nid: 2, state: 1, kind: 2, previous: 10.967305, now: 11.127479\nid: 2, state: 0, kind: 0, previous: 11.127479, now: 15.295999\nid: 2, state: 1, kind: 1, previous: 15.295999, now: 16.663526\nid: 2, state: 2, kind: 4, previous: 16.663526, now: 31.000000\nid: 3, state: 0, kind: 0, previous: 0.000000, now: 0.021088\nid: 3, state: 1, kind: 2, previous: 0.021088, now: 1.648953\nid: 3, state: 0, kind: 0, previous: 1.648953, now: 1.665451\nid: 3, state: 1, kind: 1, previous: 1.665451, now: 2.825812\nid: 3, state: 2, kind: 3, previous: 2.825812, now: 3.378253\nid: 4, state: 0, kind: 0, previous: 0.000000, now: 1.548766\nid: 4, state: 1, kind: 2, previous: 1.548766, now: 4.303079\nid: 4, state: 0, kind: 0, previous: 4.303079, now: 5.128089\nid: 4, state: 1, kind: 2, previous: 5.128089, now: 5.418233\nid: 4, state: 0, kind: 0, previous: 5.418233, now: 9.734630\nid: 4, state: 1, kind: 2, previous: 9.734630, now: 11.013894\nid: 4, state: 0, kind: 0, previous: 11.013894, now: 26.388802\nid: 4, state: 1, kind: 2, previous: 26.388802, now: 26.514306\nid: 4, state: 0, kind: 0, previous: 26.514306, now: 27.803678\nid: 4, state: 1, kind: 2, previous: 27.803678, now: 28.437418\nid: 4, state: 0, kind: 4, previous: 28.437418, now: 31.000000\n#+end_example\n\n*** Limitations of the in-line approach\n\nOne limitation for the in-line code is that common random numbers, which are manipulated in C++ and use R's random number functions, are *not* available. Common random numbers can be used in a package, which is used by the [[https://github.com/mclements/prostata][prostata]] package.\n\n\n** Extensive use case\nFor more advance use of the microsimulation framework, please have a\nlook at our prostate cancer natural history model:\n\n[[https://github.com/mclements/prostata]]\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmclements%2Fmicrosimulation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmclements%2Fmicrosimulation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmclements%2Fmicrosimulation/lists"}