findTuning: Find Tuning parameters for B-spline spatial deformation

Description Usage Arguments Value Examples

View source: R/findTuning.R

Description

This auxiliary function helps finding tuning parameters (lambda, zeta) for the B-spline tensor product spatial deformation. Execution might be slow.

Usage

1
2
3
findTuning(model, grid.lambda = 10^(-5:5),
  grid.zeta = min(apply(model$x, 2, function(x) diff(range(x)))) *
  (1:10)/20, verbose = FALSE)

Arguments

model

an object from the bdef function.

grid.lambda

Grid of values for the penalty parameter lambda.

grid.zeta

Grid of values for the penalty parameter zeta.

verbose

Verbose execution informs user of the LOOCV progress. Defaults to FALSE.

Value

a data frame with the selected grid, and the leave-one-out cross validation error

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
36
37
38
# Example using artificially generated data
## Not run: 
set.seed(1)
m <- 10
x1 <- (0:m)/m
x2 <- (0:m)/m
x <- as.matrix(expand.grid(x1,x2))
n <- nrow(x)
F1 <- function(x1,x2, a = 2.5, b = 1.0) {
x <- x1 - 0.5; y <- x2 - 0.5
angle <- a*exp(-(x*x+y*y)/(b*b)) + 3*pi/2
return(cos(angle)*x + sin(angle)*y + 0.5)
}
F2 <- function(x1,x2, a = 2.5, b = 1.0) {
x <- x1 - 0.5; y <- x2 - 0.5
angle <- a*exp(-(x*x+y*y)/(b*b)) + 3*pi/2
return(-sin(angle)*x + cos(angle)*y + 0.5)
}
TIME <- 20
covModel <- RMexp(var = 1, scale = .25, proj = "space") + RMnugget(var = 1) # Independent in time
data <- RFsimulate(covModel, x = F1(x[,1],x[,2]), y = F2(x[,1],x[,2]), 
                   T = seq(from = 1, by = 1, len = TIME)) # order ~ expand.grid(x, y, T)
y <- as.numeric(unlist(data@data))
# Model for spatial dependence, time is assumed independent
covModelM <- RMexp(var = NA, scale = NA) + RMnugget(var = NA)
# Calculates deformation, profle likelihood up to maxit times
test.def <- bdef(x, y, tim = 1:TIME, cov.model = covModelM, maxit = 10)
tuningChoice <- findTuning(test.def, verbose = TRUE)
require(ggplot2)
require(dplyr)
tuningChoice %>%
mutate(zeta = factor(zeta)) %>%
mutate(lambda = log(lambda)) %>%
ggplot(aes(x = lambda, y = LOOCV, color = zeta)) + 
geom_point() +
geom_line(aes(group = zeta))

## End(Not run)

guiludwig/bsplinedef documentation built on May 16, 2020, 10:24 p.m.