particleMetropolisHastings {pmhtutorial} | R Documentation |
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
particleMetropolisHastings(y, initialPhi, sigmav, sigmae, noParticles,
initialState, noIterations, stepSize)
Arguments
y |
Observations from the model for |
initialPhi |
The mean of the log-volatility process |
sigmav |
The standard deviation of the state process |
sigmae |
The standard deviation of the observation process
|
noParticles |
The number of particles to use in the filter. |
initialState |
The inital state. |
noIterations |
The number of iterations in the PMH algorithm. |
stepSize |
The standard deviation of the Gaussian random walk proposal
for |
Value
The trace of the Markov chain exploring the marginal posterior for
\phi
.
Note
See Section 4 in the reference for more details.
Author(s)
Johan Dahlin uni@johandahlin.com
References
Dahlin, J. & Schon, T. B. "Getting Started with Particle Metropolis-Hastings for Inference in Nonlinear Dynamical Models." Journal of Statistical Software, Code Snippets, 88(2): 1–41, 2019.
Examples
# Generates 100 observations from a linear state space model with
# (phi, sigma_e, sigma_v) = (0.5, 1.0, 0.1) and zero initial state.
theta <- c(0.5, 1.0, 0.1)
d <- generateData(theta, noObservations=100, initialState=0.0)
# Estimate the marginal posterior for phi
pmhOutput <- particleMetropolisHastings(d$y,
initialPhi=0.1, sigmav=1.0, sigmae=0.1, noParticles=50,
initialState=0.0, noIterations=1000, stepSize=0.10)
# Plot the estimate
nbins <- floor(sqrt(1000))
par(mfrow=c(1, 1))
hist(pmhOutput, breaks=nbins, main="", xlab=expression(phi),
ylab="marginal posterior", freq=FALSE, col="#7570B3")