cvband: Cross-validation for Bandwidth Selection in...

View source: R/cvband.R

cvbandR Documentation

Cross-validation for Bandwidth Selection in Separable-plus-banded Model

Description

Calculates the objective value of the cross-validation criterion for bandwidth d between mind and maxd.

Usage

cvband(X, Folds = 10, maxd = 20, mind = 1)

Arguments

X

data set, array of size N x K1 x K2

Folds

number of folds

maxd

maximum bandwidth value to check

mind

minimum bandwidth value to check

Value

matrix with two rows: first row gives the fit, the second gives the norm, columns correspond to different bandwidths

Examples

N <- 500
K1 <- 5
K2 <- 7
set.seed(517)
X <- array(rnorm(N*K1*K2),c(N,K1,K2))
A <- matrix(rnorm(K1^2),K1)
B <- matrix(rnorm(K2^2),K2)
A <- A %*% t(A)
B <- B %*% t(B)
A <- mat_root(A)
B <- mat_root(B)
for(n in 1:N){
  X[n,,] <- A %*% X[n,,] %*% B + matrix(rnorm(K1*K2),K1)
}
maxd <- 3 # max range tobe
mind <- 1
cvscores <- cvband(X,10,maxd,mind) # two rows: fit and norm
cvscores[1,]/cvscores[2,] # cross-validation objective: fit/norm
cvscores[2,]^2 - 2*cvscores[1,] # alternative objective: norm^2 - 2*fit
# choose bandwidth as the smallest local maximum:
min(localMaxima(cvscores[1,]/cvscores[2,])) + mind - 1
min(which.min(cvscores[2,]^2 - 2*cvscores[1,])) + mind - 1
  # "+mind-1" to take care if mind in not equal to one

TMasak/surfcov documentation built on April 25, 2022, 12:15 a.m.