Skip to content

Commit

Permalink
Following upon PR stan-dev#201, also avoid the preprocess_data() ca…
Browse files Browse the repository at this point in the history
…ll in

`fit_gamm_callback()`. The reasons are the same as those given in PR stan-dev#201. Thus,
this fixes issue stan-dev#202. Furthermore, this also fixes issue stan-dev#147 by breaking the
infinite loop.
  • Loading branch information
fweber144 committed May 5, 2022
1 parent 3f9defc commit a937680
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions R/divergence_minimizers.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,24 @@ fit_gamm_callback <- function(formula, projpred_formula_no_random,
))))
}, error = function(e) {
if (grepl("not positive definite", as.character(e))) {
scaled_data <- preprocess_data(data, projpred_formula_no_random)
fit_gamm_callback(
if ("optimx" %in% control$optimizer &&
length(control$optCtrl$method) > 0 &&
control$optCtrl$method == "nlminb") {
stop("Encountering the `not positive definite` error while running ",
"the lme4 fitting procedure, but cannot fix this automatically ",
"anymore.")
}
return(fit_gamm_callback(
formula = formula,
projpred_formula_no_random = projpred_formula_no_random,
projpred_random = projpred_random,
data = scaled_data,
data = data,
family = family,
control = control_callback(family,
optimizer = "optimx",
optCtrl = list(method = "nlminb")),
...
)
))
} else {
stop(e)
}
Expand Down Expand Up @@ -328,16 +334,6 @@ fit_glmer_callback <- function(formula, family,
})
}

preprocess_data <- function(data, formula) {
tt <- extract_terms_response(formula)
non_group_terms <- c(tt$individual_terms, tt$interaction_terms)
X <- data %>%
dplyr::select(non_group_terms) %>%
scale()
data[, non_group_terms] <- X
return(data)
}

# Helper function for fit_glmer_callback() and fit_gamm_callback() to get the
# appropriate control options depending on the family:
control_callback <- function(family, ...) {
Expand Down

0 comments on commit a937680

Please sign in to comment.