Problem with defining imputed variable as a vector in generated stan code

Open
#408 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
Over a week
Newbie friendliness
18/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
tooling

Research direction

The report points at the loop over right_symbols in the ulam code generator, where symbols are indexed with ii but a parameter's dims are read from symbols[[j]]. Reproducing it needs a model with an imputed variable used in a local vector expression, which the reporter has not supplied. The work is already a year old with no decision, so it needs a maintainer's view of intended behaviour before any fix.

Written by the indexing model from the issue text.

Description

I have an occasional issue In which the stan code does not identify a local variable as a vector when it depends on an imputed variable. I believe there is a bug the ulam code that is causing it. Below ii is the iterator for right_symbols but is used to index symbols on the third line. I tried changing the code to define j before that if statement, then index symbols with j, but it still resulted in the same error. I can keep chasing the issue, but I wanted to make sure I am not missing something. Let me know if you want me to generate something that reproduces the error.

for (ii in 1:length(right_symbols)) {
if (right_symbols[ii] %in% names(symbols)) {
if (symbols[[ii]]$type == "par") {
j <- which(names(symbols) == right_symbols[ii])
if (any(!is.na(symbols[[j]]$dims))) {
zzdims <- 0
if (length(symbols[[j]]$dims) == 1)
zzdims <- 1
else zzdims <- symbols[[j]]$dims[[2]]
the_dims <- max(the_dims, zzdims, na.rm = TRUE)
}
}
}
}

Dominant language
R
Stars
2.4k
Forks
632
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from rmcelreath/rethinking

All issues in rmcelreath/rethinking

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.