R: Could not find function "function (object, ...) \ nobject" in glm () and bestglm ()

I ran the analysis bestglm

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

      

and I started getting this error:

Error in model.frame.default(formula = y ~ 1, weights = weights, drop.unused.levels = TRUE) : 
  could not find function "function (object, ...) \nobject"

      

I have looked at my model data and it looks good - correct classes, no gaps, variables I used previously, in the same way without issue.

After unsuccessful troubleshooting and searching the internet for the error, I tried a normal one glm

with data and started getting an almost 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 of this problem. Here is my data structure:

> 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 issue persists regardless of my model specification and if I remove columns from data frames, so I don't think it is 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)

      

As suggested by @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"))
})()

      

I've also tried:

rm(res.bestglm) # Because of a message you can see in the comments
install.packages("bestglm")
require(bestglm)

      

+3


source to share


1 answer


Many thanks to the people in the comments.

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



  • The problematic object was removed, res.bestglm

  • Reinstalled bestglm

  • Saved image and closing the project
  • Reopen project and downloaded packages

I'm not sure why the object at # 1 was problematic, but it cluttered the global environment in some way. Moreover, R could not find bestglm

after I started the vanilla session without first deleting the object and reinstalling the package.

+3


source







All Articles