stan-dev / stan-dev/rstanarm

`stan_gamm4()` and response expression

Open
#545 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary:

stan_gamm4() seems to have a problem with an expression on the left-hand (response) side of the formula.

Description:

stan_gamm4() throws an unexpected error in case of an expression on the left-hand (response) side of the formula (see "Reproducible Steps" below). Such an error does not occur with stan_glm() or stan_glmer().

Reproducible Steps:
# Original source: Example section of `?rstanarm::stan_gamm4`.
library(rstanarm)
options(mc.cores = parallel::detectCores(logical = FALSE))
dat <- mgcv::gamSim(1, n = 400, scale = 2) ## simulate 4 term additive truth
## Now add 20 level random effect`fac'...
dat$fac <- fac <- as.factor(sample(1:20, 400, replace = TRUE))
dat$y <- dat$y + model.matrix(~ fac - 1) %*% rnorm(20) * .5
br <- stan_gamm4(abs(y) ~ s(x0) + x1 + s(x2), data = dat, random = ~ (1 | fac),
                 chains = 1,
                 iter = 500, # for example speed
                 seed = 1140350788)

throws the error

Error in eval(predvars, data, env) : object 'y' not found

which does not occur with stan_glm() or stan_glmer():

br_glm <- stan_glm(abs(y) ~ x0 + x1 + x2, data = dat,
                   chains = 1,
                   iter = 500, # for example speed
                   seed = 1140350788)

br_glmer <- stan_glmer(abs(y) ~ x0 + x1 + x2 + (1 | fac), data = dat,
                       chains = 1,
                       iter = 500, # for example speed
                       seed = 1140350788)

RStanARM Version:

2.21.2 (from https://mc-stan.org/r-packages/)

R Version:

4.1.1

Operating System:

Ubuntu 20.04.2

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.

Research direction

Start by running the reproducible stan_gamm4(abs(y) ~ s(x0) + x1 + s(x2), ...) example and compare its formula handling with stan_glm() and stan_glmer(). Trace where stan_gamm4() evaluates the response expression; done means the example runs without the object 'y' not found error while preserving the existing model behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.