README.md

R interface to the SSM library

SSM is a C library to perform inference for time series analysis with State Space Models, like playing with duplo blocks. ssminr is a R package that provides an interface to SSM.

Installation

Before installing ssminr, make sure you have installed the SSM library by following these instructions. Note that SSM only works on Unix machines. If you run Windows, you will need to set up a virtual machine.

Assuming that SSM and R are installed on your machine, the easiest way to install ssminr is to use the devtools package:

# install.packages("devtools")
library(devtools)
install_github("StateSpaceModels/ssminr")

To work with ssminr: fire up R, and type

library(ssminr)

Before compiling your model

ssminr compiles your model by calling SSM from your R session using the function system(). As such, when compilating, SSM asks R where to find the header files as well as the librairy dependencies needed.

Outside of R, these information are generally stored in the environment variables CPATH (path to header files) and LIBRARY_PATH (path to librairy dependencies). You can check this in your terminal by typing:

echo $CPATH
echo $LIBRARY_PATH

If these environment variables don't exist it's probably a good idea to set them.

However, even if they exist in your system, the environment variables LIBRARY_PATH and CPATH might not be imported in your R session, which can result in a compilation failure. For instance, if SSM doesn't have the right path to the header files when called within R you will obtain the following error at compilation:

Building the model...
gcc  -std=gnu99 -O3 -DGSL_RANGE_CHECK_OFF -I /Users/ntncmch/.ssm/include -o Ht.o -c Ht.c
[91mFAIL[0m: In file included from Ht.c:19:
/Users/ntncmch/.ssm/include/ssm.h:36:10: fatal error: 'gsl/gsl_math.h' file not found
[91mFAIL[0m: #include <gsl/gsl_math.h>
         ^
[91mFAIL[0m: 1 error generated.
[91mFAIL[0m: make: *** [Ht.o] Error 1
[91mFAIL[0m: could not build the model (2).

If you experience a similar issue, check whether the environment variables are imported in your R session by typing

Sys.getenv("CPATH")
Sys.getenv("LIBRARY_PATH")

If one or both variables are missing or doesn't indicate the appropriate path, you will need to set them permanently in your ~/.Rprofile (read this post if you don't have one yet) by adding the following lines:

Sys.setenv(CPATH="/usr/local/include") # header path
Sys.setenv(LIBRARY_PATH="/usr/local/lib") # library path

Note that I have set the paths to my default ones and it might not be the same on your system.



StateSpaceModels/ssminr documentation built on Feb. 7, 2020, 8:20 p.m.