Learn R Programming

SpatioTemporal (version 0.9.2)

simulateMesaData: Simulate Data from the Spatio-Temporal Model

Description

Simulates data from the spatio-temporal model.

Usage

simulateMesaData(x, mesa.data.model, mesa.data = NA, rep = 1,
                 combine.data = FALSE)

Arguments

x
Parameters for which to simulate data. If only log-covariance parameters are given then the regression parameters are inferred by calling cond.expectation(x, mesa.data.model, only.pars=TRUE).
mesa.data.model
Data structure holding observations, and information regarding where to simulate observations. See mesa.data.model.
mesa.data
Data structure holding observations, observation locations, smooth temporal trends, geographic covariates and spatio-temporal covariates. This can be used to obtain simulated values at different times and or locations than specified by
rep
Number of field replicates to simulate.
combine.data
If TRUE will combine locations and covariates from mesa.data.model and mesa.data, but will use temporal trends from

Value

  • Returns a list containing:
  • paramParameters used to simulate the data.
  • BThe simulated beta fields in a (number of locations) - by - (number of temporal trends) - by - (number of replicates) array.
  • XThe simulated spatio-temporal fields in a (number of timepoints) - by - (number of locations) - by - (number of replicates) array. Row and column names indicate the time and locations for each observation.
  • obsA list with one element per replicate, containing the simulated observations extracted at space-time locations matching those in mesa.data.model$obs (or a sorted version of mesa.data.model$obs). Each element of the list is a data.frame with obs, date, idx, and ID fields. To replace the observations with the i:th simulated values do: mesa.data.model$obs <- obs[[i]].

encoding

latin1

Details

Data is simulated for the space-time locations in mesa.data.model and/or mesa.data, given the parameters in x. If only log-covariance parameters are given then the regression parameters are inferred using generalised least squares (GLS), as cond.expectation(x, mesa.data.model, only.pars=TRUE, type="p").

The space-time locations at which to simulate data are specified through mesa.data.model and/or mesa.data. If mesa.data=NA data will be simulated at all space-time locations given in mesa.data.model. If mesa.data!=NA two options exist:

  1. Ifcombine.data=FALSEdata will be simulated atonlythe space-time locations in mesa.data. Ifmesa.datadoes not have a smooth temporal trend, the trend in mesa.data.modelwill be used (with a warning).
  2. Ifcombine.data=TRUElocations and covariates from bothmesa.data.modelandmesa.dataare combined usingcombineMesaData. The smooth temporal trends are taken frommesa.data.modelwith trends inmesa.databeingignored. I.e. data is simulated at the combined set of locations inmesa.data.modelandmesa.data; atonlythe times specified inmesa.data.model$trend.
If the additional object mesa.data is given, mesa.data.model is used to specify the model (through the fields LUR.list and ST.Ind).

See Also

For estimation functions see fit.mesa.model, run.MCMC, and estimateCV.

For prediction see cond.expectation and predictCV

Examples

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

##Get estimated parameters
x <- mesa.data.res$par.est$res.best$par.all

##Simulate 5 replicates from these parameters
sim.data <- simulateMesaData(x, mesa.data.model, rep = 5)

##plot the simulated observations as a function of time
par(mfrow=c(2,2),mar=c(4,4,.5,.5))
plot(sim.data$obs[[1]]$date, sim.data$obs[[1]]$obs,
     type="n", ylab="obs", xlab="Date")
for(i in 1:5)
  points(sim.data$obs[[i]]$date, sim.data$obs[[i]]$obs, col=i)

##and the latent beta-fields
for(i in 1:3){
  plot(sim.data$B[,i,1], ylim=range(sim.data$B[,i,]), type="n",
       xlab="loc", ylab=paste("beta",colnames(sim.data$B)[i]))
  for(j in 1:5)
    points(sim.data$B[,i,j], col=j)
}

###########################################
## A case with some unobserved locations ##
###########################################
##keep only observations from the AQS sites
ID.AQS <- mesa.data$location$ID[mesa.data$location$type=="AQS"]
mesa.data$obs <- mesa.data$obs[mesa.data$obs$ID %in% ID.AQS,]

##create a model object, dropping unobserved locations.
mesa.data.model <- create.data.model(mesa.data,
    LUR = mesa.data.model$LUR.list, ST.Ind = mesa.data.model$ST.Ind)

##simulate some replicates for this object
sim.data.obs <- simulateMesaData(x, mesa.data.model)
sim.data.all <- simulateMesaData(x, mesa.data.model,
    mesa.data=mesa.data)
sim.data.comb <- simulateMesaData(x, mesa.data.model,
    mesa.data=mesa.data, combine.data = TRUE)

##The first simulated object now only contains the AQS sites
mesa.data.model$location$ID
colnames(sim.data.obs$X)

##while the other two contain all locations
colnames(sim.data.all$X)
colnames(sim.data.comb$X)
if( any(mesa.data.model$location$ID != colnames(sim.data.obs$X)) ){
  stop("simulateMesaData 1: Miss-match in simulated locations.")
}
if( any(colnames(sim.data.all$X) != colnames(sim.data.comb$X)) ){
  stop("simulateMesaData 2: Miss-match in simulated locations.")
}

Run the code above in your browser using DataLab