Wayne's Github Page

A place to learn about statistics

Homework3 - Practice with Kalman Filters

Goals

The purpose of this homework is to give you some exercise with applying Kalman Filters on the spatio-temporal data used in project 2.

Some basics on GPS:

Please show ALL code for this assignment.

Question 0 Familiarizing yourself with the data

On Canvas, you can find the dataset gps.zip but we will focus on a single file for this assignment. Please load the file 20200826131614.geojson which should be read like a usual JSON file.

Question 1: The Dynamic Linear Model

Recall the generic dynmaic linear model which describes the relatinoship between the observed data and the underlying state: \(Y_t = F_t \theta_t + v_t\) and the relationship between the states at different times: \(\theta_t = G_t \theta_{t-1} + w_t\)

For this assignment, you should treat \(Y_t\) as your noisy measured position at time \(t\) where \(\theta_t\) is your true position and speed at time \(t\), i.e. $\theta_t$ would be a 4 dimension vector with your 2 dimension true position information along with your 2 dimensional velocity. This description already imposes restrictions on what \(F_t\) and \(G_t\) can be. Let \(Y_t=\begin{bmatrix} X_t \\ Z_t \end{bmatrix}\) be a 2 by 1 vector with the noisy position data in 2 dimensions. If \(\theta_t = \begin{bmatrix} \mu_{x, t} \\ \mu_{z, t} \\ \nu_{x, t} \\ \nu_{z, t}\end{bmatrix}\) is a 4 by 1 vector with the true position and velocity.

Question 2: Computing DLMs with Projections

Unfortunately, degrees in longitude and latitude do not translate into distances properly, e.g. 1 degree in latitude is different from 1 degree in longitude in terms of absolute distance. To remedy this, we will project the data into UTM coordinates where the distances between UTM coordinates are meters.

To do so, we need the libraries sp and rgdal. Please install these in a special environment isolated from your other classes. The spatial library gdal (necessary dependency for rgdal) is notorious for breaking people’s computing environments if you’re not careful. The following code should help you convert longitude/latitude coordinates into UTM coordinates. Sadly, we will not go into details of projections for this class.

library(sp)
library(rgdal)
# This following step is similar to transforming time stamps like "2020-01-25" into a time object
spat_df <- SpatialPointsDataFrame(coords=df[, c("longitude", "latitude")],
                                  data=df['time_stamp'],   # This needs to be a data frame
                                  proj4string=CRS("+proj=lonlat +datum=WGS84"))
# This step converts the longitude/latitude -> UTM
utm_df <- spTransform(spat_df, CRSobj = "+proj=utm +zone=12 +datum=WGS84")
utm_coords <- coordinates(utm_df)

Question 3: Final Project Check-in