Learn R Programming

SpatioTemporal (version 0.9.2)

predictNaive: Naive Temporal Predictions

Description

Computes naive predictions that are based on a few sites. These predictions can then be used, e.g. in summaryStatsCV, to evaluate how much better the spatial-temporal model performs compared to simple (temporal) predictions.

Usage

predictNaive(mesa.data.model, location = NULL, type = NULL)

Arguments

mesa.data.model
location
List of locations on which to base the naive predictions.
type
The type of sites to base the predictions on, uses the (optional) field mesa.data.model$location$type.

Value

  • locationsA character vector with the locations used for the naive predictions.
  • predA (number of observations) - by - (4) matrix containing the four naive predictions described under details above.

encoding

latin1

Details

The function requires one of location and type to be specified, if both are given location will be used over type. If only type is given then all locations such that as.character(mesa.data.model$location$type) %in% type will be used.

Given a set of locations the function computes 4 sets of naive prediction for all observations in mesa.data.model$obs$obs. The compute predictions are: [object Object],[object Object],[object Object],[object Object]

See Also

See createCV and estimateCV for cross-validation set-up and estimation.

For computing CV statistics, see also compute.ltaCV, and for further illustration see plotCV, CVresiduals.qqnorm, and summaryStatsCV.

Examples

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

##naive predictions based on either AQS
pred.aqs <- predictNaive(mesa.data.model, type="AQS")
##or FIXED sites
pred.fixed <- predictNaive(mesa.data.model, type="FIXED")

##plot the predictions - The two cases that are constant in space
par(mfcol=c(3,1), mar=c(4.5,4.5,1,.5))
##observations as a function of date
plot(mesa.data.model$obs$date, mesa.data.model$obs$obs,
     col=mesa.data.model$obs$idx, pch=19, cex=.25,
     xlab="Date", ylab="observations")
##Add the predictions based on the smooth fitted to all sites
lines(mesa.data.model$obs$date,
      pred.aqs$pred[,"smooth.fixed"], col=1)
lines(mesa.data.model$obs$date,
      pred.fixed$pred[,"smooth.fixed"], col=2)

plot(mesa.data.model$obs$date, mesa.data.model$obs$obs,
     col=mesa.data.model$obs$idx, pch=19, cex=.25,
     xlab="Date", ylab="observations")
##Add predictions based on the temporal average
lines(mesa.data.model$obs$date,
      pred.aqs$pred[,"avg.fixed"], col=1)
lines(mesa.data.model$obs$date,
      pred.fixed$pred[,"avg.fixed"], col=2)

##plot the predictions - One of the cases that vary in space
##first extract a data matrix
D <- create.data.matrix(date=mesa.data.model$obs$date,
    obs=pred.aqs$pred[,"smooth.closest.fixed"],
    ID=mesa.data.model$obs$ID)

##observations as a function of date
##(only five sites for clarity)
IND <- (mesa.data.model$obs$idx %in% c(1:5))
plot(mesa.data.model$obs$date[IND], mesa.data.model$obs$obs[IND],
     col=mesa.data.model$obs$idx[IND], pch=19, cex=.25,
     xlab="Date", ylab="observations")
##Add the predictions based on the smooth
##fitted to the closest site
for(i in 1:5)
  lines(as.Date(rownames(D)), D[,mesa.data.model$location$ID[i]],
        col=i)

Run the code above in your browser using DataLab