Learn R Programming

SMC (version 1.0)

auxiliaryParticleFilter: The auxiliary particle filtering algorithm

Description

Function for doing auxiliary particle filtering given the state equation (via generateNextStreamsFunc), the stream representative generation rule (via generateStreamRepsFunc), and the observation equation density (via logObsDensFunc).

Usage

auxiliaryParticleFilter(nStreams,                          
                        nPeriods,                          
                        dimPerPeriod,                      
                        generateStreamRepsFunc,            
                        generateNextStreamsFunc,            
                        logObsDensFunc,                    
                        resampCriterionFunc = NULL,  
                        resampFunc          = NULL, 
                        summaryFunc         = NULL,  
                        nMHSteps            = 0,     
                        MHUpdateFunc        = NULL,  
                        nStreamsPreResamp   = NULL,  
                        returnStreams       = FALSE, 
                        returnLogWeights    = FALSE, 
                        verboseLevel        = 0,     
                        ...)

Arguments

nStreams
integer $>$ 0.
nPeriods
integer $>$ 0.
dimPerPeriod
integer $>$ 0.
generateStreamRepsFunc
function of five arguments (currentPeriod, lag1Streams, lag1LogWeights, streamIndices, ...).
generateNextStreamsFunc
function of seven arguments (currentPeriod, lag1Streams, lag1LogWeights, streamIndices, streamReps, startingStreams, ...).
logObsDensFunc
function of three arguments (currentPeriod, currentStreams, ...).
resampCriterionFunc
function of four arguments (currentPeriod, currentStreams, currentLogWeights, ...).
resampFunc
function of four arguments (currentPeriod, currentStreams, currentLogWeights, ...).
summaryFunc
function of four arguments (currentPeriod, currentStreams, currentLogWeights, ...).
nMHSteps
integer $\ge$ 0.
MHUpdateFunc
function of six arguments (currentPeriod, nMHSteps, currentStreams, lag1Streams, lag1LogWeights, ...).
nStreamsPreResamp
integer $>$ 0.
returnStreams
logical.
returnLogWeights
logical.
verboseLevel
integer, a value $\ge$ 2 produces a lot of output.
...
optional arguments to be passed to generateStreamRepsFunc, generateNextStreamsFunc, logObsDensFunc, resampCriterionFunc, resampFunc, summaryFunc and MHUpdateFu

Value

  • This function returns a list with the following components:
  • drawsa list with the following components: summary, propUniqueStreamIds, streams, logWeights, acceptanceRates. See the section Note for more details.
  • nStreamsthe nStreams argument.
  • nPeriodsthe nPeriods argument.
  • dimPerPeriodthe dimPerPeriod argument.
  • nStreamsPreResampthe nStreamsPreResamp argument.
  • nMHStepsthe nMHSteps argument.
  • filterTypetype of the filter: auxiliaryParticleFilter.
  • timethe time taken by the run.

Warning

Using very small values ($\le$ 1e3) for nStreams might not give reliable results.

Details

We introduce the following terms, which will be used in the sections Required Function and Optional Function below:

[object Object],[object Object]

References

Michael K. Pitt and Meil Shephard (1999). Filtering via Simulation: Auxiloary Particle Filters. Journal of the American Statistical Association 94(446): 590-599.

See Also

particleFilter

Examples

Run this code
MSObj  <- MarkovSwitchingFuncGenerator(-2468)
smcObj <-
    with(MSObj,
     {
         auxiliaryParticleFilter(nStreams                = 5000,
                                 nPeriods                = nrow(yy),
                                 dimPerPeriod            = ncol(yy),
                                 generateStreamRepsFunc  = generateStreamRepsFunc,
                                 generateNextStreamsFunc = generateNextStreamsFunc,
                                 logObsDensFunc          = logObsDensFunc,
                                 returnStreams           = TRUE,
                                 returnLogWeights        = TRUE,
                                 verboseLevel            = 1)
     })
print(smcObj)
print(names(smcObj))
with(c(smcObj, MSObj),
 {
     par(mfcol = c(2, 1))
     plot(as.ts(yy),
          main     = expression('The data and the underlying regimes'),
          cex.main = 0.8,
          xlab     = 'period',
          ylab     = 'data and the regime means',
          cex.lab  = 0.8)
     lines(as.ts(mu), col = 2, lty = 2)
     plot(as.ts(draws$summary[1, ]),
          main     = expression('The underlying regimes and their estimates'),
          cex.main = 0.8,
          xlab     = 'period',
          ylab     = 'regime means',
          cex.lab  = 0.8)
     lines(as.ts(mu), col = 2, lty = 2)        
 })

MSObj  <- MarkovSwitchingFuncGenerator(-8642)
smcObj <-
    with(MSObj,
     {
         auxiliaryParticleFilter(nStreams                = 5000,
                                 nPeriods                = nrow(yy),
                                 dimPerPeriod            = ncol(yy),
                                 generateStreamRepsFunc  = generateStreamRepsFunc,
                                 generateNextStreamsFunc = generateNextStreamsFunc,
                                 logObsDensFunc          = logObsDensFunc,
                                 returnStreams           = TRUE,
                                 returnLogWeights        = TRUE,
                                 verboseLevel            = 1)
     })
print(smcObj)
print(names(smcObj))
with(c(smcObj, MSObj),
 {
     par(mfcol = c(2, 1))
     plot(as.ts(yy),
          main     = expression('The data and the underlying regimes'),
          cex.main = 0.8,
          xlab     = 'period',
          ylab     = 'data and the regime means',
          cex.lab  = 0.8)
     lines(as.ts(mu), col = 2, lty = 2)
     plot(as.ts(draws$summary[1, ]),
          main     = expression('The underlying regimes and their estimates'),
          cex.main = 0.8,
          xlab     = 'period',
          ylab     = 'regime means',
          cex.lab  = 0.8)
     lines(as.ts(mu), col = 2, lty = 2)        
 })

Run the code above in your browser using DataLab