Learn R Programming

pmhtutorial (version 1.0.0)

pmh: Particle Metropolis-Hastings algorithm for a linear Gaussian state space model

Description

Estimates the parameter posterior for \(phi\) a linear Gaussian state space model of the form \( x_{t} = \phi x_{t-1} + \sigma_v v_t \) and \( y_t = x_t + \sigma_e e_t \), where \(v_t\) and \(e_t\) denote independent standard Gaussian random variables, i.e.\(N(0,1)\).

Usage

pmh(y, initPar, sigmav, sigmae, nPart, T, x0, nIter, stepSize)

Arguments

y

Observations from the model for \(t=1,...,T\).

initPar

The mean of the log-volatility process \(\mu\).

sigmav

The standard deviation of the state process \(\sigma_v\).

sigmae

The standard deviation of the observation process \(\sigma_e\).

nPart

The number of particles to use in the filter.

T

The number of observations.

x0

The inital state.

nIter

The number of iterations in the PMH algorithm.

stepSize

The standard deviation of the Gaussian random walk proposal for \(\phi\).

Value

The trace of the Markov chain exploring the marginal posterior for \(\phi\).

References

Dahlin, J. & Schoen, T. B. "Getting started with particle Metropolis-Hastings for inference in nonlinear dynamical models." pre-print, arXiv:1511.01707, 2015.

Examples

Run this code
# NOT RUN {
# Use a short run when testing the code on CRAN
# Set nIter manually if running on local computer, 
# nIter=1000 is usually enough
if(nchar(Sys.getenv("LONG_TEST")) != 0) {
  nIter=7500
} else {
  nIter=100
}
## Generates T=500 observations from a linear state space model with
## ( phi, sigma_e, sigma_v ) = ( 0.5, 1.0, 0.1 ) and zero initial state.

d <- generateData(phi=0.5, sigmav=1.0, sigmae=0.1, T=500, x0=0.0) 

## Estimate the marginal posterior for phi
res   <- pmh(d$y, initPar=0.1, sigmav=1.0, sigmae=0.1, nPart=50, T=500, 
             x0=0.0, nIter, stepSize=0.10)

## Plot the estimate
par(mfrow=c(1,1))
hist(res, main="", xlab=expression(phi), 
     ylab="marginal posterior", freq=FALSE)

# }

Run the code above in your browser using DataLab