Skip to content

Commit c6015aa

Browse files
author
Joshua Loftus
committed
cvMakeFolds now has permutation built in
1 parent cb3ef4a commit c6015aa

File tree

1 file changed

+12
-4
lines changed
  • forLater/josh/selectiveInference/R

1 file changed

+12
-4
lines changed

forLater/josh/selectiveInference/R/cv.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# ------------------------------------------------
22
# Cross-validation, preliminary
33

4-
cvMakeFolds <- function(x, nfolds = 10) {
5-
#inds <- sample(1:nrow(x), replace=FALSE)
6-
inds <- 1:nrow(x)
4+
cvMakeFolds <- function(x, nfolds = 5) {
5+
inds <- sample(1:nrow(x), replace=FALSE)
6+
#inds <- 1:nrow(x)
77
foldsize <- floor(nrow(x)/nfolds)
8-
lapply(1:nfolds, function(f) return(inds[1:foldsize+(f-1)*foldsize]))
8+
folds <- lapply(1:nfolds, function(f) return(inds[1:foldsize+(f-1)*foldsize]))
9+
if (nfolds*foldsize < nrow(x)) {
10+
# remainder observations added to first several folds
11+
for (i in 1:(nrow(x) - nfolds*foldsize)) {
12+
folds[[i]] <- c(folds[[i]], inds[nfolds*foldsize + i])
13+
}
14+
}
15+
return(folds)
916
}
1017

1118
############################################
@@ -87,6 +94,7 @@ cvfs <- function(x, y, index = 1:ncol(x), maxsteps, sigma = NULL, intercept = TR
8794
fold <- folds[[f]]
8895
fit <- groupfs(X[-fold,], Y[-fold], index=index, maxsteps=maxsteps, sigma=sigma, intercept=FALSE, center=FALSE, normalize=FALSE)
8996
fit$fold <- fold
97+
# Why is this commented out?
9098
## projections[[f]] <- lapply(fit$projections, function(step.projs) {
9199
## lapply(step.projs, function(proj) {
92100
## # Reduce from n by n matrix to svdu_thresh

0 commit comments

Comments
 (0)