Skip to content

Commit 59f40e3

Browse files
committed
Filter all duplicate components
1 parent 572343c commit 59f40e3

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

R/blockedCV.R

+54
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,59 @@ blockedCV <- function(data, options = list(),
345345
covInPres <- covInPres[!covInPres %in% biasFormlabels]
346346
covInPres <- covInPres[!covInPres %in% grepl('_biasField', covInPres)]
347347

348+
if (sum(grepl('_spatial', covInPres)) > 1) {
349+
350+
spatIn <- covInPres[grepl('_spatial', covInPres)]
351+
if (paste0(predictName,'_spatial') %in% spatIn) covInPres[!covInPres %in% paste0(dataToUse[!dataToUse%in% predictName],'_spatial')]
352+
else {
353+
if (any(unlist(data$.__enclos_env__$private$Family)[names(data$.__enclos_env__$private$Family) %in% dataToUse] %in% c('poisson', 'binomial'))) {
354+
355+
keepSpat <- unlist(data$.__enclos_env__$private$Family)[names(data$.__enclos_env__$private$Family) %in% dataToUse] %in% c('poisson', 'binomial')
356+
keepSpat <- names(unlist(data$.__enclos_env__$private$Family)[names(data$.__enclos_env__$private$Family) %in% dataToUse])[keepSpat][1]
357+
covInPres <- covInPres[!covInPres %in% paste0(dataToUse[!dataToUse%in% keepSpat],'_spatial')]
358+
359+
} else {
360+
361+
keepSpat <- names(unlist(data$.__enclos_env__$private$Family)[names(data$.__enclos_env__$private$Family) %in% dataToUse])[1]
362+
covInPres <- covInPres[!covInPres %in% paste0(dataToUse[!dataToUse%in% keepSpat],'_spatial')]
363+
364+
}
365+
366+
}
367+
368+
}
369+
370+
if (sum(grepl('_intercept', covInPres)) > 1) {
371+
372+
intInt <- covInPres[grepl('_intercept', covInPres)]
373+
if (paste0(predictName,'_intercept') %in% intInt) covInPres[!covInPres %in% paste0(dataToUse[!dataToUse%in% predictName],'_intercept')]
374+
else {
375+
if (any(unlist(data$.__enclos_env__$private$Family)[names(data$.__enclos_env__$private$Family) %in% dataToUse] %in% c('poisson', 'binomial'))) {
376+
377+
keepInt <- unlist(data$.__enclos_env__$private$Family)[names(data$.__enclos_env__$private$Family) %in% dataToUse] %in% c('poisson', 'binomial')
378+
keepInt <- names(unlist(data$.__enclos_env__$private$Family)[names(data$.__enclos_env__$private$Family) %in% dataToUse])[keepInt][1]
379+
covInPres <- covInPres[!covInPres %in% paste0(dataToUse[!dataToUse%in% keepInt],'_intercept')]
380+
381+
} else {
382+
383+
keepInt <- names(unlist(data$.__enclos_env__$private$Family)[names(data$.__enclos_env__$private$Family) %in% dataToUse])[1]
384+
covInPres <- covInPres[!covInPres %in% paste0(dataToUse[!dataToUse%in% keepInt],'_intercept')]
385+
386+
}
387+
388+
}
389+
390+
}
391+
##grepl(_spatial, covInPres) <- if bigger than 1 <- then keep only predict and PA/Counts BUT KEEP shared_spatial
392+
##grepl(_intercept, covInPres) <- then keep only predict and PA/Counts
393+
394+
#if not shared spatial
395+
#Select predData intercept
396+
#Else if not in, select first non PO
397+
#Else select PO
398+
399+
#Same for intercept
400+
348401
if (!is.null(data$.__enclos_env__$private$speciesName)) {
349402

350403
likeSpec <- unique(testLike[[pd]]$data[[paste0(data$.__enclos_env__$private$speciesName, 'INDEX_VAR')]])
@@ -377,6 +430,7 @@ blockedCV <- function(data, options = list(),
377430
}
378431

379432
}
433+
380434
#if bias
381435

382436
#covInPres <- intersect(oldIn[[pd]], formula_terms)

0 commit comments

Comments
 (0)