Motivation
A potentially attractive approach to modelling complex health systems is to begin with a relatively simple computational model and to progressively extend its scope and sophistication. Such an approach could be described as “modular” if it is possible to readily combine multiple discrete modelling projects (potentially developed by different modelling teams) that each independently describe distinct aspects of the system being modelled.
Implementation
The ready4 facilitates modular model development by
supplying a template module that enables model developers to avail of
the encapsulation
and inheritance features of Object Oriented Programming (OOP). The
ready4 framework uses two of
R’s systems for implementing OOP - S3 and S4. An in-depth explanation of
R’s different class system is beyond the scope of this article, but is
explored in Hadley Wickham’s
Advanced R handbook. However, it is useful to know some very high
level information about S3 and S4 classes:
S4 classes are frequently said to be “formal”, “strict” or “rigorous”. The elements of an S4 class are called slots and the type of data that each slot is allowed to contain is specified in the class definition. An S4 class can be comprised of slots that contain different types of data (e.g. a slot that contains a character vector and another slot that contains tabular data).
S3 classes are often described as “simple”, “informal” and “flexible”. S3 objects attach an attribute label to base type objects (e.g. a character vector, a data.frame, a list), which in turn is used to work out what methods should be applied to the class.
Use
ready4 Model Modules
As we use the term, a “model module” is comprised of both a
data-structure (an S4 class) and the algorithms (or “methods”) that are
associated with that data-structure. Model modules can be created from a
template - the ready4 package’s Ready4 class.
Ready4 is a virtual class - it cannot be used directly to
create objects. However, it can be used to create other classes that
inherit the syntax defined for Ready4.
In the below example, we create a new inheriting class
(ExampleClass) from Ready4 using the following
command.
ExampleClass <- setClass(
"Ready4Object",
contains = "Ready4",
slots = c(data = "character")
)The new class we have created can be used to create objects, for
example X.
X <- ExampleClass(data = "Some data")
X@data## [1] "Some data"
The Ready4 class is therefore not intended to be called
directly. Instead, the purpose of Ready4 is to be the
parent class of model modules developed with the ready4 framework.
Prototype tools for authoring modules from this template are described
here.
