Learn R Programming

SpatioTemporal (version 1.1.2)

createDataMatrix: Create a Data Matrix

Description

Creates a data matrix from a STdata/STmodel object, e.g. mesa.data or mesa.model. Missing observations are marked as NA.

Usage

createDataMatrix(STdata = NULL, obs = STdata$obs$obs,
    date = STdata$obs$date, ID = STdata$obs$ID,
    subset = NULL)

Arguments

STdata
A STdata/STmodel object containing observations, see mesa.data. Use either this or the obs, date, and ID inputs.
obs
A vector of observations.
date
A vector of observation times.
ID
A vector of observation locations.
subset
A subset of locations to extract the data matrix for. A warning is given for each name not found in ID.

Value

  • Returns a matrix with dimensions (number of timepoints)-by-(number of locations). Row and column names of the matrix are taken as ID and sort(unique(date)) respectively.

See Also

Other data matrix: mesa.data.raw, SVDmiss, SVDsmooth, SVDsmoothCV

Other STdata functions: createSTdata, createSTmodel, c.STmodel, detrendSTdata, removeSTcovarMean, updateSTdataTrend

Other STmodel functions: createCV, createSTmodel, dropObservations, loglikeST, loglikeSTdim, loglikeSTnaive, predictNaive, processLocation, processLUR, processST, updateCovf

Examples

Run this code
##load the data
data(mesa.data)

##create a data matrix
M1 <- createDataMatrix(mesa.data)
dim(M1)
head(M1)

##create data matrix for only a few locations
M2 <- createDataMatrix(mesa.data, subset =
                         c("60370002","60370016","60370113","60371002",
                           "60371103","60371201","L001","L002"))
dim(M2)
head(M2)
if( (dim(M1)[1]!=dim(mesa.data$trend)[1]) ||
     (dim(M1)[2]!=dim(mesa.data$covars)[1]) ){
    stop("createDataMatrix: dimension missmatch - M1")
  }
  if( (dim(M2)[1]!=dim(mesa.data$trend)[1]) || (dim(M2)[2]!=8) ){
    stop("createDataMatrix: dimension missmatch - M2")
  }
  if( max(abs(M1[,colnames(M2)]-M2),na.rm=TRUE) > 1e-13 ){
    stop("createDataMatrix: M1!=M2")
  }

Run the code above in your browser using DataLab