R:找不到函数"function(object,...)\ nobject"在glm()和bestglm()中 [英] R: could not find function "function (object, ...) \nobject" in glm() and bestglm()

查看:128
本文介绍了R:找不到函数"function(object,...)\ nobject"在glm()和bestglm()中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从软件包 bestglm 中进行 bestglm 分析:

I was running a bestglm analysis from the package 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"

我检查了模型数据,看起来很不错-正确的类,没有缺失,以相同的方式使用过的变量也没问题.

I inspected my model data and it looks good -- the right classes, no missingness, variables I've used before in this same way with no problem.

在未成功排除故障并通过网络搜索错误之后,我尝试了对数据进行常规 glm 并开始收到几乎相同的错误:

After unsucessfully troubleshooting and web searching the error, I tried a regular glm with the data and started getting a nearly identical error:

> 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"

我不确定如何为该问题制作一个可复制的示例.这是我的数据结构:

I'm not sure how to make a reproducible example for this problem. Here's the structure of my data:

> 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 ...

无论我的模型规格如何,以及是否从数据框中删除列,此问题仍然存在,因此我认为这不是数据问题.

This problem persists regardless of my model specification and if I remove columns from the dataframes, so I do not think that it's a data issue.

> 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的建议下,我尝试了一些调试选项并获得了更多信息:

At the suggestion of @BenBolker, I tried some debugging options and got a little more info:

> 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)

推荐答案

非常感谢评论中的人们.

Many thanks to the folks in the comments.

我不太确定是什么导致了此错误,但这是修复该错误的原因:

I'm not really sure what caused this error, but here's what fixed it:

  1. 删除了有问题的对象 res.bestglm
  2. 重新安装 bestglm
  3. 保存图像并关闭项目
  4. 重新打开项目并加载软件包

我不确定为什么#1中的对象有问题,但是它在某种程度上使全球环境混乱.而且,在我启动香草会话之后,R不能找到 bestglm ,而没有先删除对象并重新安装软件包.

I'm not sure why the object in #1 was problematic, but it was somehow cluttering the Global Environment. Moreover, R could not find bestglm after I launched a vanilla session without removing the object first and re-installing the package.

这篇关于R:找不到函数"function(object,...)\ nobject"在glm()和bestglm()中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆