merliseclyde / BAS

BAS R package https://merliseclyde.github.io/BAS/
https://merliseclyde.github.io/BAS/
GNU General Public License v3.0
41 stars 16 forks source link

coef throws warnings with bas.glm objects if prior is AIC or BIC #65

Closed merliseclyde closed 1 year ago

merliseclyde commented 1 year ago

Describe the bug priors in bas.glm are objects, while in bas.lm character strings are used to refer to the prior, so the check to see if the prior is one of AIC or BIC in the coef function fails as it is comparing to object$prior which completes to object$priorprobs and the wrong length. No warning occurs if there is only a single model as when restricting the number of models.

To Reproduce Steps to reproduce the behavior:

 pima.bas = bas.glm(formula = type ~ bp + bmi, data = Pima.tr, 
                     family = binomial(), 
                     betaprior = bic.prior(), 
                     modelprior = uniform(), 
                     method = "BAS")

 coef(pima.bas)

Expected behavior no warnings or errors

Offending Code

Starting line 126

  if (!(object$prior == "AIC" || object$prior == "BIC")) {
    conditionalsd[, -1] <- sweep(conditionalsd[, -1, drop = F], 1,
      sqrt(shrinkage),
      FUN = "*"
    )
  }

and line 140

      df <- df - object$rank
    } else {
      df <- df - 1

Desktop (please complete the following information):

Additional context check if this impacts predictions too

merliseclyde commented 1 year ago

Fixed in main version 1.6.5