Giter VIP home page Giter VIP logo

lssm's Introduction

lssm

This will be an R package for estimating and forecasting from linear state space models. The models are implemented in Stan using an implementation of Kalman filtering adapted from https://github.com/jrnold/ssmodels-in-stan.

lssm's People

Contributors

elray1 avatar serena-wang avatar

Watchers

James Cloos avatar  avatar  avatar

lssm's Issues

marginal distribution forecasts at horizons larger than 1

Modify predict function.

Output from stan is a 3d array of shape (p, p + 1, horizon). At each steps ahead h = 1, ..., horizon,
result[:, 1, h] is the point prediction for h steps ahead
result[:, 2:(p+1), h] is the covariance matrix for h steps ahead

Logic:

  • No change to existing code to get forecasts for 1 step ahead. This gives us 4 things:
    • a = E(alpha_{n + 1} | Y_n)
    • P = Cov(alpha_{n + 1} | Y_n)
    • d + Z*a = E(y_{n + 1} | Y_n)
    • F = Cov(y_{n + 1} | Y_n) = ZPZ' + H = to_symmetric_matrix(quad_form(P, Z') + H)
  • if horizon > 1, for loop from h = 2 to horizon.
    • E[alpha_{n + h} | Y_n] = E[c + T \alpha_{n + h - 1} + R eta_{t + h - 1} | Y_n] = c + T a_{n + h - 1}. Update a = c + T a
    • Cov(alpha_{n + h} | Y_n) = Cov(c + T \alpha_{n + h - 1} + R eta_{t + h - 1} | Y_n) = TPT' + RQR'
    • E(y_{n + h} | Y_n) = E(d + Z alpha_{n + h} + epsilon_{n + h}) = d + Z*a
    • Cov(y_{n + h} | Y_n) = Cov(d + Z alpha_{n + h} + epsilon_{n + h}) = ZPZ' + H = to_symmetric_matrix(quad_form(P, Z') + H)

allow for an intercept in ARMA models

The intercept parameter will be a single real number. To handle this in the filtering, set up a column vector c of length m with first entry equal to the intercept parameter and all others 0.

estimation targeting a fixed number of steps ahead

in the model section of the stan file, rather than calculating the likelihood, calculate the log predictive density h steps after the last time point. Probably want to write a helper function to do this calculation.

Function:
lssm_constant_forecast_log_score (or similar)

Inputs:

  • LSSM matrices
  • observed data y
  • horizon h

Logic:

  • initialize return value = 0
  • for t in 1:(n - h):
    • update filtering up through time t
    • obtain mean and covariance of forecast distribution at time t + h
    • return value += log predictive density at time t + h evaluated at y[t + h]

Then in the model section of stan file, call
target += lssm_constant_forecast_log_score(...)

move stan files

SARIMA.stan, SARIMA_predict.stan, functions.stan to stan from stan_models

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.