cv.cov_ogk: K-fold cross-validation for Bivariate Nadaraya-Watson...

View source: R/cov_ogk.R

cv.cov_ogkR Documentation

K-fold cross-validation for Bivariate Nadaraya-Watson smoothing for Covariance

Description

K-fold cross-validation for Bivariate Nadaraya-Watson smoothing for Covariance

Usage

cv.cov_ogk(
  X,
  type = c("huber", "bisquare", "tdist"),
  MM = TRUE,
  bw_cand = NULL,
  K = 5,
  ncores = 1
)

Arguments

X

a n x p matrix with or without NA.

type

the option for robust dispersion estimator. "huber", "bisquare", and "tdist" are supported.

MM

the option for M-scale estimator in GK identity. Default is same method using type which is iterative algorithm. The closed form solution using method of moments can be used when MM == TRUE.

bw_cand

a vector contains the candidates of bandwidths for bivariate smoothing.

K

the number of folds for K-fold cross validation.

ncores

the number of cores on foreach for parallel computing.

Value

a list contatining as follows:

selected_bw

the optimal bandwidth selected from the robust K-fold cross-validation.

cv.error

a matrix containing CV error per bandwidth candidates.

Examples

set.seed(100)
x.list <- sim_delaigle(n = 100,
                       type = "partial",
                       out.prop = 0.2,
                       dist = "normal")
x <- list2matrix(x.list)

# 5-fold CV for bivariate smoothing
# You can improve the computaion speed by setting "ncores" option.
bw_cand = seq(0.01, 0.1, length.out = 10)
cov.cv.obj <- cv.cov_ogk(x,
                         type = 'huber',
                         bw_cand = bw_cand,
                         K = 5,
                         ncores = 1)
print(cov.cv.obj$selected_bw)

# Robust smoothed covariance using selected bw from cross-validation
cov.obj <- cov_ogk(x,
                   type = "huber",
                   bw = cov.cv.obj$selected_bw)
mu.ogk.sm <- cov.obj$mean
cov.ogk.sm <- cov.obj$cov
noise.ogk.sm <- cov.obj$noise.var


statKim/robfpca documentation built on April 15, 2023, 10:12 p.m.