Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error using .Call() in R 3.0.+

Tags:

r

I am trying to use a function that models nesting success of birds using a logistic exposure link function.

When I run this function using the example code above in R 3.0.0 or 3.0.1, I get the error:

Error in .Call("logit_mu_eta", eta, PACKAGE = "stats") : 
  "logit_mu_eta" not available for .Call() for package "stats"

However, it works fine in R 2.15.3.

I'd like for this to work in more recent versions of R, since I use those for further analysis of the outputs. If anybody has any suggestions, workarounds or corrections, I'd happily try them.

like image 252
MAHE Avatar asked Oct 21 '22 00:10

MAHE


1 Answers

This is not technically a bug, since the function used an internal function whose location has now changed. I have a working example of this posted at https://rpubs.com/bbolker/logregexp ... the key is changing logit_mu_eta to stats:::C_logit_mu_eta as below. Of course, this will still be fragile to future changes in the internals ...

logexp <- function(exposure = 1)
{
    linkfun <- function(mu) qlogis(mu^(1/exposure))
    ## FIXME: is there some trick we can play here to allow
    ##   evaluation in the context of the 'data' argument?
    linkinv <- function(eta)  plogis(eta)^exposure
    mu.eta <- function(eta) exposure * plogis(eta)^(exposure-1) *
      .Call(stats:::C_logit_mu_eta, eta, PACKAGE = "stats")
    valideta <- function(eta) TRUE
    link <- paste("logexp(", deparse(substitute(exposure)), ")",
                   sep="")
    structure(list(linkfun = linkfun, linkinv = linkinv,
                   mu.eta = mu.eta, valideta = valideta, 
                   name = link),
              class = "link-glm")
}
like image 164
Ben Bolker Avatar answered Oct 30 '22 23:10

Ben Bolker