我正在从bestglm
包中运行bestglm
分析:
res.bestglm <-
bestglm(Xy = offermodel,
family = binomial,
IC = "BIC",
method = "exhaustive")
summary(res.bestglm$BestModel)
Morgan-Tatar search since family is non-gaussian.
我开始收到此错误:
Error in model.frame.default(formula = y ~ 1, weights = weights, drop.unused.levels = TRUE) :
could not find function "function (object, ...) \nobject"
我检查了我的模型数据并且它看起来很好 - 正确的类,没有遗漏,我以前用过的变量同样没有问题。
在对错误进行了无法进行故障排除和网络搜索后,我尝试了常规的glm
数据并开始得到几乎相同的错误:
> glm.mba <- glm(y ~ female + DNC + SE_region + enr_before_offer + FA,
+ family = binomial(link = "probit"), data = offermodel)
Error in model.frame.default(formula = y ~ female + DNC + SE_region + :
could not find function "function (object, ...) \nobject"
我不确定如何为此问题制作可重现的示例。这是我的数据结构:
> str(offermodel)
'data.frame': 2559 obs. of 10 variables:
$ online_chan : num 1 1 1 1 1 1 1 1 1 1 ...
$ SE_region : num 1 0 0 0 1 0 0 0 0 0 ...
$ recruited : num 0 0 0 0 0 0 0 0 0 0 ...
$ referral : num 0 0 0 0 0 0 0 0 0 0 ...
$ FA : num 1 1 0 0 1 1 1 1 1 1 ...
$ female : num 0 0 0 0 0 0 0 0 0 0 ...
$ enr_before_offer: num 0 0 0 0 0 0 0 0 0 0 ...
$ reg_lag_high : num 0 0 0 0 0 0 0 0 0 0 ...
$ DNC : num 0 0 0 0 1 0 0 0 0 0 ...
$ y : num 1 1 1 0 0 1 1 1 1 1 ...
无论我的模型规范如何,如果我从数据框中删除列,这个问题仍然存在,所以我认为这不是数据问题。
> traceback()
5: model.frame.default(formula = y ~ female + DNC + SE_region +
enr_before_offer + FA, data = offermodel, drop.unused.levels = TRUE)
4: stats::model.frame(formula = y ~ female + DNC + SE_region + enr_before_offer +
FA, data = offermodel, drop.unused.levels = TRUE)
3: eval(expr, envir, enclos)
2: eval(mf, parent.frame())
1: glm(y ~ female + DNC + SE_region + enr_before_offer + FA, family = binomial(link = "probit"),
data = offermodel)
根据@BenBolker的建议,我尝试了一些调试选项并获得了更多信息:
> glm.mba <- glm(y ~ female + DNC + SE_region + enr_before_offer + FA, data = offermodel)
Error in model.frame.default(formula = y ~ female + DNC + SE_region + :
could not find function "function (object, ...) \nobject"
Enter a frame number, or 0 to exit
1: glm(y ~ female + DNC + SE_region + enr_before_offer + FA, data = offermodel)
2: eval(mf, parent.frame())
3: eval(expr, envir, enclos)
4: stats::model.frame(formula = y ~ female + DNC + SE_region + enr_before_offer + FA, data = offermodel, drop.unu
5: model.frame.default(formula = y ~ female + DNC + SE_region + enr_before_offer + FA, data = offermodel, drop.un
Selection: 5
Called from: (function ()
{
if (.isMethodsDispatchOn()) {
tState <- tracingState(FALSE)
on.exit(tracingState(tState))
}
calls <- sys.calls()
from <- 0L
n <- length(calls)
if (identical(sys.function(n), recover))
n <- n - 1L
for (i in rev(seq_len(n))) {
calli <- calls[[i]]
fname <- calli[[1L]]
if (!is.na(match(deparse(fname)[1L], c("methods::.doTrace",
".doTrace")))) {
from <- i - 1L
break
}
}
if (from == 0L)
for (i in rev(seq_len(n))) {
calli <- calls[[i]]
fname <- calli[[1L]]
if (!is.name(fname) || is.na(match(as.character(fname),
c("recover", "stop", "Stop")))) {
from <- i
break
}
}
if (from > 0L) {
if (!interactive()) {
try(dump.frames())
cat(gettext("recover called non-interactively; frames dumped, use debugger() to view\n"))
return(NULL)
}
else if (identical(getOption("show.error.messages"),
FALSE))
return(NULL)
calls <- limitedLabels(calls[1L:from])
repeat {
which <- menu(calls, title = "\nEnter a frame number, or 0 to exit ")
if (which)
eval(substitute(browser(skipCalls = skip), list(skip = 7 -
which)), envir = sys.frame(which))
else break
}
}
else cat(gettext("No suitable frames for recover()\n"))
})()
我也尝试过:
rm(res.bestglm) # Because of a message you can see in the comments
install.packages("bestglm")
require(bestglm)
答案 0 :(得分:3)
非常感谢评论中的人们。
我不确定是什么导致了这个错误,但是这就是修复它的原因:
res.bestglm
bestglm
我不确定为什么#1中的对象存在问题,但它在某种程度上混淆了全球环境。此外,在我没有首先移除对象并重新安装包之后启动了一个vanilla会话后,R找不到bestglm
。