stan-dev / stan-dev/rstanarm

model.matrix() fails for stan_betareg if x = TRUE

Open
#186 11 comments 0 reactions 1 assignee View on GitHub

@imadmali is already working on this.

Since May 15, 2017.

minor bug
Dominant language
R
Stars
401
Forks
136
PR merge metrics
No merged PRs in 30d

Description

Summary:

By default, x = FALSE in stan_betareg() in which case model.matrix() works. However, if x = TRUE, then model.matrix() eventually fails.

Description:

model.matrix() calls model.matrix.stanreg(), which hands off to model.matrix.betareg(), which is

function (object, model = c("mean", "precision"), ...) 
{
    model <- match.arg(model)
    rval <- if (!is.null(object$x[[model]])) 
        object$x[[model]]
    else model.matrix(object$terms[[model]], model.frame(object), 
        contrasts = object$contrasts[[model]])
    return(rval)
}

this falls to the else clause by default because object$x partially matches object$xlevels, which is a list without an element called "mean" (or "precision"). But when x = TRUE, in the call to stan_betareg, object$x matches this matrix, which cannot be indexed by [model].

In addition, if model = FALSE in the call to stan_betareg(), then model.matrix() will fail even if x = FALSE because when it falls into else model.matrix(...), model.matrix.default() tries to extract object$model, which partially matches object$modeling_function and barfs on this character string.

Reproducible Steps:
example(stan_betareg, ask = FALSE)
model.matrix(update(fit, x = TRUE))
RStanARM Version:

2.15.3

R Version:

3.4.0

Operating System:

Debian

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.