You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I really appreciate the work both in educating on bayesian regression in such an entertaining way and in making stan so easy to use from R.
I'm abusing the rethinking package to avoid writing macros to write stan code (because someone already did that, right?). I'd use brms for my problem except I want per-coefficient lower bounds (ie some coefficients to be non-negative, but not all). At any rate, I've got a very long deterministic assignment. Once I add 'too many' terms to the model, ulam() breaks up the assignment into two lines, but not in a way that is syntatically correct.
If you check the resulting stan code in fff$model, you'll see that big_model[i] is split into two lines, but the first one ends in a +, and the second line does not increment the existing big_model[i]. I'll paste that code in below.
#!stan
data{
array[100] int store_id;
array[100] int week;
vector[100] cos1;
vector[100] sin1;
array[100] int twitter;
array[100] int tiktok;
array[100] int taboola;
array[100] int tv;
array[100] int video;
array[100] int snapchat;
array[100] int simplifi;
array[100] int radio;
array[100] int pinterest;
array[100] int ooh;
array[100] int newspaper;
array[100] int mntn;
array[100] int marketingcloud;
array[100] int google;
array[100] int facebook;
array[100] int digital;
array[100] int cable;
array[100] int bing;
vector[100] leads;
}
parameters{
real b_bing;
real b_cable;
real b_digital;
real b_facebook;
real b_google;
real b_marketingcloud;
real b_mntn;
real b_newspaper;
real b_ooh;
real b_pinterest;
real b_radio;
real b_simplifi;
real b_snapchat;
real b_video;
real b_tv;
real b_taboola;
real b_tiktok;
real b_twitter;
real b_sin1;
real b_cos1;
vector[2] store_int;
real a0;
real b_week;
real<lower=0> big_sigma;
}
model{
vector[100] big_model;
leads ~ normal( big_model , big_sigma );
big_sigma ~ normal( 100 , 100 );
for ( i in 1:100 ) {
big_model[i] = b_bing * bing[i] + b_cable * cable[i] + b_digital * digital[i] + b_facebook * facebook[i] + b_google * google[i] + b_marketingcloud * marketingcloud[i] + b_mntn * mntn[i] + b_newspaper * newspaper[i] + b_ooh * ooh[i] + b_pinterest * pinterest[i] + b_radio * radio[i] + b_simplifi * simplifi[i] + b_snapchat * snapchat[i] + b_video * video[i] + b_tv * tv[i] + b_taboola * taboola[i] + b_tiktok * tiktok[i] + b_twitter * twitter[i] + b_sin1 * sin1[i] + b_cos1 * cos1[i] + b_week * week[i] + store_int[store_id[i]] + ;
big_model[i] = a0;
}
b_week ~ normal( 0 , 100 );
a0 ~ normal( 0 , 10 );
store_int ~ normal( 0 , 10 );
b_cos1 ~ normal( 0 , 10 );
b_sin1 ~ normal( 0 , 10 );
b_twitter ~ normal( 0 , 10 );
b_tiktok ~ normal( 0 , 10 );
b_taboola ~ normal( 0 , 10 );
b_tv ~ normal( 0 , 10 );
b_video ~ normal( 0 , 10 );
b_snapchat ~ normal( 0 , 10 );
b_simplifi ~ normal( 0 , 10 );
b_radio ~ normal( 0 , 10 );
b_pinterest ~ normal( 0 , 10 );
b_ooh ~ normal( 0 , 10 );
b_newspaper ~ normal( 0 , 10 );
b_mntn ~ normal( 0 , 10 );
b_marketingcloud ~ normal( 0 , 10 );
b_google ~ normal( 0 , 10 );
b_facebook ~ normal( 0 , 10 );
b_digital ~ normal( 0 , 10 );
b_cable ~ normal( 0 , 10 );
b_bing ~ normal( 0 , 10 );
}
for my immediate purposes I'm just going to use shorter variable names, but this might be a simple fix? Changing the big_model assignment to
I really appreciate the work both in educating on bayesian regression in such an entertaining way and in making stan so easy to use from R.
I'm abusing the rethinking package to avoid writing macros to write stan code (because someone already did that, right?). I'd use brms for my problem except I want per-coefficient lower bounds (ie some coefficients to be non-negative, but not all). At any rate, I've got a very long deterministic assignment. Once I add 'too many' terms to the model, ulam() breaks up the assignment into two lines, but not in a way that is syntatically correct.
here's an attempt at a reproducible example:
If you check the resulting stan code in fff$model, you'll see that big_model[i] is split into two lines, but the first one ends in a +, and the second line does not increment the existing big_model[i]. I'll paste that code in below.
for my immediate purposes I'm just going to use shorter variable names, but this might be a simple fix? Changing the big_model assignment to
seems to work (ie the sampling runs instead of generating an error), in case there is some character limit in R or Stan that is hard to work around.
The text was updated successfully, but these errors were encountered: