Skip to content

Commit 3b8dc05

Browse files
committed
merge with master, resolved merge conflicts
2 parents aa85325 + 574e10d commit 3b8dc05

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

R/snpnet.R

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
137137
warning(paste0("Missing phenotype entry (", phenotype, ") in ", s, " set for: ", utils::head(check.missing, 5), " ...\n"))
138138
}
139139
}
140+
141+
# focus on individuals with non-missing values.
142+
for(s in splits){
143+
ids[[s]] <- intersect(ids[[s]], phe.no.missing.IDs)
144+
}
140145

141146
### --- Prepare the feature matrix --- ###
142147
features <- list()
@@ -247,6 +252,8 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
247252
earlyStopNow <- (validation && checkEarlyStopping(metric.val, max.valid.idx, configs[['prevIter']], configs))
248253
}
249254
cat("\n")
255+
# end of pre-processing
256+
250257
if(! earlyStopNow){
251258
for (iter in (configs[['prevIter']]+1):configs[['niter']]) {
252259
time.iter.start <- Sys.time()
@@ -375,8 +382,6 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
375382
stats, glmfit, configs, iter, p.factor
376383
)
377384
snpnetLogger("KKT check obj done ...", indent=1)
378-
379-
lambda.idx <- check.obj[["next.lambda.idx"]] + (start.lams - 1)
380385
max.valid.idx <- check.obj[["max.valid.idx"]] + (start.lams - 1) # max valid index in the whole lambda sequence
381386

382387
# Update the lambda index of variants added
@@ -389,7 +394,16 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
389394
}
390395
}
391396

392-
if (configs[['use.glmnetPlus']] && check.obj[["max.valid.idx"]] > 0) {
397+
398+
if (lambda.idx < max.valid.idx) {
399+
is.KKT.valid.for.at.least.one <- TRUE
400+
} else{
401+
is.KKT.valid.for.at.least.one <- FALSE
402+
}
403+
lambda.idx <- check.obj[["next.lambda.idx"]] + (start.lams - 1)
404+
405+
406+
if (configs[['use.glmnetPlus']] && check.obj[["max.valid.idx"]] > 0) {
393407
prev.beta <- glmfit$beta[, check.obj[["max.valid.idx"]]]
394408
prev.beta <- prev.beta[prev.beta != 0]
395409
}
@@ -398,7 +412,10 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
398412
} else {
399413
num.new.valid[iter] <- check.obj[["max.valid.idx"]] - ifelse(iter > 1, num.new.valid[iter-1], 0)
400414
}
401-
if (check.obj[["max.valid.idx"]] > 0) {
415+
if (!is.KKT.valid.for.at.least.one) {
416+
features.to.keep <- union(features.to.keep, features.to.add)
417+
increase.snp.size <- TRUE
418+
} else {
402419
for (j in 1:check.obj[["max.valid.idx"]]) {
403420
a0[[j + (start.lams - 1)]] <- as.numeric(glmfit$a0[j])
404421
beta[[j + (start.lams - 1)]] <- glmfit$beta[, j]
@@ -427,10 +444,8 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
427444
is.ever.active <- apply(glmfit$beta[, 1:check.obj[["max.valid.idx"]], drop = F], 1, function(x) any(x != 0))
428445
features.to.keep <- union(rownames(glmfit$beta)[is.ever.active], features.to.keep)
429446
increase.snp.size <- FALSE
430-
} else if (check.obj[["max.valid.idx"]] == 0) {
431-
features.to.keep <- union(features.to.keep, features.to.add)
432-
increase.snp.size <- TRUE
433447
}
448+
434449
if (configs[['verbose']]) snpnetLoggerTimeDiff("End checking KKT condition.", time.KKT.start, indent=2)
435450

436451
if (configs[['save']]) {

0 commit comments

Comments
 (0)