gpt4 book ai didi

R: 在 glm() 和 bestglm() 中找不到函数 "function (object, ...)\nobject"

转载 作者:行者123 更新时间:2023-12-04 20:40:19 25 4
gpt4 key购买 nike

我正在运行 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)

最佳答案

非常感谢评论中的人。

我不确定是什么导致了这个错误,但这是修复它的方法:

  • 删除了一个有问题的对象,res.bestglm
  • 重装 bestglm
  • 保存图像并关闭项目
  • 重新打开项目并加载包

  • 我不知道为什么#1 中的对象有问题,但它以某种方式扰乱了全局环境。而且,R 找不到 bestglm在我启动了一个 vanilla session 之后,没有先删除对象并重新安装包。

    关于R: 在 glm() 和 bestglm() 中找不到函数 "function (object, ...)\nobject",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27724009/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com