Description Usage Arguments Details Value Author(s) See Also Examples
Creates a matrix that specifies cross-validation schemes.
1 2 3 |
STmodel |
Model object for which to determine cross-validation. |
groups |
Number of cross-validation groups, zero gives leave-one-out cross-validation. |
min.dist |
Minimum distance between locations for them to end up in
separate groups. Points closer than |
random |
If |
subset |
A subset of locations for which to define the cross-validation
setup. Only sites listed in |
option |
For internal MESA Air usage, see Details below. |
Icv.vector |
Attempt to return a vector instead of a matrix. If the same observation is in several groups a matrix will still be returned. |
The number of observations left out of each group can be rather uneven;
the main goal of createCV
is to create CV-groups such that the groups
contain roughly the same number of locations ignoring the number of
observations at each location. If there are large differences in the number
of observations at differnt locations one could use the subset
option
to create different CV-groupings for different types of locations. If
Icv.vector=FALSE
, the groups can then be combined as
I.final = I.1 | I.2 | I.3
.
The option
input determines which sites to include in the
cross-validation. Possible options are "all"
, "fixed"
,
"comco"
, "snapshot"
and "home"
.
Uses all available sites, possibly subset according to
subset
. The sites will be grouped with sites
seperated by less than min.dist
being put in the
same CV-group.
Uses only sites that have
STmodel$locations$type %in% c("AQS","FIXED")
.
Given the subsettting the sites will be grouped as for all
.
Uses only sites that have
STmodel$locations$type %in% c("HOME")
.
Given the subsettting the sites will be grouped as for all
.
Uses only sites that have
STmodel$locations$type %in% c("COMCO")
.
The sites will be grouped together if they are from the same road
gradient. The road gradients are grouped by studying the name of the
sites. With "?" denoting one or more letters and "#" denoting one or
more digits the names are expected to follow "?-?#?#", for random sites,
and "?-?#?#?" for the gradients (with all but the last letter being the
same for the entire gradient).
Return a vector, with each element giving the CV-group (as an
integer) of each observation; Or a (number or observations) - by -
(groups) logical matrix; each column defines a cross-validation set with
the TRUE
values marking the observations to be left out.
Johan Lindstrom
Other STmodel functions: createDataMatrix
,
createSTmodel
,
dropObservations
,
estimateBetaFields
,
loglikeSTdim
, loglikeST
,
predictNaive
, processLUR
,
processLocation
, updateCovf
,
updateTrend.STdata
Other cross-validation functions: computeLTA
,
dropObservations
,
estimateCV.STmodel
,
predictNaive
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | ##load the data
data(mesa.model)
##create a matrix with the CV-schemes
I.cv <- createCV(mesa.model, groups=10)
##number of observations in each CV-group
table(I.cv)
##Which sites belong to which groups?
ID.cv <- sapply(split(mesa.model$obs$ID, I.cv),unique)
print(ID.cv)
##Note that the sites with distance 0.084<min.dist
##are grouped together (in group 10).
mesa.model$D.beta[ID.cv[[10]], ID.cv[[10]]]
##Find out which location belongs to which cv group
I.col <- apply(sapply(ID.cv,function(x) mesa.model$locations$ID
%in% x), 1, function(x) if(sum(x)==1) which(x) else 0)
names(I.col) <- mesa.model$locations$ID
print(I.col)
##Plot the locations, colour coded by CV-grouping
plot(mesa.model$locations$long, mesa.model$locations$lat,
pch=23+floor(I.col/max(I.col)+.5), bg=I.col,
xlab="Longitude", ylab="Latitude")
###############################################################
## Using matrix representation of cross-validation structure ##
###############################################################
##create a matrix with the CV-schemes
I.cv <- createCV(mesa.model, groups=10, Icv.vector=FALSE)
##number of observations in each CV-group
colSums(I.cv)
##Which sites belong to which groups?
ID.cv <- apply(I.cv, 2, function(x){ unique(mesa.model$obs$ID[x]) })
##and then as above...
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.