Skip to content

Commit

Permalink
Removed formula terms for testLike
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipMostert committed Aug 7, 2024
1 parent 6d69e60 commit 5bd436f
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions R/blockedCV.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,27 @@ blockedCV <- function(data, options = list(),
else spatRM <- FALSE #What about if species copy?
} else spatRM <- FALSE

formIn <- testLike[[1]]$used$effect
oldIn <- lapply(testLike, function(x) x$used$effect)

predComp <- comp_terms %in% formIn
#predComp <- comp_terms %in% formIn

if (spatRM) {
#if (spatRM) {

compsChange <- data$.__enclos_env__$private$Components
whichRM <- grepl(paste0(predictName, '_spatial'), compsChange)
compsChange[whichRM] <- paste0(predictName, '_spatial(main = geometry, model = predict_field)')
predict_field <- data$spatialFields$datasetFields[[1]]
# compsChange <- data$.__enclos_env__$private$Components
# whichRM <- grepl(paste0(predictName, '_spatial'), compsChange)
# compsChange[whichRM] <- paste0(predictName, '_spatial(main = geometry, model = predict_field)')
# predict_field <- data$spatialFields$datasetFields[[1]]

} else compsChange <- data$.__enclos_env__$private$Components
#} else compsChange <- data$.__enclos_env__$private$Components

compPreds <- formula(paste('~ - 1 +', paste(c(compsChange[predComp], 'olikhoodvar(main = olikhoodvar, model = "offset")'), collapse = ' + ')))
testLike[[1]]$used$effect <- c(testLike[[1]]$used$effect, 'olikhoodvar')
#compPreds <- formula(paste('~ - 1 +', paste(c(compsChange[predComp], 'olikhoodvar(main = olikhoodvar, model = "offset")'), collapse = ' + ')))

for (lik in 1:length(testLike)) {

testLike[[lik]]$used$effect <- c('testIntercept', 'olikhoodvar')#c(testLike[[1]]$used$effect, 'olikhoodvar')

}

}

trainLiks <- do.call(inlabru::like_list,
Expand Down Expand Up @@ -293,9 +298,10 @@ blockedCV <- function(data, options = list(),

for(pd in 1:length(testData[[1]])) {

covInPres <- testLike[[pd]]$used$effect
covInPres <- covInPres[!covInPres %in% c('olikhoodvar', biasFormlabels, grep('_biasField', covInPres))] #bias

#covInPres <- testLike[[pd]]$used$effect
#covInPres <- covInPres[!covInPres %in% c('olikhoodvar', biasFormlabels, grep('_biasField', covInPres))] #bias
covInPres <- intersect(oldIn[[pd]], formula_terms)
##Get all old vars in test like and thin with formula terms
predForm <- formula(paste0('~(', paste(covInPres, collapse = ' + '), ')'))


Expand All @@ -316,7 +322,7 @@ blockedCV <- function(data, options = list(),
foldOptions$control.family <- foldOptions$control.family[sourcePred]

optionsTest <- append(options, foldOptions)

compPreds <- ~ olikhoodvar(main = olikhoodvar, model = "offset") + testIntercept(1) - 1
testModel <- try(inlabru::bru(components = compPreds,
testLike, options = optionsTest))

Expand Down

0 comments on commit 5bd436f

Please sign in to comment.