link() not handling id variable values not in original data

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

Nobody has claimed this yet.

Assessment

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

Research direction

Start by running the reproducible example in the issue: fit a small ulam() model with an index variable (store_id), then call link() on new data with store_id values 1, 2 and 0 to see which ones fail. The payload does not name the source files involved, so locate link() and its index handling yourself. Done means either link() handles unseen index values as the documentation describes, or the error and documentation are changed to say clearly what is required. Expect design questions from the maintainer, and check the thread first.

Written by the indexing model from the issue text.

Description

Howdy,

I don't know if this is a bug or if the function documentation is out of date, but link() no longer will handle an indexing variable set to 0 or missing (for ulam output, at least) and throws an error instead. Here's an example:

library(rethinking)

tib<-tibble(store_id=c(1,1,1,2,2,2),
            y=c(0,1,2,0,2,4),
            x=c(0,1,2,0,1,2))

ulam_obj<-ulam(
  alist(y~normal(product,.0000001),
         product<- (bx[store_id] +b )*x,
        bx[store_id] ~ normal(0,1),
        b ~ normal(1.5,.00001)
        ),
  data=tib,
  chains=1,sample=T,iter=50
)


new_tib1<-tibble(store_id=c(1,1),x=c(3,4))

new_tib2<-tibble(store_id=c(2,2),x=c(3,4))

new_tib0<-tibble(store_id=c(0,0),x=c(3,4))

link(ulam_obj,new_tib1)
link(ulam_obj,new_tib2)

#this one errors:
link(ulam_obj,new_tib0)

#as does
new_tib<-tibble(x=c(3,4))
link(ulam_obj,new_tib)

If you have the time, I'd love a pointer or hint or suggestion towards a workaround. The inner workings of link() are mysterious to this uninitiated fellow. Many thanks, again, for the work you've put in to the package and into educating so many of us.

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.