plotGrid: Plot Spatial Deformations from bdef

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/plotGrid.R

Description

This function plot a spatial deformation on a grid obtained via the bdef function

Usage

1
2
3
plotGrid(model, nx = 20, ny = 20, colorO = "Black", colorD = "Red",
  plot = TRUE, margins = TRUE, persp = FALSE, F1 = NULL,
  F2 = NULL, chull = FALSE, offset = c(0, 0), ...)

Arguments

model

An object returned by the function bdef. Alternatively, a list with named components matching those returned by bdef.

nx

Number of ticks in x-axis for grid. Defaults to 10.

ny

Number of ticks in y-axis for grid. Defaults to 10.

colorO

Color of original data points and grid. Defaults to Black.

colorD

Color of deformed data points and grid. Defaults to Red.

plot

Whether a plot should be produced or not. Defaults to TRUE.

margins

Whether a layout should be produced, with f1, f2 estimates shown along the corresponding axes. Defaults to TRUE.

F1

Allows the user to supply a function that generates the deformed coordinate y1. Defaults to NULL, in which case the tensor product of B-splines is used instead.

F2

Allows the user to supply a function that generates the deformed coordinate y2. Defaults to NULL, in which case the tensor product of B-splines is used instead.

chull

Whether the deformation is displayed inside of the convex hull of the sampled sites, or a square window containing the sampled sites. Defaults to FALSE, which corresponds to the square window.

...

Extra parameters to be passed to perspective plot, in particular the azymutal direction and colatitude. See persp for a description.

Value

plotGrid invisibly returns the values of the deformation on the grid.

Author(s)

Guilherme Ludwig and Ronaldo Dias

References

To add.

See Also

bdef

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
39
40
41
42
43
44
45
46
47
# Example using artificially generated data
set.seed(1)
m <- 10
x1 <- (0:m)/m
x2 <- (0:m)/m
x <- as.matrix(expand.grid(x1,x2))
n <- nrow(x)
K <- 4
tempb1 <- bs(x[, 1], K, intercept = TRUE)
tempb2 <- bs(x[, 2], K, intercept = TRUE)
tempW <- matrix(0, n, K^2)
for(i in 1:n) tempW[i,] <- kronecker(tempb2[i,], tempb1[i,])
theta1 <- solve(crossprod(tempW), crossprod(tempW, x[,1] + .2*x[,2]))
theta2 <- solve(crossprod(tempW), crossprod(tempW, x[,2] - .2*sqrt(x[,1]*x[,2])))
def.x <- cbind(tempW%*%theta1, tempW%*%theta2)
fakeModel <- list(basis = list(B1 = bs(range(x[, 1]), K, intercept = TRUE),
                               B2 = bs(range(x[, 2]), K, intercept = TRUE)),
                  window = list(x = 0:1, y = 0:1),
                  x = x, def.x = def.x,
                  theta1 = theta1,
                  theta2 = theta2,
                  df1 = K,
                  df2 = K)
 plotGrid(fakeModel, margins = FALSE)
 plotGrid(fakeModel)
 plotGrid(fakeModel, persp = TRUE, theta = 15)
# Example with truth function
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(y + x^2)
}
plotGrid(list(window = list(x = range(x1), y = range(x2)),
x = x, def.x = cbind(F1(x[,1],x[,2]), 
                                  F2(x[,1],x[,2]))),
        F1 = F1, F2 = F2)

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