Learn R Programming

SpatioTemporal (version 1.1.9.1)

createSTdata: Construct STdata Object

Description

Creates a STdata object that can be used as input for createSTmodel. Names and dates are derived from the input data, either using predefined fields or rownames / colnames; for details see the sub-functions linked under the relevant Arguments.

Usage

createSTdata(obs, covars, SpatioTemporal = NULL, transform.obs = function(x)
  {     return(x) }, mean.0.ST = FALSE, n.basis = 0, extra.dates = NULL,
  ..., detrend = FALSE, region = NULL, method = NULL)

Arguments

obs

Either a data.frame with fields obs, date, ID giving obsevations, time-points and location names; or a matrix, e.g. output from createDataMatrix.

covars

matrix/data.frame of covariates; should include both geographic covariates and coordinates of all locations, see stCheckCovars.

SpatioTemporal

possible spatio-temporal covariate, see stCheckSTcovars.

transform.obs

function to apply to the observations, defaults to an identity transform. Possible options are log, sqrt, and exp.

mean.0.ST

Call removeSTcovarMean to produce a mean-zero spatio-temporal covariate?

n.basis

Number of temporal components in the smooth trends computed by updateTrend.STdata, if NULL no trend is computed (implies only a constant).

extra.dates

Additional dates for which smooth trends should be computed, used by updateTrend.STdata. If n.basis=NULL this will force n.basis=0; since the dates are stored in the trend..

...

Additional parameters passed to updateTrend.STdata.

detrend

Use detrendSTdata to remove a termporal trend from the observations; requires n.basis!=NULL.

region, method

Additional parameters passed to detrendSTdata.

Value

A STdata object with, some or all of, the following elements:

covars

Geographic covariates, locations and names of the observation locations (the later in covars$ID), createSTmodel will extract covariates (land use regressors), observations locations, etc from this data.frame when constructing the model specification.

trend

The temporal trends with one of the columns being named date, preferably of class Date providing the time alignment for the temporal trends.

obs

A data.frame with columns:

obs

The value of each observation.

date

The observations time, preferably of class Date.

ID

A character-class giving observation locations; should match elements in locations$ID.

SpatioTemporal

A 3D-array of spatio-temporal covariates, or NULL if no covariates exist. The array should be (number of timepoints) - by - (number of locations) - by - (number of covariates) and provide spatio-temporal covariates for all space-time locations, even unobserved ones (needed for prediction). The rownames of the array should represent dates/times and colnames should match the observation location names in covars$ID.

old.trend,fit.trend

Additional components added if the observations have been detrended, see detrendSTdata.

See Also

Other STdata methods: plot.STdata, print.STdata, print.summary.STdata, qqnorm.predCVSTmodel, scatterPlot.predCVSTmodel, summary.STdata

Other STdata functions: c.STmodel, createDataMatrix, createSTmodel, detrendSTdata, estimateBetaFields, removeSTcovarMean, updateTrend.STdata

Examples

Run this code
# NOT RUN {
##load the raw data
data(mesa.data.raw)

##extract observations and covariates
obs <- mesa.data.raw$obs
covars <- mesa.data.raw$X

##list with the spatio-temporal covariates
ST.list <- list(lax.conc.1500=mesa.data.raw$lax.conc.1500)

##create STdata object
mesa.data <- createSTdata(obs, covars, SpatioTemporal=ST.list)
print(mesa.data)

##create object with mean 0 spatio temporal covariate
mesa.data.2 <- createSTdata(obs, covars, SpatioTemporal=ST.list,
                            mean.0.ST=TRUE)
print(mesa.data.2)

##create object with mean 0 spatio temporal covariate, and
##trend with two components, and additional dates (every seventh day)
extra.dates <- seq(min(as.Date(rownames(obs))),
                   max(as.Date(rownames(obs))), by=7)
mesa.data.3 <- createSTdata(obs, covars, n.basis=2, extra.dates=extra.dates)
print(mesa.data.3)
# }

Run the code above in your browser using DataLab