Introduction to Kalman Filter Evaluation in R
As a data analyst or scientist working with dynamic systems, understanding the suitability of a fitted model is crucial for making informed decisions. In this article, we will explore how to calculate AIC (Akaike Information Criterion), BIC (Bayesian Information Criterion), and likelihoods of a fitted Kalman filter using the DSE function in R.
What is a Kalman Filter?
A Kalman filter is a mathematical algorithm that uses a series of measurements observed over time, containing noise, to estimate the state of an underlying system. It is widely used in various fields such as navigation, signal processing, and control systems. The Kalman filter consists of two main components: the prediction step and the correction step.
Theoretical Formulation
For illustrative purposes, let’s assume that our model is a random walk, defined by:
X(t) = X(t-1) + e(t) ~ N(0,1) Y(t) = X(t) + w(t) ~ N(0,1)
where X(t) represents the state at time t, e(t) is the process noise, and w(t) is the measurement noise.
Fitting a Kalman Filter in R
To fit a Kalman filter to our data, we use the dse package’s SS() function:
kalman.filter = dse::SS(
F = matrix(1,1,1), # state transition matrix
Q = matrix(1,1,1), # process noise covariance
H = matrix(1,1,1), # measurement matrix
R = matrix(1,1,1), # measurement noise covariance
z0 = matrix(0,1,1), # initial state estimate
P0 = matrix(0,1,1) # initial state covariance
)
Simulating the Kalman Filter
To simulate the Kalman filter, we use the simulate() function:
simulate.kalman.filter = simulate(kalman.filter, start = 1, freq = 1, sampleT = 100)
Evaluating Model Fit using Likelihoods and Information Criteria
To test the fit of our data to the model theoretical model in R, we use the informationTests() function from the dse package.
AIC (Akaike Information Criterion)
The AIC is a measure of the relative quality of two models. It penalizes for complexity by incorporating the number of parameters estimated in the model.
informationTests(kalman.filter)
This will return the AIC value for our fitted Kalman filter to the data.
BIC (Bayesian Information Criterion)
The BIC is similar to the AIC, but it also incorporates prior knowledge about the model parameters. It is considered more conservative than the AIC.
informationTests(kalman.filter)
This will return the BIC value for our fitted Kalman filter to the data.
Negative Log-Likelihood
The negative log-likelihood of a model is a measure of how well the model fits the observed data. It represents the logarithm of the probability density function of the model given the data.
informationTests(kalman.filter)
This will return the negative log-likelihood value for our fitted Kalman filter to the data.
Comparing Multiple Models
To compare two models, we can add the second model as a parameter to the informationTests() function:
informationTests(kalman.filter, test2)
This will tabulate the AIC, BIC, and likelihoods against one another for both models.
Conclusion
In this article, we explored how to calculate AIC, BIC, and likelihoods of a fitted Kalman filter using the DSE function in R. We covered the theoretical formulation, fitting a Kalman filter, simulating the Kalman filter, evaluating model fit using likelihoods and information criteria, and comparing multiple models. By following these steps, you can test the suitability of your fitted model and make informed decisions about its performance.
Additional Resources
For more information on the dse package and Kalman filters, please refer to the following resources:
Last modified on 2023-12-17