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)
dplyrnow requires atidyselectspecification 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.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) yourdata, your question is not reproducible.scale, and the problem didn't occur during model training but ratherDHARMa::simulateResiduals(fittedModel = model, plot = T).DHARMa::simulateResiduals(fittedModel = model, plot = T). Do you think it's indeed a syntax bug?data=argument in theglmmTMBcall. 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 theglmmTMBcall and just use that directly.