• Simulating Continuous-Time Markov Chains with simmer (part 2)

    In part one, we simulated a simple CTMC. Now, let us complicate things a bit. Remember the example problem there:

    A gas station has a single pump and no space for vehicles to wait (if a vehicle arrives and the pump is not available, it leaves). Vehicles arrive to the gas station following a Poisson process with a rate of $\lambda=3/20$ vehicles per minute, of which 75% are cars and 25% are motorcycles. The refuelling time can be modelled with an exponential random variable with mean 8 minutes for cars and 3 minutes for motorcycles, that is, the services rates are $\mu_\mathrm{c}=1/8$ cars and $\mu_\mathrm{m}=1/3$ motorcycles per minute respectively (note that, in this context, $\mu$ is a rate, not a mean).

    Consider the previous example, but, this time, there is space for one motorcycle to wait while the pump is being used by another vehicle. In other words, cars see a queue size of 0 and motorcycles see a queue size of 1.

    The new Markov chain is the following:

    where the states car+ and m/c+ represent car + waiting motorcycle and motorcycle + waiting motorcycle respectively.

    With $p$ the steady state distribution, the average number of vehicles in the system is given by

    Continue reading →

  • Simulating Continuous-Time Markov Chains with simmer (part 1)

    In the previous post, we gave you some insights about the simulation of simple birth-death processes with simmer. The extension of such a methodology for more complex queueing networks is immediate and was left as an exercise for the reader.

    Similarly, today we are going to explore more features of simmer with a simple Continuous-Time Markov Chain (CTMC) problem as an excuse. CTMCs are more general than birth-death processes (those are special cases of CTMCs) and may push the limits of our simulator. So let’s start.

    Continue reading →

  • Simulating queueing systems with simmer

    We are very pleased to announce that a new release of simmer, the Discrete-Event Simulator for R, is on CRAN. There are quite a few changes and fixes, with the support of preemption as a star new feature. Check out the complete set of release notes here.

    Let’s simmer for a bit and see how this package can be used to simulate queueing systems in a very straightforward way.

    Continue reading →

  • simmer v3.1.1 released on CRAN

    Last week the latest version of simmer was released on CRAN: v3.1.1.

    This version allows adding attributes to arrivals (and basing decisions on their values).

    Also, the rollback activity was introduced, enabling you to roll back a trajectory with n steps.

    In addition, a new priority param for the seize() command was introduced. This allows ordering a resource queue based on the arrival’s seize priority.

    Check the vignettes on simmer’s CRAN page to get started.


    New features:

    • Add attributes to arrivals and new set_attribute activity (#16).
    • New rollback activity (#17 and #22).
    • Add priorities to resources’ queue (#20).

    Minor changes and fixes:

    • Performance improvements with Boost (1b654fd).
    • Fix arrivals’ timing issues (#24).
    • Nicer object printing (#26).
    • Return self visibly, instead of invisibly (#35).
    • Add at and from convenience functions (29cccd2 and 7cfdd90).
    • Some work on vignettes (#29).
    • Fix ggplot2 2.0.0 compatibility issues (#37).
  • Making an R based ML model accessible through a simple API

    Building an accurate machine learning (ML) model is a feat on its own. But once you’re there, you still need to find a way to make the model accessible to users. If you want to create a GUI for it, the obvious approach is going after shiny. However, often you don’t want a direct GUI for a ML model but you want to integrate the logic you’ve created into an existing (or new) application things become a bit more difficult.

    Let’s say you’ve created a robust ML model in R and explain the model to your in-house IT department, it is (currently) definitely not a given that they can easily integrate it. Be it either due to the technology used is unfamiliar to them or because they simply don’t have a in-depth knowledge on ML.

    Continue reading →

  • simmer 3.0.0 is on CRAN

    I’m very pleased to announce the first CRAN release of simmer. (https://cran.rstudio.com/web/packages/simmer/). This release has been realised thanks to the efforts made by Iñaki.

    To reiterate a bit, simmer is a discrete-event simulation (DES) package for R. It is the first R package that focuses on creating a robust DES framework for R. It provides a framework somewhat similar as e.g SimPy and SimJulia but is arguably written from a bit more of an applied angle.

    R might not be the most efficient language to implement a DES framework due to its method of memory allocation. Therefore, simmer implements a C++ backend by making use of Rcpp.

    Continue reading →

  • jug 0.1.0 on CRAN

    Jug is a package to allow you to easily create web APIs based on your R codestack.

    Documentation and examples can be found at: http://bart6114.github.io/jug/

    Continue reading →

  • Jug: Easily Create R APIs

    Jug stands for Just Unified Galloping. Okay, okay, it’s just a play on words coming from a Flask (Python) background.

    Jug is my attempt to create a simple small web framework that allows you to turn your (existing) R functions into an API. Having the wonderful httpuv package at my disposal made this very easy for me.

    So, how does this work?

    Let’s say I have the following function:

    say_hello_to<-function(name) paste("Hello", name)

    Sometimes you would be in a situation where you want to send a GET request to a server and let a function (let’s say the one above) return it’s result. Thus, I want to expose the above function to allow HTTP GET requests to acces it. Using Jug I could do something like this:

    jug() %>%
      gett("/", decorate(say_hello_to)) %>%
    Serving the jug at

    However, when I run this code and post a GET request to the URL, the following happens:

    $ curl
    ERROR: argument "name" is missing, with no default

    Obviously, because the function say_hello_to requires the parameter name. A second attempt has better results:

    $ curl
    Hello Bart

    Continue reading →

  • dimple charts for R

    dimple is a simple-to-use charting API powered by D3.js.

    Making use of the nice htmlwidgets package it only took a minimum amount of coding to make the dimple library available from R.

    You can find the dimple R package at github.com/Bart6114/dimple and some documentation and examples at: bart6114.github.io/dimple (can take a while to load). Using the package you can create static javascript-based graphs, but you can also use dimple charts in Shiny applications.


  • licorice: plot Likert-like data

    I wanted to create a nice visualization from a survey data set. I quickly stumbled upon the likert package (go check it out).

    I did however have some trouble getting it to work the way I wanted. Therefore I made a quick implementation of my own that you can install from GitHub: github.com/Bart6114/licorice (check out the GitHub README for more info).

    Below you can see an example plot. It is a basic ggplot2 object which you can add upon to your liking. The plot below has been themed using the ggthemr package.

  • infuser: a template engine for R

    Version 0.1 of infuser was just released on CRAN.

    infuser is a very basic templating engine. It allows you to replace parameters in character strings or text files with a given specified value.

    I would often include some SQL code in my R scripts so that I could make parameters in the SQL code variable. But I was always a bit hesitant on the cleanliness of this. It irked me so much that I finally wrote this very simple package. The infuse function allows me to read in a text file (or a character string for that matter) and infuse it with the requested values.

    Continue reading →

  • sparklines for R

    I’ve always liked the jQuery Sparklines library and today I had a use case for implementing these in one of my Rmarkdown reports.

    While it wouldn’t be too difficult to staticly include a javascript based chart, ideally I would simply want to dynamically generate the sparkline using values computed in R. Luckily we now have htmlwidgets for R. This library makes it stupidly simple to integrate javascript libraries in R code. It simply up to one who has a use case for integrating a javascript library with R to insert some glue code: and so sparklines was born.

    Continue reading →

  • scheduleR receives big update

    For the newcomers; scheduleR is a framework to deploy/schedule R tasks, reports and Shiny apps. The tool has an integrated logging and notification system to ease the maintenance of scheduled R related jobs.

    After a lot of refactoring the tasks have been separated into tasks (e.g. ETL scripts) and reports (rmarkdown). The back-end that handles the execution of R scripts has gotten a polish, as did the UI.

    Continue reading →

  • Compensation in artifical neural networks

    Last week I was at the succesful doctoral defence of Wouter on the role of the cerebellum while walking. During the questions, the topic of compensation came up: if a part of your neural system gets damaged can other parts (over time) take over some of its functionality? The answer is most probably yes, but only to some extent.

    Continue reading →

  • New blog

    %$*! my server crashed… Oh well, might as well take this opportunity to start with a fresh blog platform. I’ll be using Jekyll from now on.

    The texts of my posts have (mostly) been preserved, I will start recovering old posts in the coming days / weeks.

  • scheduleR: a web interface to schedule .R & .Rmd scripts

    This post has been transferred from another blog platform and could have dead links / incorrect lay-out.

    scheduleR is an attempt to create an intuitive interface for scheduling R and Rmarkdown scripts. Especially for the latter, I find the lack of a good scheduling, logging and notification tool the reason for why I don’t use Rmarkdown as much as I could for generating business report / dashboards.

    Continue reading →

  • Introducing simmer: Discrete Event Simulation for R

    This post has been transferred from another blog platform and could have dead links / incorrect lay-out.

    Please note: the syntax described here is no longer up-to-date, please refer to the readme at simmer’s GitHub page.

    The simmer package grew out of a personal need for a simple rapid development discrete event simulation (DES) framework. I work in the hospital sector and at times use a DES approach to simulate hospital processes / patient trajectories. DES can give you a quick look at process bottlenecks and test out the impact of alternative process set-ups.

    Continue reading →