##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