1
library(glmmTMB)
library(dplyr)
library(DHARMa)

ml <- glmmTMB(menthlth ~ sex + medcost + ...,
                   ziformula = ~ sex + medcost + X_educag + internet + ...,
                   data = data %>% mutate(across(c(where(is.numeric), -menthlth), scale)),
                   family = "genpois",
                   control = glmmTMBControl(optCtrl = list(iter.max = 1e3, eval.max = 1e3)))
model <- step(ml, direction = "both", k = log(nrow(data)))
DHARMa::simulateResiduals(fittedModel = model, plot = T)

I fitted a zero-inflated general Poisson model to my dataset data and tried to test the model. However, I don't understand the returned error. It seemingly points to the line of code centering all numerical columns except for the response in my data frame, but I don't see why. The problem didn't occur during the model fitting but rather DHARMa::simulateResiduals(). Can anyone help me? Thank you very much!

Error in UseMethod("mutate") : 
no applicable method for 'mutate' applied to an object of class "function"
17. mutate(., across(c(where(is.numeric), -menthlth), scale))
16. data %>% mutate(across(c(where(is.numeric), -menthlth), scale))
15. is.data.frame(data)
14. model.frame.default(drop.unused.levels = TRUE, formula = ~sex +
medcost + X_educag + smoke100 + status + sleptim1 + exeroft1 +
maxdrnks, data = data %>% mutate(across(c(where(is.numeric),
-menthlth), scale)))
13. model.frame(drop.unused.levels = TRUE, formula = ~sex + medcost +
X_educag + smoke100 + status + sleptim1 + exeroft1 + maxdrnks,
data = data %>% mutate(across(c(where(is.numeric), -menthlth),
scale)))
12. eval(mf, envir = environment(fixedform))
11. eval(mf, envir = environment(fixedform))
10. terms(eval(mf, envir = environment(fixedform)))
9. getXReTrms(formula, mf, fr, type = "conditional", contrasts = contrasts,
sparse = sparseX[["cond"]], old_smooths = old_smooths$cond)
8. mkTMBStruc(RHSForm(omi$allForm$formula, as.form = TRUE), omi$allForm$ziformula,
omi$allForm$dispformula, omi$allForm$combForm, mf, fr = augFr,
yobs = yobs, respCol = respCol, weights = c(model.weights(augFr)),
contrasts = omi$contrasts, family = omi$family, ziPredictCode = ziPredNm, ...
7. eval(expr, p)
6. eval.parent(mkTMBStruc(RHSForm(omi$allForm$formula, as.form = TRUE),
omi$allForm$ziformula, omi$allForm$dispformula, omi$allForm$combForm,
mf, fr = augFr, yobs = yobs, respCol = respCol, weights = c(model.weights(augFr)),
contrasts = omi$contrasts, family = omi$family, ziPredictCode = ziPredNm, ...
5. predict.glmmTMB(object, type = "response", re.form = ~0)
4. predict(object, type = "response", re.form = ~0)
3. getFitted.default(fittedModel)
2. getFitted(fittedModel)
1. DHARMa::simulateResiduals(fittedModel = model, plot = T)
5
  • 1
    This seems to be a bug, dplyr now requires a tidyselect specification in most of its verbs (e.g. all_of(where(is.numeric)) -- not sure if that would even work). Either way, not something that's on topic for this website. Perhaps StackOverflow might be better suited, but the package's issue tracker is your best bet. Commented Nov 18 at 9:57
  • data %>% mutate(across(c(where(is.numeric), -menthlth) seems syntactically incorrect. The second argument should be a function. Also it seems strange to attempt to set possibly many columns to the same set of values. Without (a sample of) your data, your question is not reproducible. Commented Nov 19 at 8:32
  • @Limey Thank you for your reply. The 2nd argument is indeed scale, and the problem didn't occur during model training but rather DHARMa::simulateResiduals(fittedModel = model, plot = T). Commented 22 hours ago
  • @PBulls Thank you for your reply! The problem didn't occur during the model training but rather DHARMa::simulateResiduals(fittedModel = model, plot = T). Do you think it's indeed a syntax bug? Commented 22 hours ago
  • 1
    Upon closer inspection the source is actually what you provided for the data= argument in the glmmTMB call. That might've worked there, but perhaps there is some non-standard evaluation interaction deep within all of these methods (and it is quite a stack) that causes the issue. A very simple fix might be to create your filtered input outside the glmmTMB call and just use that directly. Commented 22 hours ago

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.