Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lorenze3 opened this issue Oct 3, 2023 · 2 comments
Open

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

lorenze3 opened this issue Oct 3, 2023 · 2 comments

Comments

@lorenze3
Copy link

lorenze3 commented Oct 3, 2023

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.

@rmcelreath
Copy link
Owner

I am not sure there is a workaround - you want to predict for a new store? I will look at the code and see if this is a method difference.

@lorenze3
Copy link
Author

lorenze3 commented Oct 3, 2023

Yes, the goal is to be able to predict a new/out of sample store.

Thanks for the response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants