Computes the likelihood cross-validation

Share:

Description

The lemXv function computes the likelihood cross-validation scores for the observed data with the input bandwidths used for the smoothing matrix. The cross-valiation test and training datasets of the observed cases are generated by k-fold sampling without replacement.

Usage

1
2
lemXv(x, lemObjects, Nxv = 5, ncores = 1, tol = 1e-06, maxIter = 2000,
  randomSeed = NULL, verbose = FALSE)

Arguments

x

Spatial polygons of case data

lemObjects

List of arrays for the smoothing matrix, and raster stacks for the partition and smoothed offsets

Nxv

Number of cross-validation datasets

ncores

Number of cores/threads for parallel processing

tol

Tolerance for convergence

maxIter

Maximum number of iterations for convergence

randomSeed

Seed for random number generator

verbose

Verbose output

Details

After using the lemXv function, the last entry of the data frame object is the theoretical cross-validation score when bandwidth is set to infinity.

Value

The lemXv function returns a data frame of specified bandwidths and their cross-validation scores.

Examples

 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
## Not run:  
data(kentuckyCounty)
data(kentuckyTract)

ncores = 1 + (.Platform$OS.type == 'unix')

lemRaster = rasterPartition(polyCoarse = kentuckyCounty, 
                           polyFine = kentuckyTract, 
                           cellsCoarse = 6, 
                           cellsFine = 100, 
                           bw = c(10, 12, 15, 17, 20, 25) * 1000, 
                           ncores = ncores, 
                           idFile = 'id.grd', 
                           offsetFile = 'offset.grd', 
                           verbose = TRUE)


lemSmoothMat = smoothingMatrix(rasterObjects = lemRaster, 
                               ncores = ncores, 
                               verbose = TRUE)

lemCv = lemXv(x = kentuckyCounty, 
             lemObjects = lemSmoothMat, 
             Nxv = 5, 
             ncores = ncores, 
             verbose = TRUE)
bestBw = lemCv$bw[which.min(lemCv$cv)]

plot(lemCv[is.finite(lemCv$bw),], 
    xlab = 'Bandwidth (m)', 
    ylab = 'CV', 
    log = 'x', col = 'red', type = 'o')
abline(v = bestBw, lty = 3)

## End(Not run)