Code Monkey home page Code Monkey logo

pmh-tutorial-rpkg's Introduction

pmh-tutorial-rpkg

This package provides minimal working examples for implementing the particle Metropolis-Hastings (PMH) algorithm for parameter inference in non-linear state space models. The package accompanies the tutorial:

J. Dahlin and T. B. Schön, Getting started with particle Metropolis-Hastings for inference in nonlinear models. Journal of Statistical Software, Code Snippets, Volume 88, Number 2, pp. 1-41, Foundation for Open Access Statistics, 2019.

The tutorial is available as an open access publication from Journal of Statistical Software. Additional standalone code is provided for Python and MATLAB in the GitHub repository pmh-tutorial. This repository also contains R code, which is almost identical to the code provided in the package.

Usage

The main functions of the package are the five examples connected to the tutorial:

  • example1_lgss() State estimation in a LGSS model using the KM and a fully-adapted PF (faPF). The code is discussed in Section 3.1 and the results are presented in Section 3.2 as Figure 4 and Table 1.

  • example2_lgss() Parameter estimation of one parameter in the LGSS model using PMH with the faPF as the likelihood estimator. The code is discussed in Section 4.1 and the results are presented in Section 4.2 as Figure 5.

  • example3_sv() Parameter estimation of three parameters in the SV model using PMH with the bootstrap PF as the likelihood estimator. The code is discussed in Section 5.1 and the results are presented in Section 5.2 as Figure 6. The code takes about an hour to run.

  • example4_sv() Modified version of the code in example3-sv.R to make use of a better tailored parameter proposal. The details are discussed in Section 6.3.2 and the results are presented in the same section as Figures 7 and 8. Note that the only difference in the code is that the variable stepSize is changed.

  • example5_sv() Modified version of the code in example3-sv.R to make use of another parameterisation of the model and a better tailored parameter proposal. The details are discussed in Section 6.3.3 and the results are presented in the same section. Note that the differences in the code is the use of another implementation of PMH ant that the variable stepSize is changed.

Simple example

The examples can be executed by e.g.

example2_lgss()

which will recreate on of the plots in the aforementioned tutorial. See the reference for more background and details.

How do I get it?

The package is available through CRAN and can be installed by

install.packages("pmhtutorial")

or directly from GitHub by

install.packages("devtools")
devtools::install_github("compops/pmh-tutorial-rpkg/package")

or downloaded the latest release as a binary package.

Dependencies

The package requires Quandl and mvtnorm to be able to download financial data from the Internet and to generate random variables from the multivariate Gaussian distribution. These can be installed by executing

install.packages(c("Quandl", "mvtnorm"))

in the R console if it is not installed at the same time as this package.

How to build the package (notes to the maintainer)

Clone the repo from GitHub. In Rstudio, switch the working directory to package, then run (use devtools::check(run_dont_test=TRUE) to check all the example which takes a looong time)

install.packages(c("devtools", "Quandl", "mvtnorm"))
library(devtools)
devtools::document()
devtools::check(manual=TRUE)
devtools::check_win_devel()
devtools::check_win_release()
devtools::build()

An e-mail will be received after 10-20 mins with the result of the rest run on Windows. Also, install and check the package on your local computer. Especially, the LaTeX renderings and similar can be broken.

devtools::install()

If everything is fine and all the tests are passed then submit the new release to CRAN by

devtools::check_rhub()
devtools::release()

pmh-tutorial-rpkg's People

Contributors

compops avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pmh-tutorial-rpkg's Issues

Forecasting strength - MSE metric

Hi @compops !
I hope you're well.
I am looking at using the matlab code for a university project, located at -

https://github.com/compops/pmh-tutorial

I am just wondering, my understanding of state space models is that their accuracy can be determined by the mean squared error. However when I run your code, Im not sure how the forecast accuracy is measured. Is it split into test and train sets, then a metric is determined?
What metric is used to measure the forecast accuracy of the state space model?

Many thanks for your help,
Best,
Andrew

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.