diff options
| author | Luca Coraggio <luca.coraggio@unina.it> | 2020-07-04 09:50:03 +0000 |
|---|---|---|
| committer | cran-robot <csardi.gabor+cran@gmail.com> | 2020-07-04 09:50:03 +0000 |
| commit | 511e3ca9e5235e018f772693907d9ec10002b02a (patch) | |
| tree | c7cb699babfa439e6bfbe47007e3916867517f76 /R/cv_loss.R | |
version 1.0
Diffstat (limited to 'R/cv_loss.R')
| -rw-r--r-- | R/cv_loss.R | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/R/cv_loss.R b/R/cv_loss.R new file mode 100644 index 0000000..ea46007 --- /dev/null +++ b/R/cv_loss.R @@ -0,0 +1,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) +} |
