Simplex in transformed parameters not working

Hello,
I have 12 variables and their corresponding intercepts. I want to fit a constraint on them such that sum of all exponential transformation of the intercept multiplied with their corresponding variable value, for each week should be a simplex i.e., the sum should be equal to one. I have written the following piece of code but it is not working. I am also attaching a sample excel sheet of my data to giive an idea. Kindly help me fit this.

Blockquote

code = "
data{
int N;
real VolumeVelocity[N];
real EquBasePrice[N];
real DISP[N];
real FEAT[N];
real MobileCoupon[N];
real DigitalPreStoreAd[N];
real MessagingAwayFromShelf[N];
real IRCAtShelf[N];
real Demo[N];
real DirectMailCoupon[N];
real TargetedPreStoreCoupon[N];
real PreStoreAd[N];
real TargetedDigitalPreStoreAd[N];
int Retailer[N];
int N_Retailer;
}

parameters{
real Intercept;
real beta_EquBasePrice;
real<upper = 0.1> beta_DISP;
real beta_FEAT;
real beta_MobileCoupon;
real beta_DigitalPreStoreAd;
real beta_MessagingAwayFromShelf;
real beta_IRCAtShelf;
real beta_Demo;
real beta_DirectMailCoupon;
real beta_TargetedPreStoreCoupon;
real beta_PreStoreAd;
real beta_TargetedDigitalPreStoreAd;
real<lower=0> sigma;
real vary_Retailer[N_Retailer];
real<lower=0> sigma_Retailer;
}

transformed parameters{

simplex a[12]

for (n in 1:N) {

a[1] <- (exp(beta_EquBasePrice) - 1)*EquBasePrice[n];
a[2] <- (exp(beta_DISP) - 1)*DISP[n];
a[3] <- (exp(beta_FEAT) - 1)*FEAT[n];
a[4] <- (exp(beta_MobileCoupon) - 1)*MobileCoupon[n];
a[5] <- (exp(beta_DigitalPreStoreAd) - 1)*DigitalPreStoreAd[n];
a[6] <- (exp(beta_TargetedDigitalPreStoreAd) - 1)*TargetedDigitalPreStoreAd[n];
a[7] <- (exp(beta_MessagingAwayFromShelf) - 1)*MessagingAwayFromShelf[n];
a[8] <- (exp(beta_IRCAtShelf) - 1)*IRCAtShelf[n];
a[9] <- (exp(beta_Demo) - 1)*Demo[n];
a[10] <- (exp(beta_DirectMailCoupon) - 1)*DirectMailCoupon[n];
a[11] <- (exp(beta_TargetedPreStoreCoupon) - 1)*TargetedPreStoreCoupon[n];
a[12] <- (exp(beta_PreStoreAd)-1)*PreStoreAd[n];

}

}

model{
real vary[N];
real glm[N];
// Priors
Intercept ~ normal( 0.3 , 0.1 );
beta_EquBasePrice ~ normal( 0.05 , 0.5 );
beta_DISP ~ normal( 0.1 , .5 );
beta_FEAT ~ normal( .05 , .5 );
beta_MobileCoupon ~ normal( .05 , .5 );
beta_DigitalPreStoreAd ~ normal( .05 , .5 );
beta_MessagingAwayFromShelf ~ normal( .05 , .5 );
beta_IRCAtShelf ~ normal( .05 , .5 );
beta_Demo ~ normal( .05 , .5 );
beta_DirectMailCoupon ~ normal( 0.05 , .1 );
beta_TargetedPreStoreCoupon ~ normal( 0.05 , .1 );
beta_PreStoreAd ~ normal( 0.08 , 0.2 );
beta_TargetedDigitalPreStoreAd ~ normal( 0.08 , 0.2 );
sigma_Retailer ~ uniform( 0 , 100 );
sigma ~ uniform( 0 , 100 );
// Varying effects
for ( j in 1:N_Retailer ) vary_Retailer[j] ~ normal( 0 , sigma_Retailer );
// Fixed effects
for ( i in 1:N ) {
vary[i] <- vary_Retailer[Retailer[i]];
glm[i] <- vary[i] + Intercept
+ beta_EquBasePrice * EquBasePrice[i]
+ beta_DISP * DISP[i]
+ beta_FEAT * FEAT[i]
+ beta_MobileCoupon * MobileCoupon[i]
+ beta_DigitalPreStoreAd * DigitalPreStoreAd[i]
+ beta_MessagingAwayFromShelf * MessagingAwayFromShelf[i]
+ beta_IRCAtShelf * IRCAtShelf[i]
+ beta_Demo * Demo[i]
+ beta_DirectMailCoupon * DirectMailCoupon[i]
+ beta_TargetedPreStoreCoupon * TargetedPreStoreCoupon[i]
+ beta_PreStoreAd * PreStoreAd[i]
+ beta_TargetedDigitalPreStoreAd * TargetedDigitalPreStoreAd[i];
}
VolumeVelocity ~ normal( glm , sigma );
}

generated quantities{
real dev;
real vary[N];
real glm[N];
dev <- 0;
for ( i in 1:N ) {
vary[i] <- vary_Retailer[Retailer[i]];
glm[i] <- vary[i] + Intercept
+ beta_EquBasePrice * EquBasePrice[i]
+ beta_DISP * DISP[i]
+ beta_FEAT * FEAT[i]
+ beta_MobileCoupon * MobileCoupon[i]
+ beta_DigitalPreStoreAd * DigitalPreStoreAd[i]
+ beta_MessagingAwayFromShelf * MessagingAwayFromShelf[i]
+ beta_IRCAtShelf * IRCAtShelf[i]
+ beta_Demo * Demo[i]
+ beta_DirectMailCoupon * DirectMailCoupon[i]
+ beta_TargetedPreStoreCoupon * TargetedPreStoreCoupon[i]
+ beta_PreStoreAd * PreStoreAd[i]
+ beta_TargetedDigitalPreStoreAd * TargetedDigitalPreStoreAd[i];
dev <- dev + (-2) * normal_log( VolumeVelocity[i] , glm[i] , sigma );
}
}"

What makes you think those values you assign to the simplex add up to 1 and are all positive?

I would strongly recommend fitting simpler models first before trying to fit complex ones.

Also, we use = now rather than <- for assignment—that’ll get rid of the deprecation warnings.

You’re likely going to have problems with variables if they really do have scales of 0.1—it helps to put everything on a unit scale.

We don’t recommend uniform interval priors. If you insist on them, then you have to declare the variables with constraints to match.