link() not handling id variable values not in original data
lorenze3 opened this issue · 2 comments
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.
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.
Yes, the goal is to be able to predict a new/out of sample store.
Thanks for the response!