

    \filetitle{filter}{Kalman smoother and estimator of out-of-likelihood parameters}{model/filter}

	\paragraph{Syntax}
 
 \begin{verbatim}
 [M,OUTP,V,DELTA,PE] = filter(M,INP,RANGE,...)
 [M,OUTP,V,DELTA,PE] = filter(M,INP,RANGE,J,...)
 \end{verbatim}
 \paragraph{Input arguments}
 
 \begin{itemize}
 \item
   \texttt{M} {[} model {]} - Solved model object.
 \item
   \texttt{INP} {[} struct \textbar{} cell {]} - Input database or
   datapack from which the measurement variables will be taken.
 \item
   \texttt{RANGE} {[} numeric {]} - Filter date range.
 \item
   \texttt{J} {[} struct {]} - Database with tunes on the mean of shocks
   and/or time-varying std devs of shocks.
 \end{itemize}
 \paragraph{Output arguments}
 
 \begin{itemize}
 \item
   \texttt{M} {[} model {]} - Model object with updates of std devs (if
   \texttt{'relative='} is true) and/or updates of out-of-likelihood
   parameters (if \texttt{'outoflik='} is non-empty).
 \item
   \texttt{OUTP} {[} struct \textbar{} cell {]} - Output struct with
   smoother or prediction data.
 \item
   \texttt{V} {[} numeric {]} - Estimated variance scale factor if the
   \texttt{'relative='} options is true; otherwise \texttt{V} is 1.
 \item
   \texttt{DELTA} {[} struct {]} - Database with estimates of
   out-of-likelihood parameters.
 \item
   \texttt{PE} {[} struct {]} - Database with prediction errors for
   measurement variables.
 \end{itemize}
 \paragraph{Options}
 
 \begin{itemize}
 \item
   \texttt{'ahead='} {[} numeric \textbar{} \emph{\texttt{1}} {]} -
   Predictions will be computed this number of period ahead.
 \item
   \texttt{'deviation='} {[} \texttt{true} \textbar{}
   \emph{\texttt{false}} {]} - Treat input and output data as deviations
   from balanced-growth path.
 \item
   \texttt{'dtrends='} {[} \emph{`auto'} \textbar{} \texttt{true}
   \textbar{} \texttt{false} {]} - Measurement data contain deterministic
   trends.
 \item
   \texttt{'data='} {[} \texttt{'predict'} \textbar{}
   \emph{\texttt{'smooth'}} \textbar{} \texttt{'predict,smooth'} {]} -
   Return smoother data or prediction data or both.
 \item
   \texttt{'exclude='} {[} cellstr \textbar{} \emph{empty} {]} - List of
   measurement variables that will be excluded from the likelihood
   function.
 \item
   \texttt{'initCond='} {[} \texttt{'fixed'} \textbar{}
   \texttt{'optimal'} \textbar{} \emph{\texttt{'stochastic'}} \textbar{}
   struct {]} - Method or data to initialise the Kalman filter.
 \item
   \texttt{'lastSmooth='} {[} numeric \textbar{} \emph{\texttt{Inf}} {]}
   - Last date up to which to smooth data backward from the end of the
   range; if \texttt{Inf} smoother will run on the entire range.
 \item
   \texttt{'meanOnly='} {[} \texttt{true} \textbar{}
   \emph{\texttt{false}} {]} - Return a plain database with mean data
   only.
 \item
   \texttt{'outOfLik='} {[} cellstr \textbar{} empty {]} - List of
   parameters in deterministic trends that will be estimated by
   concentrating them out of the likelihood function.
 \item
   \texttt{'objective='} {[} \emph{\texttt{'-loglik'}} \textbar{}
   \texttt{'prederr'} {]} - Objective function computed; can be either
   minus the log likelihood function or weighted sum of prediction
   errors.
 \item
   \texttt{'objRange='} {[} numeric \textbar{} \emph{\texttt{Inf}} {]} -
   The objective function will be computed on this subrange only;
   \texttt{Inf} means the entire filter range.
 \item
   \texttt{'precision='} {[} \emph{\texttt{'double'}} \textbar{}
   \texttt{'single'} {]} - Numeric precision to which output data will be
   stored; all calculations themselves always run to double precision.
 \item
   \texttt{'rollback='} {[} numeric \textbar{} \emph{empty} {]} - Date up
   to which to roll back individual observations on measurement variables
   from the end of the sample.
 \item
   \texttt{'relative='} {[} \emph{\texttt{true}} \textbar{}
   \texttt{false} {]} - Std devs of shocks assigned in the model object
   will be treated as relative std devs, and a common variance scale
   factor will be estimated.
 \item
   \texttt{'returnMse='} {[} \emph{\texttt{true}} \textbar{}
   \texttt{false} {]} - Return MSE matrices for predetermined state
   variables; these can be used for settin up initial condition in
   subsequent call to another \texttt{filter} or \texttt{jforecast}.
 \item
   \texttt{'returnStd='} {[} \emph{\texttt{true}} \textbar{}
   \texttt{false} {]} - Return database with std devs of model variables.
 \item
   \texttt{'tolMse='} {[} numeric \textbar{} \emph{\texttt{0}} {]} -
   Tolerance under which two MSE matrices in two consecutive periods will
   be treated as equal, and the Kalman gain system will be re-used, not
   re-computed.
 \item
   \texttt{'weighting='} {[} numeric \textbar{} \emph{empty} {]} -
   Weighting vector or matrix for prediction errors when
   \texttt{'objective=' 'prederr'}; empty means prediction errors are
   weighted equally.
 \end{itemize}
 \paragraph{Options for models with non-linearised equations}
 
 \begin{itemize}
 \item
   \texttt{'nonlinearise='} {[} numeric \textbar{} \emph{\texttt{0}} {]}
   - If non-zero the prediction step in the Kalman filter will be run in
   an exact non-linear mode using the same technique as
   \url{model/simulate}.
 \item
   \texttt{'simulate='} {[} cell \textbar{} empty {]} - Options passed in
   to \texttt{simulate} when invoking the non-linear simulation in the
   prediction step; only used when \texttt{nonlinearise=} is greater than
   \texttt{0}.
 \end{itemize}
 \paragraph{Description}
 
 The \texttt{'ahead='} and \texttt{'rollback='} options cannot be
 combined with one another, or with multiple data sets, or with multiple
 parameterisations.
 
 \paragraph{Example}


