Session Ready
Exercise

Preparing data for space-time clustering

To do a space-time clustering test with stmctest() from the splancs package, you first need to convert parts of your ppp object. Functions in splancs tend to use matrix data instead of data frames.

To run stmctest() you need to set up

  • event locations
  • event times
  • region polygon
  • time limits
  • the time and space ranges for analysis.
Instructions
100 XP

The sasq object is loaded and the spatstat and splancs packages are ready for use.

  • Get a matrix of event coordinates, assigning to sasq_xy.
    • Extract the coordinates as a data frame using coords().
    • Convert this to a matrix with two columns.
  • Check the dimensions of sasq_xy.
  • Get a vector of event dates, assigning to sasq_t.
    • Extract the marks() of the sasq object.
    • Get the date element from this object.
  • Get a matrix describing the region polygon, assigning to sasq_poly.
    • Extract the Window() of the sasq object.
    • Convert this to a data frame with as.data.frame().
    • Convert this to a matrix.
  • Calculate the limits for the time axis.
    • Use range() on sasq_t to get the time range.
    • Add c(-1, 1) to extend the range by a day at each end.
  • Create a vector s of distances for the spatial scales of the analysis.
    • The numbers passed to seq() should be in metres.
  • Create a vector tm of time periods for the temporal scales of the analysis.
    • The numbers passed to seq() should be in days.