Learn R Programming

SpatioTemporal (version 0.9.2)

CVresiduals.qqnorm: QQ-norm and Scatterplots for Data and Residual Analysis

Description

Does QQ-norm and scatterplots of observations or residuals from a cross-validation. The scatterplots are of observations against any reasonable covariate; examples of how todo scatter plots of observations against temporal smooths as well as geographic covariates are given.

Usage

CVresiduals.qqnorm(res, I.season =
    as.factor(rep("obs", length(res))), I.type = NA,
    main = "All Data", norm = FALSE, legend = TRUE, ...) 

CVresiduals.scatter(res, LUR, I.season = as.factor(rep("obs",length(res))), I.type = NA, xlab = "", main = "All Data", legend = TRUE, df = 10, ...)

Arguments

res
Vector of observations or residuals to plot. Could be one of mesa.data$obs$obs, mesa.data.model$obs$obs, predCV$pred.obs[,"pred"], statsCV$res, or statsCV$res.norm. Here predCV
LUR
A vector of land-use-regressors or other variable of interest against which to plot the residuals. Can be obtained from mesa.data.model as, e.g. mesa.data.model$X[[1]][mesa.data.model
I.season
A vector of factors with the same length as res. The factors are used to colour code the points in the plots. The default, with only one factor, gives the same colour to all points.
I.type
A vector of characters or factors with the same length as res. The factors are used to produce one plot with all the data and then subsequent plots including only data of one type.

Each of these plots are still colour coded accor

xlab
Name on the x-axis, typically the name of the LUR component against which the data is being plotted.
main
Title of the plots.
norm
If TRUE assumes standardised data/residuals (i.e. Gaussian with mean=0 and var=1) and adds abline(0,1) to the qqnorm-plot, in addition to
legend
If TRUE add a legend describing the colour coding due to I.season in the lower right hand corner.
df
Desired equivalent number of degrees of freedom for the fitted smooth spline, see smooth.spline.
...
Arguments passed on to the plotting function (qqnorm or plot).

Value

  • Does not return anything.

encoding

latin1

See Also

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

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

Examples

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

##create a vector dividing data into four seasons
I.season <- matrix(NA,length(mesa.data.model$obs$date),1)
I.season[months(mesa.data.model$obs$date) %in%
         c("December","January","February"),1] <- "DJF"
I.season[months(mesa.data.model$obs$date) %in%
         c("March","April","May"),1] <- "MAM"
I.season[months(mesa.data.model$obs$date) %in%
         c("June","July","August"),1] <- "JJA"
I.season[months(mesa.data.model$obs$date) %in%
         c("September","October","November"),1] <- "SON"
I.season <- factor(I.season,levels=c("DJF","MAM","JJA","SON"))

##create a vector dividing data into type (AQS or FIXED)
I.type <- as.character(mesa.data.model$location$type[
                       mesa.data.model$obs$idx])

##qq-plot of the observations
par(mfrow=c(2,2),mar=c(2,2,2,.5),mgp=c(1.7,.6,0),pty="s")
CVresiduals.qqnorm(mesa.data.model$obs$obs, I.season, I.type)

##scatter plot of the observations against some of the LUR-covariates
LUR <- mesa.data.model$X[[1]][mesa.data.model$obs$idx,]

par(mfrow=c(2,3),mar=c(3,2.5,2,.5),mgp=c(1.7,.6,0),pty="s")
##i=1 is the constant LUR, not very interesting
for(i in 2:4)
  CVresiduals.scatter(mesa.data.model$obs$obs, LUR[,i], I.season,
                      xlab = colnames(LUR)[i])
##and against the temporal trends
for(i in 2:3)
  CVresiduals.scatter(mesa.data.model$obs$obs, mesa.data.model$F[,i],
                      I.season, xlab = colnames(mesa.data.model$F)[i])

Run the code above in your browser using DataLab