@@ -137,6 +137,11 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
137
137
warning(paste0(" Missing phenotype entry (" , phenotype , " ) in " , s , " set for: " , utils :: head(check.missing , 5 ), " ...\n " ))
138
138
}
139
139
}
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
+ }
140
145
141
146
# ## --- Prepare the feature matrix --- ###
142
147
features <- list ()
@@ -247,6 +252,8 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
247
252
earlyStopNow <- (validation && checkEarlyStopping(metric.val , max.valid.idx , configs [[' prevIter' ]], configs ))
248
253
}
249
254
cat(" \n " )
255
+ # end of pre-processing
256
+
250
257
if (! earlyStopNow ){
251
258
for (iter in (configs [[' prevIter' ]]+ 1 ): configs [[' niter' ]]) {
252
259
time.iter.start <- Sys.time()
@@ -375,8 +382,6 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
375
382
stats , glmfit , configs , iter , p.factor
376
383
)
377
384
snpnetLogger(" KKT check obj done ..." , indent = 1 )
378
-
379
- lambda.idx <- check.obj [[" next.lambda.idx" ]] + (start.lams - 1 )
380
385
max.valid.idx <- check.obj [[" max.valid.idx" ]] + (start.lams - 1 ) # max valid index in the whole lambda sequence
381
386
382
387
# Update the lambda index of variants added
@@ -389,7 +394,16 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
389
394
}
390
395
}
391
396
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 ) {
393
407
prev.beta <- glmfit $ beta [, check.obj [[" max.valid.idx" ]]]
394
408
prev.beta <- prev.beta [prev.beta != 0 ]
395
409
}
@@ -398,7 +412,10 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
398
412
} else {
399
413
num.new.valid [iter ] <- check.obj [[" max.valid.idx" ]] - ifelse(iter > 1 , num.new.valid [iter - 1 ], 0 )
400
414
}
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 {
402
419
for (j in 1 : check.obj [[" max.valid.idx" ]]) {
403
420
a0 [[j + (start.lams - 1 )]] <- as.numeric(glmfit $ a0 [j ])
404
421
beta [[j + (start.lams - 1 )]] <- glmfit $ beta [, j ]
@@ -427,10 +444,8 @@ snpnet <- function(genotype.pfile, phenotype.file, phenotype, status.col = NULL,
427
444
is.ever.active <- apply(glmfit $ beta [, 1 : check.obj [[" max.valid.idx" ]], drop = F ], 1 , function (x ) any(x != 0 ))
428
445
features.to.keep <- union(rownames(glmfit $ beta )[is.ever.active ], features.to.keep )
429
446
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
433
447
}
448
+
434
449
if (configs [[' verbose' ]]) snpnetLoggerTimeDiff(" End checking KKT condition." , time.KKT.start , indent = 2 )
435
450
436
451
if (configs [[' save' ]]) {
0 commit comments