Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 5 additions & 32 deletions R/allFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,46 +165,19 @@ allFit <- function(object, meth.tab = NULL,
ctrl$optCtrl <- sanitize(ctrl$optCtrl,
opt.ctrls[[optimizer[..i]]])
ctrl <- do.call(if(isGLMM(object)) glmerControl else lmerControl, ctrl)
## need to stick ctrl in formula env so it can be found ...
form <- formula(object)
env <- environment(form)
tmp_env <- new.env(parent = env)
# temporarily changing the environment
environment(form) <- tmp_env
assign("ctrl", ctrl, envir = tmp_env, inherits = FALSE)
# Using the MLE as a starting point
if (start_from_mle) {
if (isGLMM(object)) {
pars <- getME(object, c("theta", "fixef"))
} else {
pars <- getME(object, "theta")
if(isNLMM(object)){
warning("results are not guaranteed when using nlmer")
fit_once <- function() {
if (start_from_mle && isNLMM(object)) {
warning("results are not guaranteed when using nlmer")
}
}
assign("pars", pars, envir = tmp_env, inherits = FALSE)
refit(object, control = ctrl)
}

fit_call <- if (start_from_mle) {
quote(update(object, start = pars, control = ctrl))
} else {
quote(update(object, control = ctrl))
}

tt <- system.time(
rr <- if (catch.errs) {
tryCatch(eval(fit_call), error = function(e) e)
} else {
eval(fit_call)
}
rr <- if (catch.errs) tryCatch(fit_once(), error = function(e) e) else fit_once()
)

attr(rr, "optCtrl") <- ctrl$optCtrl # contains crucial info here
attr(rr, "time") <- tt # store timing info

## restore original values to environment of the object
on.exit({ environment(form) <- env }, add = TRUE)

if (verbose) {
if (inherits(rr,"error")) {
cat("[failed]\n")
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-allFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ if (testLevel>1) {
cc <- capture.output(ff <- fit_func(cbpp))
expect_true(all(summary(ff)$which.OK))
})

test_that("allFit does not depend on update() data lookup", {
gm1 <- glmer(
cbind(incidence, size - incidence) ~ period + (1 | herd),
data = cbpp, family = binomial
)
gm1@call$data <- quote(.allFit_missing_data_symbol.)
cc <- capture.output(ff <- allFit(gm1, verbose = FALSE,
catch.errs = FALSE))
expect_true(all(summary(ff)$which.OK))
})

test_that("maxfun works", {
gm_it10 <- suppressWarnings(allFit(fit_cbpp_1, verbose=FALSE, maxfun = 10))
Expand Down