summaryrefslogtreecommitdiff
path: root/R/cv_loss.R
blob: ea46007cbef7e608915f42da85c8380312d572fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
.cv_loss <- function(idx, dat, evencorrection, threshold, grid.length, p, nc) {
  res <- numeric(nc)
  n1 <- as.integer(sum(idx))
  C1 <- .Fortran("cormadvecdp", matrix = dat[idx, ], nrow = n1, ncol = p, res = res, 
    ressize = nc, correcteven = evencorrection, PACKAGE = "RSC")$res
  n2 <- as.integer(sum(!idx))
  C2 <- .Fortran("cormadvecdp", matrix = dat[!idx, ], nrow = n2, ncol = p, res = res, 
    ressize = nc, correcteven = evencorrection, PACKAGE = "RSC")$res
  ans <- rep(0, times = grid.length)
  for (h in 1:grid.length) {
    C1[abs(C1) < threshold[h]] <- 0
    ans[h] <- sum(2 * {
      C1 - C2
    }^2)/p
  }
  return(ans)
}